diff options
| author | ruki <[email protected]> | 2019-10-12 23:19:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-10-12 23:19:48 +0800 |
| commit | 02e8be01f8e0311464302aff6b92a739098c7258 (patch) | |
| tree | 1cf2befc6068f1f17b0c4b4eebb3ecead0fc2821 | |
| parent | 938be7f39197d2f202fe3342e82d9d31c3264b53 (diff) | |
add opensock arguments
| -rw-r--r-- | xmake/core/base/io/file.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/io/filelock.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/io/socket.lua | 32 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 4 |
4 files changed, 22 insertions, 18 deletions
diff --git a/xmake/core/base/io/file.lua b/xmake/core/base/io/file.lua index 9e37654d7..26c914dea 100644 --- a/xmake/core/base/io/file.lua +++ b/xmake/core/base/io/file.lua @@ -64,7 +64,7 @@ end -- tostring(file) function _file:__tostring() - return "file: " .. self:name() + return "<file: " .. self:name() .. ">" end -- gc(file) diff --git a/xmake/core/base/io/filelock.lua b/xmake/core/base/io/filelock.lua index 8efbfd554..f68da33c1 100644 --- a/xmake/core/base/io/filelock.lua +++ b/xmake/core/base/io/filelock.lua @@ -121,7 +121,7 @@ end -- tostring(filelock) function _filelock:__tostring() - return "filelock: " .. self:name() + return "<filelock: " .. self:name() .. ">" end -- gc(filelock) diff --git a/xmake/core/base/io/socket.lua b/xmake/core/base/io/socket.lua index cee11fc51..79be64cf7 100644 --- a/xmake/core/base/io/socket.lua +++ b/xmake/core/base/io/socket.lua @@ -27,23 +27,29 @@ local table = require("base/table") local string = require("base/string") -- new a socket -function _socket.new(sock) - local socket = table.inherit(_socket) - socket._SOCK = sock - socket._NAME = "" +function _socket.new(socktype, family, sock) + local socket = table.inherit(_socket) + socket._SOCK = sock + socket._TYPE = socktype + socket._FAMILY = family setmetatable(socket, _socket) return socket end --- get the socket name -function _socket:name() - return self._NAME +-- get socket type +function _socket:type() + return self._TYPE +end + +-- get socket family +function _socket:family() + return self._FAMILY end -- close socket function _socket:close() if not self._SOCK then - return false, string.format("socket(%s) has been closed!", self:name()) + return false, string.format("%s has been closed!", tostring(self)) end local ok = io.socket_close(self._SOCK) if ok then @@ -54,7 +60,7 @@ end -- tostring(socket) function _socket:__tostring() - return "socket: " .. self:name() + return string.format("<socket: %s/%s>", self:type(), self:family()) end -- gc(socket) @@ -65,12 +71,10 @@ function _socket:__gc() end -- open a socket -function io.opensock() - - -- open it - local sock = io.socket_open() +function io.opensock(socktype, family) + local sock = io.socket_open(socktype, family) if sock then - return _socket.new(filepath, sock) + return _socket.new(socktype, family, sock) else return nil, string.format("failed to open socket!") end diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua index d6603e575..f4da16306 100644 --- a/xmake/core/sandbox/modules/io.lua +++ b/xmake/core/sandbox/modules/io.lua @@ -272,10 +272,10 @@ function sandbox_io.openlock(filepath) end -- open socket -function sandbox_io.opensock() +function sandbox_io.opensock(socktype, family) -- open sock - local sock, errors = io.opensock() + local sock, errors = io.opensock(socktype, family) if not sock then raise(errors) end |
