summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-30 00:36:59 +0800
committerruki <[email protected]>2023-11-30 00:36:59 +0800
commitaab8faf2ae1c7a540d7bea88880008245c37c356 (patch)
tree45e772c05c8fa074a96e7a4c0149c9452f46f0ef
parentda068da29b6978fa64923db3174f3817f8eaae74 (diff)
improve to disconnect distcc build
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua44
-rw-r--r--xmake/modules/private/service/distcc_build/server.lua3
-rw-r--r--xmake/modules/private/service/distcc_build/server_session.lua17
3 files changed, 11 insertions, 53 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