summaryrefslogtreecommitdiff
path: root/tests/modules/socket/tcp/file_client.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-10-28 22:40:27 +0800
committerruki <[email protected]>2019-10-28 10:02:46 +0800
commit8bfbf6b7fb255cda1bfd3d970c7442ed0941104c (patch)
tree356e02c9fece1f27909a64f6d270e0201ab270b5 /tests/modules/socket/tcp/file_client.lua
parenta6e3140520f31c756cc8982d3ab20eff95b75160 (diff)
add sendfile demo
Diffstat (limited to 'tests/modules/socket/tcp/file_client.lua')
-rw-r--r--tests/modules/socket/tcp/file_client.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/modules/socket/tcp/file_client.lua b/tests/modules/socket/tcp/file_client.lua
new file mode 100644
index 000000000..3d5a14651
--- /dev/null
+++ b/tests/modules/socket/tcp/file_client.lua
@@ -0,0 +1,30 @@
+import("core.base.socket")
+
+function main()
+ local addr = "127.0.0.1"
+ local port = 9090
+ 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
+ while true do
+ real, data = sock:recv(8192, {prevdata = data})
+ if real > 0 then
+ recv = recv + real
+ wait = false
+ 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
+ print("%s: recv ok, size: %d!", sock, recv)
+ sock:close()
+end