diff options
| author | ruki <[email protected]> | 2022-04-10 20:19:43 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-10 20:19:43 +0800 |
| commit | 5a67db08a505b68118d3eeeb89d32f04724261ef (patch) | |
| tree | f2066f0ac27e9094668a61af5f407f89f70e870b /xmake/modules | |
| parent | 2bafcb78b88396b8e953d86d50f59401f6eeab9b (diff) | |
send session id
Diffstat (limited to 'xmake/modules')
4 files changed, 44 insertions, 13 deletions
diff --git a/xmake/modules/private/service/client/remote_build_client.lua b/xmake/modules/private/service/client/remote_build_client.lua index 2de1cf022..9b16862b0 100644 --- a/xmake/modules/private/service/client/remote_build_client.lua +++ b/xmake/modules/private/service/client/remote_build_client.lua @@ -65,11 +65,12 @@ function remote_build_client:connect() local addr = self:addr() local port = self:port() local sock = socket.connect(addr, port) + local session_id = hash.uuid():split("-", {plain = true})[1]:lower() local connected = false print("%s: connect %s:%d ..", self, addr, port) if sock then local stream = socket_stream(sock) - if stream:send_msg(message.new_connect()) and stream:flush() then + if stream:send_msg(message.new_connect(session_id)) and stream:flush() then local msg = stream:recv_msg() if msg then vprint(msg:body()) @@ -79,7 +80,10 @@ function remote_build_client:connect() end if connected then print("%s: connected!", self) - io.save(statusfile, {addr = addr, port = port}) + io.save(statusfile, { + addr = addr, + port = port, + session_id = session_id}) self:_syncfiles() else print("%s: connect %s:%d failed", self, addr, port) @@ -97,11 +101,12 @@ function remote_build_client:disconnect() local addr = self:addr() local port = self:port() local sock = socket.connect(addr, port) + local session_id = assert(self:session_id(), "session id not found!") local disconnected = false print("%s: disconnect %s:%d ..", self, addr, port) if sock then local stream = socket_stream(sock) - if stream:send_msg(message.new_disconnect()) and stream:flush() then + if stream:send_msg(message.new_disconnect(session_id)) and stream:flush() then local msg = stream:recv_msg() if msg then vprint(msg:body()) @@ -148,6 +153,14 @@ function remote_build_client:workdir() return self._WORKDIR end +-- get the session id, only for unique project +function remote_build_client:session_id() + local status = self:status() + if status then + return status.session_id + end +end + -- sync files function remote_build_client:_syncfiles() end diff --git a/xmake/modules/private/service/message.lua b/xmake/modules/private/service/message.lua index 65d5e12c6..103d0e949 100644 --- a/xmake/modules/private/service/message.lua +++ b/xmake/modules/private/service/message.lua @@ -38,6 +38,11 @@ function message:code() return self:body().code end +-- get session id +function message:session_id() + return self:body().session_id +end + -- is connect message? function message:is_connect() return self:code() == message.CODE_CONN @@ -53,6 +58,12 @@ function message:body() return self._BODY end +-- clone a message +function message:clone() + local body = table.copy(self:body()) + return _new(body) +end + -- dump message function message:dump() print(self:body()) @@ -66,17 +77,19 @@ function _new(body) end -- new connect message -function new_connect() +function new_connect(session_id) return _new({ code = message.CODE_CONN, + session_id = session_id, xmakever = xmake.version():shortstr() }) end -- new disconnect message -function new_disconnect() +function new_disconnect(session_id) return _new({ - code = message.CODE_DISCONN + code = message.CODE_DISCONN, + session_id = session_id }) end diff --git a/xmake/modules/private/service/server/remote_build_server.lua b/xmake/modules/private/service/server/remote_build_server.lua index 606dd3c41..09dee6ba8 100644 --- a/xmake/modules/private/service/server/remote_build_server.lua +++ b/xmake/modules/private/service/server/remote_build_server.lua @@ -41,19 +41,24 @@ end -- handle connect message function remote_build_server:handle_connect(stream, msg) - local ok = stream:send_msg(message.new_connect()) and stream:flush() - vprint("%s: %s send %s", self, stream:sock(), ok and "ok" or "failed") + local session_id = msg:session_id() + local respmsg = msg:clone() + respmsg:body().xmakever = xmake.version():shortstr() + local ok = stream:send_msg(respmsg) and stream:flush() + vprint("%s: %s: <session %s>: send %s", self, stream:sock(), session_id, ok and "ok" or "failed") end -- handle disconnect message function remote_build_server:handle_disconnect(stream, msg) - local ok = stream:send_msg(message.new_disconnect()) and stream:flush() - vprint("%s: %s send %s", self, stream:sock(), ok and "ok" or "failed") + local session_id = msg:session_id() + local respmsg = msg:clone() + local ok = stream:send_msg(respmsg) and stream:flush() + vprint("%s: %s: <session %s>: send %s", self, stream:sock(), session_id, ok and "ok" or "failed") end -- on handle message function remote_build_server:on_handle(stream, msg) - vprint("%s: %s on handle message(%d)", self, stream:sock(), msg:code()) + vprint("%s: %s: <session %s>: on handle message(%d)", self, stream:sock(), msg:session_id(), msg:code()) vprint(msg:body()) if msg:is_connect() then self:handle_connect(stream, msg) diff --git a/xmake/modules/private/service/server/server.lua b/xmake/modules/private/service/server/server.lua index cbd1fcd3c..2acc230f6 100644 --- a/xmake/modules/private/service/server/server.lua +++ b/xmake/modules/private/service/server/server.lua @@ -120,7 +120,7 @@ end -- handle session function server:_handle_session(sock) - print("%s: %s session connected", self, sock) + print("%s: %s: session connected", self, sock) local stream = socket_stream(sock) while true do local msg = stream:recv_object() @@ -130,7 +130,7 @@ function server:_handle_session(sock) break end end - print("%s: %s session end", self, sock) + print("%s: %s: session end", self, sock) end function server:__tostring() |
