summaryrefslogtreecommitdiff
path: root/xmake
diff options
context:
space:
mode:
authorruki <[email protected]>2019-10-27 14:41:13 +0800
committerruki <[email protected]>2019-10-27 14:41:13 +0800
commit6df3d8bf595b3645022b4d465fd1192f9033913e (patch)
tree7f18711b1e4a9a88e1dfaa5840db71869b1e045c /xmake
parent74fe92ec5fab1725b139567f468f49cab4580888 (diff)
add socket.recv
Diffstat (limited to 'xmake')
-rw-r--r--xmake/core/base/socket.lua15
-rw-r--r--xmake/core/sandbox/modules/import/core/base/socket.lua15
2 files changed, 19 insertions, 11 deletions
diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua
index e85ec0301..b2be9bc28 100644
--- a/xmake/core/base/socket.lua
+++ b/xmake/core/base/socket.lua
@@ -160,14 +160,13 @@ function _instance:send(data, start, last)
end
-- send it
- local result, errors = io.socket_send(self._SOCK, data, start, last)
- if result < 0 and errors then
+ local real, errors = io.socket_send(self._SOCK, data, start, last)
+ if real < 0 and errors then
errors = string.format("%s: %s", self, errors)
end
- return result, errors
+ return real, errors
end
--- TODO
-- recv data from socket
function _instance:recv(size)
@@ -178,11 +177,11 @@ function _instance:recv(size)
end
-- recv it
- local result, errors = io.socket_recv(self._SOCK, data, size)
- if not result and errors then
- errors = string.format("%s: %s", self, errors)
+ local real, data_or_errors = io.socket_recv(self._SOCK, size)
+ if real < 0 and data_or_errors then
+ data_or_errors = string.format("%s: %s", self, data_or_errors)
end
- return result, errors
+ return real, data_or_errors
end
-- wait socket events
diff --git a/xmake/core/sandbox/modules/import/core/base/socket.lua b/xmake/core/sandbox/modules/import/core/base/socket.lua
index 082aabe4a..54f135a4e 100644
--- a/xmake/core/sandbox/modules/import/core/base/socket.lua
+++ b/xmake/core/sandbox/modules/import/core/base/socket.lua
@@ -107,11 +107,20 @@ end
-- send data to socket
function sandbox_core_base_socket_instance.send(sock, data, start, last)
- local result, errors = sock:_send(data, start, last)
- if result < 0 and errors then
+ local real, errors = sock:_send(data, start, last)
+ if real < 0 and errors then
raise(errors)
end
- return result
+ return real
+end
+
+-- recv data from socket
+function sandbox_core_base_socket_instance.recv(sock, size)
+ local real, data_or_errors = sock:_recv(data, size)
+ if real < 0 and data_or_errors then
+ raise(data_or_errors)
+ end
+ return real, data_or_errors
end
-- get socket rawfd