diff options
| author | ruki <[email protected]> | 2022-04-06 22:39:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-06 22:39:09 +0800 |
| commit | cc8c6dee305ab37f2ba18bbd4d04cc62ad0a9f2e (patch) | |
| tree | b3d9c336d7beb6d72285925442aecddc004c2706 /tests/modules/socket/unix_tcp/echo_server.lua | |
| parent | 60c78f84bcef3be6e5a906cd10fe6bc0d7b0c77c (diff) | |
improve socket
Diffstat (limited to 'tests/modules/socket/unix_tcp/echo_server.lua')
| -rw-r--r-- | tests/modules/socket/unix_tcp/echo_server.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/modules/socket/unix_tcp/echo_server.lua b/tests/modules/socket/unix_tcp/echo_server.lua index 8a1ea6c7d..0a9199273 100644 --- a/tests/modules/socket/unix_tcp/echo_server.lua +++ b/tests/modules/socket/unix_tcp/echo_server.lua @@ -1,3 +1,4 @@ +import("core.base.bytes") import("core.base.socket") function main(addr) @@ -13,8 +14,9 @@ function main(addr) print("%s: accepted", sock_client) local count = 0 local result = nil + local buff = bytes(8192) while true do - local recv, data = sock_client:recv(13, {block = true}) + local recv, data = sock_client:recv(buff, 13, {block = true}) if recv > 0 then result = data sock_client:send(data, {block = true}) @@ -24,7 +26,9 @@ function main(addr) end end print("%s: recv: %d, count: %d", sock_client, result and result:size() or 0, count) - result:dump() + if result then + result:dump() + end sock_client:close() end end |
