???? After an analysis of thelauncher of Skynet services, we continue to analyze how the processes in Lua are organically integrated with the service, and the interpretation of the association in Lua is described in the understanding of the association in Lua.
In the previous analysis, when a LUA service receives a message, in the LUA layer, it will eventually execute to the Raw_dispatch_message function, the code is as follows:
LocalfunctionRaw_dispatch_message(prototype , msg< Span style= "Color:navy" > , Sz , Session , Source )
???? --Skynet. Ptype_response = 1, read skynet.h
???? if prototype = = 1 Then -- Response Package
????????LocalCo=Session_id_coroutine[Session]
????????ifCo=="Break" Then
???????????? Session_id_coroutine[Session]=Nil
????????ElseIfCo==Nil Then
???????????? Unknown_response(Session,Source,Msg,Sz)
????????Else
???????????? Session_id_coroutine[Session]=Nil
???????????? Suspend(Co,Coroutine_resume(Co,true, Msg,Sz))
????????End
????Else
????????LocalP=Proto[Prototype]
????????ifP==Nil Then
????????????ifSession~=0 Then
???????????????? C.send(Source,Skynet. Ptype_error,Session,"")
????????????Else
???????????????? Unknown_request(Session,Source,Msg,Sz,Prototype)
????????????End
????????????return
????????End
????????LocalF=P.dispatch
????????ifF Then
????????????LocalRef=Watching_service[Source]
????????????ifRef Then
???????????????? Watching_service[Source]=Ref+1
????????????Else
???????????????? Watching_service[Source]=1
????????????End
????????????LocalCo=Co_create(F)
???????????? session_coroutine_id[Co]=Session
???????????? Session_coroutine_address[Co]=Source
???????????? Suspend(Co,Coroutine_resume(Co,Session,Source,P.unpack(Msg,Sz)))
????????ElseIfSession~=0 Then
???????????? C.send(Source,Skynet. Ptype_error,Session,"")
????????Else
???????????? Unknown_request ( session , Source , Msg , Sz , Span style= "Color:black" > Proto [ prototype< Span style= "Color:navy" > ]. name )
???????? end
???? end
End
The power of the Skynet service