diff options
| author | ruki <[email protected]> | 2023-11-29 23:32:22 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-29 23:32:22 +0800 |
| commit | 153d25921367f082438e12b719aaa3208bb17f63 (patch) | |
| tree | be1c0677d966e9c9d96611051208523ebb9563b3 | |
| parent | e855c7258a29c2706c7970cf77435db11b445c75 (diff) | |
| parent | caac43e35206cbe4f9dedc6935c5adce9c2575f5 (diff) | |
Merge pull request #4449 from xmake-io/service
Improve to disconnect service
7 files changed, 15 insertions, 121 deletions
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index f18c98728..70b5d4784 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -146,13 +146,9 @@ function distcc_build_client:disconnect() -- do disconnect local hosts = self:hosts() assert(hosts and #hosts > 0, "hosts not found!") - local group_name = tostring(self) .. "/disconnect" - scheduler.co_group_begin(group_name, function () - for _, host in ipairs(hosts) do - scheduler.co_start(self._disconnect_host, self, host) - end - end) - scheduler.co_group_wait(group_name) + for _, host in ipairs(hosts) do + self:_disconnect_host(host) + end -- all hosts are connected? local connected = true @@ -591,46 +587,16 @@ function distcc_build_client:_disconnect_host(host) return end - -- do disconnect - local token = host.token - local sock = socket.connect(addr, port, {timeout = self:connect_timeout()}) - local session_id = self:_session_id(addr, port) - local errors - local ok = false - print("%s: disconnect %s:%d ..", self, addr, port) - if sock then - local stream = socket_stream(sock, {send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout()}) - if stream:send_msg(message.new_disconnect(session_id, {token = token})) and stream:flush() then - local msg = stream:recv_msg() - if msg then - vprint(msg:body()) - if msg:success() then - ok = true - else - errors = msg:errors() - end - end - end - else - -- server unreachable, but we still disconnect it. - wprint("%s: server unreachable!", self) - ok = true - end - if ok then - print("%s: %s:%d disconnected!", self, addr, port) - else - print("%s: disconnect %s:%d failed, %s", self, addr, port, errors or "unknown") - end - -- update status local status = self:status() status.hosts = status.hosts or {} local host_status = status.hosts[addr .. ":" .. port] if host_status then host_status.token = nil - host_status.connected = not ok + host_status.connected = false end self:status_save() + print("%s: %s:%d disconnected!", self, addr, port) end -- clean file for the host diff --git a/xmake/modules/private/service/distcc_build/server.lua b/xmake/modules/private/service/distcc_build/server.lua index 68e14de8f..5f8ce8726 100644 --- a/xmake/modules/private/service/distcc_build/server.lua +++ b/xmake/modules/private/service/distcc_build/server.lua @@ -84,9 +84,6 @@ function distcc_build_server:_on_handle(stream, msg) end if msg:is_connect() then session:open(respmsg) - elseif msg:is_disconnect() then - session:close() - self._SESSIONS[session_id] = nil else assert(session:is_connected(), "session has not been connected!") if msg:is_compile() then diff --git a/xmake/modules/private/service/distcc_build/server_session.lua b/xmake/modules/private/service/distcc_build/server_session.lua index d32f3fc01..8e373d254 100644 --- a/xmake/modules/private/service/distcc_build/server_session.lua +++ b/xmake/modules/private/service/distcc_build/server_session.lua @@ -53,20 +53,15 @@ end -- open server session function server_session:open(respmsg) - if self:is_connected() then - return - end - - -- get server info local body = respmsg:body() body.ncpu = os.cpuinfo().ncpu body.njob = os.default_njob() - - -- update status - local status = self:status() - status.connected = true - status.session_id = self:id() - self:status_save() + if not self:is_connected() then + local status = self:status() + status.connected = true + status.session_id = self:id() + self:status_save() + end end -- close server session diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua index aea6320c7..f4385015c 100644 --- a/xmake/modules/private/service/remote_build/client.lua +++ b/xmake/modules/private/service/remote_build/client.lua @@ -143,42 +143,13 @@ function remote_build_client:disconnect() print("%s: has been disconnected!", self) return end - local addr = self:addr() - local port = self:port() - local sock = socket.connect(addr, port, {timeout = self:connect_timeout()}) - local session_id = self:session_id() - local errors - local ok = false - cprint("${dim}%s: disconnect %s:%d ..", self, addr, port) - if sock then - local stream = socket_stream(sock, {send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout()}) - if stream:send_msg(message.new_disconnect(session_id, {token = self:token()})) and stream:flush() then - local msg = stream:recv_msg() - if msg then - vprint(msg:body()) - if msg:success() then - ok = true - else - errors = msg:errors() - end - end - end - else - -- server unreachable, but we still disconnect it. - wprint("%s: server unreachable!", self) - ok = true - end - if ok then - cprint("${dim}%s: disconnected!", self) - else - cprint("${dim}%s: disconnect %s:%d failed, %s", self, addr, port, errors or "unknown") - end -- update status local status = self:status() status.token = nil - status.connected = not ok + status.connected = false self:status_save() + cprint("${dim}%s: disconnected!", self) end -- sync server files diff --git a/xmake/modules/private/service/remote_build/server.lua b/xmake/modules/private/service/remote_build/server.lua index cdad7592e..feb819236 100644 --- a/xmake/modules/private/service/remote_build/server.lua +++ b/xmake/modules/private/service/remote_build/server.lua @@ -100,9 +100,6 @@ function remote_build_server:_on_handle(stream, msg) end if msg:is_connect() then session:open() - elseif msg:is_disconnect() then - session:close() - self._SESSIONS[session_id] = nil else assert(session:is_connected(), "session has not been connected!") if msg:is_diff() then diff --git a/xmake/modules/private/service/remote_cache/client.lua b/xmake/modules/private/service/remote_cache/client.lua index db6525491..2f61ad5ec 100644 --- a/xmake/modules/private/service/remote_cache/client.lua +++ b/xmake/modules/private/service/remote_cache/client.lua @@ -136,42 +136,13 @@ function remote_cache_client:disconnect() print("%s: has been disconnected!", self) return end - local addr = self:addr() - local port = self:port() - local sock = socket.connect(addr, port, {timeout = self:connect_timeout()}) - local session_id = self:session_id() - local errors - local ok = false - print("%s: disconnect %s:%d ..", self, addr, port) - if sock then - local stream = socket_stream(sock, {send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout()}) - if stream:send_msg(message.new_disconnect(session_id, {token = self:token()})) and stream:flush() then - local msg = stream:recv_msg() - if msg then - vprint(msg:body()) - if msg:success() then - ok = true - else - errors = msg:errors() - end - end - end - else - -- server unreachable, but we still disconnect it. - wprint("%s: server unreachable!", self) - ok = true - end - if ok then - print("%s: disconnected!", self) - else - print("%s: disconnect %s:%d failed, %s", self, addr, port, errors or "unknown") - end -- update status local status = self:status() status.token = nil - status.connected = not ok + status.connected = false self:status_save() + print("%s: disconnected!", self) end -- pull cache file diff --git a/xmake/modules/private/service/remote_cache/server.lua b/xmake/modules/private/service/remote_cache/server.lua index defb0992e..d509905a9 100644 --- a/xmake/modules/private/service/remote_cache/server.lua +++ b/xmake/modules/private/service/remote_cache/server.lua @@ -84,9 +84,6 @@ function remote_cache_server:_on_handle(stream, msg) end if msg:is_connect() then session:open() - elseif msg:is_disconnect() then - session:close() - self._SESSIONS[session_id] = nil else assert(session:is_connected(), "session has not been connected!") if msg:is_push() then |
