summaryrefslogtreecommitdiff
path: root/tests/modules/socket/unix_tcp/file_server.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-12-20 00:53:14 +0800
committerruki <[email protected]>2019-12-19 23:19:27 +0800
commit4ce400a33c26c4d59e76ccb5dc321fe6dabc60f7 (patch)
tree7fba42df02bab3ab2702ad57c896002b22cb6518 /tests/modules/socket/unix_tcp/file_server.lua
parentdb52fd10877391ebc89be2c6551b94901a31e7b6 (diff)
add unix socket support
Diffstat (limited to 'tests/modules/socket/unix_tcp/file_server.lua')
-rw-r--r--tests/modules/socket/unix_tcp/file_server.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/modules/socket/unix_tcp/file_server.lua b/tests/modules/socket/unix_tcp/file_server.lua
new file mode 100644
index 000000000..b17d71104
--- /dev/null
+++ b/tests/modules/socket/unix_tcp/file_server.lua
@@ -0,0 +1,22 @@
+import("core.base.socket")
+
+function main(filepath, addr)
+ addr = addr or path.join(os.tmpdir(), "file.socket")
+ local sock = socket.bind_unix(addr)
+ sock:listen(20)
+ print("%s: listening %s ..", sock, addr)
+ while true do
+ local sock_client = sock:accept()
+ if sock_client then
+ print("%s: accepted", sock_client)
+ local file = io.open(filepath, 'rb')
+ if file then
+ local send = sock_client:sendfile(file, {block = true})
+ print("%s: send %s %d bytes!", sock_client, filepath, send)
+ file:close()
+ end
+ sock_client:close()
+ end
+ end
+ sock:close()
+end