diff options
| author | ruki <[email protected]> | 2022-05-15 12:57:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-05-15 12:57:16 +0800 |
| commit | ba6bd4bba6db46f771e5b24cca0dda113b9caf3a (patch) | |
| tree | b101f7b54b7e378f6c25796e25a855274a261f90 | |
| parent | 14148b3694a1e0a994c2f66d18b0c3f256e0c425 (diff) | |
fix session
| -rw-r--r-- | xmake/modules/private/service/distcc_build/client.lua | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua index c6e4042ff..ab319cb15 100644 --- a/xmake/modules/private/service/distcc_build/client.lua +++ b/xmake/modules/private/service/distcc_build/client.lua @@ -209,17 +209,14 @@ function distcc_build_client:iorunv(program, argv, opt) -- lock this host self:_host_status_lock(host) - -- get the host session - local session = self:_host_status_session(host) - - -- open session - session:open() + -- open the host session + local session = assert(self:_host_status_session_open(host), "open session failed!") -- do distcc compilation local outdata, errdata = session:iorunv(program, argv, opt) -- close session - session:close() + self:_host_status_session_close(host, session) -- unlock this host self:_host_status_unlock(host) @@ -319,17 +316,41 @@ function distcc_build_client:_host_status_unlock(host_status) self._RUNNING = running end --- get host session -function distcc_build_client:_host_status_session(host_status) +-- open host session +function distcc_build_client:_host_status_session_open(host_status) host_status.sessions = host_status.sessions or {} - local running = host_status.running - local session = host_status.sessions[running] - if not session then - local sock = assert(socket.connect(host_status.addr, host_status.port), "%s: server unreachable!", self) - session = client_session(self, host_status.session_id, host_status.token, sock) - host_status.sessions[running] = session + host_status.free_sessions = host_status.free_sessions or {} + local sessions = host_status.sessions + local free_sessions = host_status.free_sessions + if #free_sessions > 0 then + local session = free_sessions[#free_sessions] + if session and not session:is_opened() then + table.remove(free_sessions) + session:open() + return session + end + end + local njob = host_status.njob + for i = 1, njob do + local session = host_status.sessions[i] + if not session then + local sock = assert(socket.connect(host_status.addr, host_status.port), "%s: server unreachable!", self) + session = client_session(self, host_status.session_id, host_status.token, sock) + host_status.sessions[i] = session + session:open() + return session + elseif not session:is_opened() then + session:open() + return session + end end - return session +end + +-- close session +function distcc_build_client:_host_status_session_close(host_status, session) + host_status.free_sessions = host_status.free_sessions or {} + session:close() + table.insert(host_status.free_sessions, session) end -- get the session id, only for unique project |
