Skip to content

Fix socket.recv documentation. #3206

Open
@nshy

Description

@nshy

Product: Tarantool
Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/socket/#lua-function.socket_object.recv
SME: @ nshy

Info

https://www.tarantool.io/en/doc/latest/reference/reference_lua/socket/#lua-function.socket_object.recv

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    factual errorFactual error in functionality descriptionreference[location] Tarantool manual, Reference parttypo[nature] Just a typo. Typically tickets created by online bug reporter.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions