diff options
| author | ruki <[email protected]> | 2019-11-02 00:45:02 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-11-01 22:30:18 +0800 |
| commit | 4f932ba407833f9559a23037958c7388cc22d2e0 (patch) | |
| tree | b3c2b9c43b357fdba9af1f68630e733484638905 /tests/modules/socket/tcp/file_client.lua | |
| parent | 6d4ad7fe1c5f8ac44b420a8cb5de0bc9cd0d37b6 (diff) | |
improve socket.recv using bytes
Diffstat (limited to 'tests/modules/socket/tcp/file_client.lua')
| -rw-r--r-- | tests/modules/socket/tcp/file_client.lua | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/modules/socket/tcp/file_client.lua b/tests/modules/socket/tcp/file_client.lua index 1d2756d77..42532f5fe 100644 --- a/tests/modules/socket/tcp/file_client.lua +++ b/tests/modules/socket/tcp/file_client.lua @@ -10,12 +10,13 @@ function main() local recv = 0 local data = nil local wait = false + local results = {} while true do - real, data = sock:recv(8192, {prevdata = data}) - print(real, type(data)) + 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 @@ -26,6 +27,9 @@ function main() break end end - print("%s: recv ok, size: %d, #data: %d!", sock, recv, #data) + 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() end |
