summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-01-05 23:29:13 +0800
committerruki <[email protected]>2024-01-05 23:29:13 +0800
commit8dd20c25ce7d376d872e51b5b9ae058bf562fc99 (patch)
treed874b0a5a2eb5122a1d67123fdd591e9261f3bbb
parent4727636cee877d9aed97bb395606fa6c90699a2f (diff)
trace socket
-rw-r--r--xmake/core/base/socket.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua
index 8976faed5..bd474a992 100644
--- a/xmake/core/base/socket.lua
+++ b/xmake/core/base/socket.lua
@@ -230,6 +230,12 @@ function _instance:connect(addr, port, opt)
local ok, errors = io.socket_connect(self:cdata(), addr, port, self:family())
if ok == 0 then
opt = opt or {}
+
+ -- trace socket
+ if socket._is_tracing_socket() then
+ print(string.format("%s: connecting %s:%d, timeout: %d", self, addr, port, opt.timeout or -1))
+ end
+
local events, waiterrs = _instance.wait(self, socket.EV_CONN, opt.timeout or -1)
if events == socket.EV_CONN then
ok, errors = io.socket_connect(self:cdata(), addr, port, self:family())
@@ -702,6 +708,23 @@ function _instance:__gc()
end
end
+-- trace socket for profile(stuck,trace)?
+function socket._is_tracing_socket()
+ local is_tracing = socket._IS_TRACING_SOCKET
+ if is_tracing == nil then
+ local profile = os.getenv("XMAKE_PROFILE")
+ if profile then
+ profile = profile:trim()
+ if profile == "trace" or profile == "stuck" then
+ is_tracing = true
+ end
+ end
+ is_tracing = is_tracing or false
+ socket._IS_TRACING_SOCKET = is_tracing
+ end
+ return is_tracing
+end
+
-- open a socket
--
-- @param socktype the socket type, e.g. tcp, udp, icmp