summaryrefslogtreecommitdiff
path: root/tests/modules/socket/unix_tcp/echo_client.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2020-08-04 23:00:31 +0800
committerruki <[email protected]>2020-08-04 23:00:31 +0800
commitdf97547270f725cd31352c8c7c483549001f676d (patch)
treef266b64cc1c2768e93b687cac51dbb19538e4e8a /tests/modules/socket/unix_tcp/echo_client.lua
parent81c072eaa6eadde5f6427e0109226a7fa04691b0 (diff)
fix socket bug
Diffstat (limited to 'tests/modules/socket/unix_tcp/echo_client.lua')
-rw-r--r--tests/modules/socket/unix_tcp/echo_client.lua24
1 files changed, 13 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