Open
Description
Product: Tarantool
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/socket/#lua-function.socket_object.recv
SME: @ nshy
Info
What's wrong?
Method returns nil
on error with socket._errno
set.
Code:
socket = require('socket')
s = socket('AF_UNIX', 'SOCK_DGRAM', 0)
-- should be error as socket is nonblocking
r = s:recv(1)
print(r)
print(s._errno)
Output
nil
11
Also in case of EOF it just receives empty string. There is no special EOF status.
socket = require('socket')
fio = require('fio')
fio.unlink('test.sock')
s = socket('AF_UNIX', 'SOCK_STREAM', 0)
assert(s)
assert(s:bind('unix/', 'test.sock'))
assert(s:listen())
c = socket.tcp_connect('unix/', 'test.sock')
assert(c)
print(c)
sc = s:accept()
assert(sc)
sc:write("4444")
d = c:recv(2)
assert(d)
print(d)
sc:shutdown(socket.SHUT_WR)
d = c:recv(2)
assert(d)
print(d)
d = c:recv(2)
assert(d)
assert(string.len(d) == 0)
print("EOF")
d = c:recv(2)
assert(d)
assert(string.len(d) == 0)
print("EOF")
Output:
fd 12, aka unix/:, peer unix/:test.sock
44
44
EOF
EOF