summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-05 23:07:51 +0800
committerruki <[email protected]>2022-07-05 23:07:51 +0800
commitc94c4d9aa8fe72a25358e89fa608f3457e9ee1f7 (patch)
tree5c00acd7ef42c0dfce82d1f17f5f1405b6d9c5c9
parent61d5d3faef3360303c862a4db2e7101e17ac6aac (diff)
checkout timeout errors
-rw-r--r--xmake/core/base/socket.lua6
-rw-r--r--xmake/modules/private/service/stream.lua9
2 files changed, 14 insertions, 1 deletions
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("<stream: %s>", self:sock())
+end
+
function main(sock, opt)
local instance = stream()
instance:init(sock, opt)