Github.com/cloudwu/sky… \

Github.com/cloudwu/sky…

blog.codingnow.com/eo/skynet/

Research on Cloud Wind Skynet Server Framework

\

Skynet unofficial websiteskynetclub.github.io/

Skynet resource collection

Linux installation of Skynet problem summary \

Skynet Basics Examples (1)

Skynet Basics Examples (2)

Skynet Basics Examples (3)

Skynet Basics Examples (4)

Skynet Basics Examples (5)

Skynet Basics Examples (6)

Skynet基础入门例子详解(7)

\

Learn the Skynet_examples study from scratch

Skynet startup process _1

\

# # skynet

*. Network: Gate. lua, Gateserver. lua, Socketdriver. Lua, netpack.lua is a set of things that fully implement packet processing, i.e., two bytes of data size + data

{MSG, sz, fd}

*. Network: Socket_server.c && Skynet_socket. c is the core of network processing, exposing a large number of thread-safe methods, using epoll for request distribution, send, just write a request to a FD to complete the asynchronous process

*. Network: Before using a domain name, you must resolve the domain name to an IP address before passing it in. Otherwise, socket_server calls getAddInfo on the open_socket and the whole process is blocked

Processing of individual requests, including sending data, opening sockets, and so on, is done in a poll

*. Network: the length of a single message packet agreed between agent and client, that is, the packet header is an unsigned integer of 2 bytes, which can actually reach 2^16, that is, 65536 bytes, and use big encoder

*. Sproto: Sprotoloader loads sproto into memory and uses index to index the corresponding sproto

*. Sproto: Sproto. Lua uses metatable to create a new instance of sproto, which shares memory. The other attach function mainly deals with the problem of how to encode in the case of active sending.

It just returns a closure function for encode

*.sproto: sproto. Lua: sproto:host: packagename:.sproto :host: sproto. Lua: sproto:host: sproto.

Used to implement the RPC, contains the type with the session, so when back to the package also include such data, can let the caller know response packet which is corresponding to the session

*.sproto: lsproto.c specifies the maxsize of encode, i.e. 0x1000000, and the level of encode is 64

*. Main program entry: skynet_main.c, specific: skynet_start.c starts various threads, passes in various parameters, initializes, and begins work

*. Main logic: Skynet_server. c, message distribution, logic transfer, Skynet_context creation, skynet_context_new: Load the module, call Skynet_HANDle_register to bind, initialize, create MQ, and add to global MQ

*. Skynet_context: an important concept in Skynet, in fact, is a service carrier. The so-called skynet standard service contains a series of functions such as “service name _*”, * including” create, release, init, signal,

Initialization of Pointers to these functions (i.e., mapping from names to actual Pointers is done in Skynet_module. c, using dlSYm functions to load functions with the corresponding names from modules)

*. Conforming C modules: need to include a series of “service name _*” functions, * including” create, release, init, signal, where signal is optional

*.service_snlua. c: this is a service that was first used in skynet_start.c bootstrap. If you set bootstrap to snlua bootstrap in cofig.xxx, it will

Skynet_context_new (“snlua”, “bootstrap”), that is, start the SNluA service and pass in the bootstrap parameter

*.bootstrap. lua: This standard module starts the launcher service, which is used to load the module when newService runs

*. Message packets: The size limit for message packets is 2^56 bytes, SIZE_MAX >> 8

*. Message distribution: Skynet_context_message_dispatch in Skynet_server. c is the entire core, called by the Skynet_start. c thread_worker loop

*.skynet. Launch: Used to launch a C service. There are only a few C services in Skynet, such as service_snlua, service_logger, and so on.

So skynet. newService ends up calling skynet.launch, which in turn calls cmd_launch in Skynet_server. c, and yi

*.skynet. lua: Most of the operations are associated back to skynet_context, skynet.dispatch_message is registered as a LUa service CB and is called by CB when the context has a message.

Then raw_dispatch_message is called to resolve the message type, MSG and SZ are resolved using the pack or unpack functions specified by Skynet_register_protocol, and the specific functions are dispatched back

To deal with

*.skynet. lua: Regarding the working principle of Skynet. timeout, first use the func passed in to establish a coroutine, and then call the timeout function of Skynet-server, which will return a session

When the timer is called back, the co is retrieved by the session value, and then resume, skynet-server timeout where the caller’s handle&session is recorded. After the time of arrival,

Dispatch the message to the corresponding Handle and pass the session value back

Skynet. lua: Skynet. sleep works like skynet.timeout, but instead of creating a new co, just yield the current CO and wait for it to resume

\

\

\