diff options
| author | ruki <[email protected]> | 2019-10-16 00:48:50 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-10-15 22:53:03 +0800 |
| commit | 690dc274a4d5f9f443e6c2004b985b03345874d6 (patch) | |
| tree | 43b6ba534d331325ca8d4022994bda75e496e5eb /xmake/core/base/socket.lua | |
| parent | e915ad63a7f1a9fa4736472c60b0550cbd174361 (diff) | |
add socket.send
Diffstat (limited to 'xmake/core/base/socket.lua')
| -rw-r--r-- | xmake/core/base/socket.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/xmake/core/base/socket.lua b/xmake/core/base/socket.lua index 09fd00646..78bbb9935 100644 --- a/xmake/core/base/socket.lua +++ b/xmake/core/base/socket.lua @@ -150,6 +150,23 @@ function _instance:connect(addr, port) return result, errors end +-- send data to socket +function _instance:send(data, start, last) + + -- ensure opened + local ok, errors = self:_ensure_opened() + if not ok then + return -1, errors + end + + -- send it + local result, errors = io.socket_send(self._SOCK, data, start, last) + if result < 0 and errors then + errors = string.format("%s: %s", self, errors) + end + return result, errors +end + -- wait socket events function _instance:wait(events, timeout) |
