diff options
| author | ruki <[email protected]> | 2019-10-13 22:50:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-10-13 22:50:39 +0800 |
| commit | f2a2f516c29eeb5a3d9475903dd3b4ed8c3df45d (patch) | |
| tree | b1525ee420b10faa179b788ce8dcca32bb2d7229 | |
| parent | 2eeba59f19090ee8108f13f8883d739739a4967d (diff) | |
add socket.connect
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/socket.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/xmake/core/sandbox/modules/import/core/base/socket.lua b/xmake/core/sandbox/modules/import/core/base/socket.lua index 3522d34d5..e13d55fca 100644 --- a/xmake/core/sandbox/modules/import/core/base/socket.lua +++ b/xmake/core/sandbox/modules/import/core/base/socket.lua @@ -97,6 +97,38 @@ function sandbox_core_base_socket.open_udp6() return sandbox_core_base_socket.open("udp", "ipv6") end +-- open and connect tcp/ipv4 socket +function sandbox_core_base_socket.connect4(addr, port, timeout) + local sock = sandbox_core_base_socket.open_tcp4() + local ok = 0 + repeat + ok = sock:connect(addr, port) + -- TODO wait + until ok ~= 0 + if ok > 0 then + return sock + else + sock:close() + raise("connect %s:%s failed!", addr, port) + end +end + +-- open and connect tcp/ipv6 socket +function sandbox_core_base_socket.connect6(addr, port) + local sock = sandbox_core_base_socket.open_tcp6() + local ok = 0 + repeat + ok = sock:connect(addr, port) + -- TODO wait + until ok ~= 0 + if ok > 0 then + return sock + else + sock:close() + raise("connect %s:%s failed!", addr, port) + end +end + -- return module return sandbox_core_base_socket |
