From c94c4d9aa8fe72a25358e89fa608f3457e9ee1f7 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 5 Jul 2022 23:07:51 +0800 Subject: checkout timeout errors --- xmake/core/base/socket.lua | 6 ++++++ xmake/modules/private/service/stream.lua | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua index 615f28a0c..b9da2e99a 100644 --- a/xmake/core/base/socket.lua +++ b/xmake/core/base/socket.lua @@ -318,6 +318,8 @@ function _instance:send(data, opt) local events, waiterrs = _instance.wait(self, socket.EV_SEND, opt.timeout or -1) if events == socket.EV_SEND then wait = true + elseif events == 0 then + os.raise("%s: send timeout!", self) else errors = waiterrs break @@ -385,6 +387,8 @@ function _instance:sendfile(file, opt) local events, waiterrs = _instance.wait(self, socket.EV_SEND, opt.timeout or -1) if events == socket.EV_SEND then wait = true + elseif events == 0 then + os.raise("%s: sendfile timeout!", self) else errors = waiterrs break @@ -451,6 +455,8 @@ function _instance:recv(buff, size, opt) local events, waiterrs = _instance.wait(self, socket.EV_RECV, opt.timeout or -1) if events == socket.EV_RECV then wait = true + elseif events == 0 then + os.raise("%s: recv timeout!", self) else data_or_errors = waiterrs break diff --git a/xmake/modules/private/service/stream.lua b/xmake/modules/private/service/stream.lua index 9037bdd8b..e7972e7e9 100644 --- a/xmake/modules/private/service/stream.lua +++ b/xmake/modules/private/service/stream.lua @@ -101,6 +101,7 @@ function stream:send(data, start, last) -- send data to socket local sock = self._SOCK local real = sock:send(cache, {block = true, timeout = self:timeout()}) + print("send", real) if real > 0 then -- copy left data to cache assert(size <= cache_maxn) @@ -287,9 +288,11 @@ function stream:recv(buff, size) end wait = false elseif real == 0 and not wait then - if sock:wait(socket.EV_RECV, self:timeout()) == socket.EV_RECV then + local ok = sock:wait(socket.EV_RECV, self:timeout()) + if ok == socket.EV_RECV then wait = true else + assert(ok ~= 0, "%s: recv timeout!", self) break end else @@ -449,6 +452,10 @@ function stream:_recv_compressed_file(lz4_stream, filepath, size) end end +function stream:__tostring() + return string.format("", self:sock()) +end + function main(sock, opt) local instance = stream() instance:init(sock, opt) -- cgit v1.3.1