diff options
| author | ruki <[email protected]> | 2020-08-04 23:00:31 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-08-04 23:00:31 +0800 |
| commit | df97547270f725cd31352c8c7c483549001f676d (patch) | |
| tree | f266b64cc1c2768e93b687cac51dbb19538e4e8a /tests/modules/socket | |
| parent | 81c072eaa6eadde5f6427e0109226a7fa04691b0 (diff) | |
fix socket bug
Diffstat (limited to 'tests/modules/socket')
| -rw-r--r-- | tests/modules/socket/unix_tcp/echo_client.lua | 24 | ||||
| -rw-r--r-- | tests/modules/socket/unix_tcp/echo_server.lua | 1 |
2 files changed, 14 insertions, 11 deletions
diff --git a/tests/modules/socket/unix_tcp/echo_client.lua b/tests/modules/socket/unix_tcp/echo_client.lua index 53788d428..27c88cb9f 100644 --- a/tests/modules/socket/unix_tcp/echo_client.lua +++ b/tests/modules/socket/unix_tcp/echo_client.lua @@ -4,17 +4,19 @@ function main(addr) addr = addr or path.join(os.tmpdir(), "echo.socket") print("connect %s ..", addr) local sock = socket.connect_unix(addr) - print("%s: connected!", sock) - local count = 0 - while count < 10000 do - local send = sock:send("hello world..", {block = true}) - if send > 0 then - sock:recv(13, {block = true}) - else - break + if sock then + print("%s: connected!", sock) + local count = 0 + while count < 10000 do + local send = sock:send("hello world..", {block = true}) + if send > 0 then + sock:recv(13, {block = true}) + else + break + end + count = count + 1 end - count = count + 1 + print("%s: send ok, count: %d!", sock, count) + sock:close() end - print("%s: send ok, count: %d!", sock, count) - sock:close() end diff --git a/tests/modules/socket/unix_tcp/echo_server.lua b/tests/modules/socket/unix_tcp/echo_server.lua index 7a2334095..8b69d495f 100644 --- a/tests/modules/socket/unix_tcp/echo_server.lua +++ b/tests/modules/socket/unix_tcp/echo_server.lua @@ -3,6 +3,7 @@ import("core.base.socket") function main(addr) addr = addr or path.join(os.tmpdir(), "echo.socket") + os.tryrm(addr) local sock = socket.bind_unix(addr) sock:listen(20) print("%s: listening %s ..", sock, addr) |
