diff options
| author | ruki <[email protected]> | 2019-12-14 00:46:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-12-13 22:37:35 +0800 |
| commit | 26ea5a3e4a0a474366e879b529d6f0a2c918ef2d (patch) | |
| tree | bb1964bc50281bf09f83c1eab44827fe01756a65 /tests/modules/socket/sched_tcp/file_client.lua | |
| parent | 4f171e9e2b1eb119b43f08db23c9e6f271f9021d (diff) | |
add file_server and file_client tests for scheduler/socket
Diffstat (limited to 'tests/modules/socket/sched_tcp/file_client.lua')
| -rw-r--r-- | tests/modules/socket/sched_tcp/file_client.lua | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/modules/socket/sched_tcp/file_client.lua b/tests/modules/socket/sched_tcp/file_client.lua new file mode 100644 index 000000000..5dda4be6d --- /dev/null +++ b/tests/modules/socket/sched_tcp/file_client.lua @@ -0,0 +1,45 @@ +import("core.base.socket") +import("core.base.scheduler") + +function _session(addr, port) + print("connect %s:%d ..", addr, port) + local sock = socket.connect(addr, port) + print("%s: connected!", sock) + local real = 0 + local recv = 0 + local data = nil + local wait = false + local results = {} + while true do + real, data = sock:recv(8192) + if real > 0 then + recv = recv + real + wait = false + table.insert(results, data) + elseif real == 0 and not wait then + if sock:wait(socket.EV_RECV, -1) == socket.EV_RECV then + wait = true + else + break + end + else + break + end + end + if #results > 0 then + data = bytes(results) + end + print("%s: recv ok, size: %d, #data: %d!", sock, recv, data and data:size() or 0) + sock:close() + if scheduler.co_count() == 1 then + scheduler.stop() + end +end + +function main(count) + count = count and tonumber(count) or 1 + for i = 1, count do + scheduler.co_start(_session, "127.0.0.1", 9090) + end + scheduler.runloop() +end |
