blob: 3ea2cd1357b992f00373230e44276ef53d0c1f93 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import("core.base.socket")
import("core.base.bytes")
function main(addr)
addr = addr or path.join(os.tmpdir(), "file.socket")
print("connect %s ..", addr)
local sock = socket.connect_unix(addr)
print("%s: connected!", sock)
local real = 0
local recv = 0
local data = nil
local wait = false
local buff = bytes(8192)
while true do
real, data = sock:recv(buff, 8192)
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
|