From 4ce400a33c26c4d59e76ccb5dc321fe6dabc60f7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 20 Dec 2019 00:53:14 +0800 Subject: add unix socket support --- tests/modules/socket/unix_tcp/file_server.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/modules/socket/unix_tcp/file_server.lua (limited to 'tests/modules/socket/unix_tcp/file_server.lua') 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 -- cgit v1.3.1