summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-05 23:19:12 +0800
committerruki <[email protected]>2022-07-05 23:19:12 +0800
commit75604a4d159a554bc6664f5d7a41f422fb256f20 (patch)
tree124eb46a67fc018ea6d5fa2117fda6fb08b1e376
parent5ad5e57ffd468bdec13f292773c7413201a68184 (diff)
add connect timeout
-rw-r--r--xmake/modules/private/service/client.lua6
-rw-r--r--xmake/modules/private/service/client_config.lua1
-rw-r--r--xmake/modules/private/service/distcc_build/client.lua8
-rw-r--r--xmake/modules/private/service/distcc_build/client_session.lua8
-rw-r--r--xmake/modules/private/service/remote_build/client.lua10
-rw-r--r--xmake/modules/private/service/remote_cache/client.lua6
6 files changed, 26 insertions, 13 deletions
diff --git a/xmake/modules/private/service/client.lua b/xmake/modules/private/service/client.lua
index 4eb18d1a1..c3af668d8 100644
--- a/xmake/modules/private/service/client.lua
+++ b/xmake/modules/private/service/client.lua
@@ -33,6 +33,7 @@ function client:init()
-- init timeout
self._SEND_TIMEOUT = config.get("send_timeout") or -1
self._RECV_TIMEOUT = config.get("recv_timeout") or -1
+ self._CONNECT_TIMEOUT = config.get("connect_timeout") or -1
end
-- get send timeout
@@ -45,6 +46,11 @@ function client:recv_timeout()
return self._RECV_TIMEOUT
end
+-- get connect timeout
+function client:connect_timeout()
+ return self._CONNECT_TIMEOUT
+end
+
-- parse host address
function client:address_parse(address)
local addr, port, user
diff --git a/xmake/modules/private/service/client_config.lua b/xmake/modules/private/service/client_config.lua
index fef687ef7..49feac13e 100644
--- a/xmake/modules/private/service/client_config.lua
+++ b/xmake/modules/private/service/client_config.lua
@@ -41,6 +41,7 @@ function _generate_configfile()
local configs = {
send_timeout = -1,
recv_timeout = -1,
+ connect_timeout = -1,
remote_build = {
-- without authorization: "127.0.0.1:9691"
-- with user authorization: "[email protected]:9691"
diff --git a/xmake/modules/private/service/distcc_build/client.lua b/xmake/modules/private/service/distcc_build/client.lua
index e51f6391c..b413a498f 100644
--- a/xmake/modules/private/service/distcc_build/client.lua
+++ b/xmake/modules/private/service/distcc_build/client.lua
@@ -469,7 +469,7 @@ function distcc_build_client:_host_status_session_open(host_status)
local session = host_status.sessions[i]
if not session then
session = client_session(self, host_status.session_id, host_status.token, host_status.addr, host_status.port,
- {send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout()})
+ {send_timeout = self:send_timeout(), recv_timeout = self:recv_timeout(), connect_timeout = self:connect_timeout()})
host_status.sessions[i] = session
session:open()
return session
@@ -536,7 +536,7 @@ function distcc_build_client:_connect_host(host)
end
-- do connect
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:_session_id(addr, port)
local ok = false
local errors
@@ -586,7 +586,7 @@ function distcc_build_client:_disconnect_host(host)
-- do disconnect
local token = host.token
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
local session_id = self:_session_id(addr, port)
local errors
local ok = false
@@ -637,7 +637,7 @@ function distcc_build_client:_clean_host(host)
-- do clean
local token = host.token
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
local session_id = self:_session_id(addr, port)
local errors
local ok = false
diff --git a/xmake/modules/private/service/distcc_build/client_session.lua b/xmake/modules/private/service/distcc_build/client_session.lua
index f4ff8c5ef..d913878fa 100644
--- a/xmake/modules/private/service/distcc_build/client_session.lua
+++ b/xmake/modules/private/service/distcc_build/client_session.lua
@@ -44,6 +44,7 @@ function client_session:init(client, session_id, token, addr, port, opt)
self._CLIENT = client
self._SEND_TIMEOUT = opt.send_timeout and opt.send_timeout or -1
self._RECV_TIMEOUT = opt.recv_timeout and opt.recv_timeout or -1
+ self._CONNECT_TIMEOUT = opt.connect_timeout and opt.connect_timeout or -1
end
-- get client session id
@@ -71,6 +72,11 @@ function client_session:recv_timeout()
return self._RECV_TIMEOUT
end
+-- get connect timeout
+function client_session:connect_timeout()
+ return self._CONNECT_TIMEOUT
+end
+
-- server unreachable?
function client_session:is_unreachable()
return self._UNREACHABLE
@@ -82,7 +88,7 @@ function client_session:stream()
if stream == nil then
local addr = self._ADDR
local port = self._PORT
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
if not sock then
self._UNREACHABLE = true
raise("%s: server unreachable!", self)
diff --git a/xmake/modules/private/service/remote_build/client.lua b/xmake/modules/private/service/remote_build/client.lua
index a665b2634..9ed4abb84 100644
--- a/xmake/modules/private/service/remote_build/client.lua
+++ b/xmake/modules/private/service/remote_build/client.lua
@@ -96,7 +96,7 @@ function remote_build_client:connect()
-- do connect
local addr = self:addr()
local port = self:port()
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:session_id()
local ok = false
local errors
@@ -144,7 +144,7 @@ function remote_build_client:disconnect()
end
local addr = self:addr()
local port = self:port()
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
local session_id = self:session_id()
local errors
local ok = false
@@ -185,7 +185,7 @@ function remote_build_client:sync()
assert(self:is_connected(), "%s: has been not connected!", self)
local addr = self:addr()
local port = self:port()
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:session_id()
local errors
local ok = false
@@ -239,7 +239,7 @@ function remote_build_client:clean()
assert(self:is_connected(), "%s: has been not connected!", self)
local addr = self:addr()
local port = self:port()
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:session_id()
local errors
local ok = false
@@ -268,7 +268,7 @@ function remote_build_client:runcmd(program, argv)
assert(self:is_connected(), "%s: has been not connected!", self)
local addr = self:addr()
local port = self:port()
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:session_id()
local errors
local ok = false
diff --git a/xmake/modules/private/service/remote_cache/client.lua b/xmake/modules/private/service/remote_cache/client.lua
index 1b3656eaa..c006d93b3 100644
--- a/xmake/modules/private/service/remote_cache/client.lua
+++ b/xmake/modules/private/service/remote_cache/client.lua
@@ -94,7 +94,7 @@ function remote_cache_client:connect()
-- do connect
local addr = self:addr()
local port = self:port()
- local sock = assert(socket.connect(addr, port), "%s: server unreachable!", self)
+ local sock = assert(socket.connect(addr, port, {timeout = self:connect_timeout()}), "%s: server unreachable!", self)
local session_id = self:session_id()
local ok = false
local errors
@@ -137,7 +137,7 @@ function remote_cache_client:disconnect()
end
local addr = self:addr()
local port = self:port()
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
local session_id = self:session_id()
local errors
local ok = false
@@ -440,7 +440,7 @@ function remote_cache_client:_sock_open()
local addr = self:addr()
local port = self:port()
- local sock = socket.connect(addr, port)
+ local sock = socket.connect(addr, port, {timeout = self:connect_timeout()})
if not sock then
self._UNREACHABLE = true
raise("%s: server unreachable!", self)