Skip to content

Commit

Permalink
Update BasicSocket#recv documentation on return value
Browse files Browse the repository at this point in the history
Ref: #6407

[Bug #19012]

`0` is now interpreted as closed connection an not an
empty packet, as these are very rare and pretty much
useless.
  • Loading branch information
byroot committed Dec 18, 2023
1 parent 40fc9b0 commit b2fc1b0
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ext/socket/lib/socket.rb
Expand Up @@ -333,9 +333,10 @@ def sendmsg_nonblock(mesg, flags = 0, dest_sockaddr = nil, *controls,
# _flags_ is zero or more of the +MSG_+ options.
# The result, _mesg_, is the data received.
#
# When recvfrom(2) returns 0, Socket#recv_nonblock returns
# an empty string as data.
# The meaning depends on the socket: EOF on TCP, empty packet on UDP, etc.
# When recvfrom(2) returns 0, Socket#recv_nonblock returns nil.
# In most cases it means the connection was closed, but for UDP connections
# it may mean an empty packet was received, as the underlying API makes
# it impossible to distinguish these two cases.
#
# === Parameters
# * +maxlen+ - the number of bytes to receive from the socket
Expand Down Expand Up @@ -480,9 +481,10 @@ def ipv6only!
# The second element, _sender_addrinfo_, contains protocol-specific address
# information of the sender.
#
# When recvfrom(2) returns 0, Socket#recvfrom_nonblock returns
# an empty string as data.
# The meaning depends on the socket: EOF on TCP, empty packet on UDP, etc.
# When recvfrom(2) returns 0, Socket#recv_nonblock returns nil.
# In most cases it means the connection was closed, but for UDP connections
# it may mean an empty packet was received, as the underlying API makes
# it impossible to distinguish these two cases.
#
# === Parameters
# * +maxlen+ - the maximum number of bytes to receive from the socket
Expand Down Expand Up @@ -1229,9 +1231,10 @@ class UDPSocket < IPSocket
# The first element of the results, _mesg_, is the data received.
# The second element, _sender_inet_addr_, is an array to represent the sender address.
#
# When recvfrom(2) returns 0,
# Socket#recvfrom_nonblock returns an empty string as data.
# It means an empty packet.
# When recvfrom(2) returns 0, Socket#recv_nonblock returns nil.
# In most cases it means the connection was closed, but it may also mean
# an empty packet was received, as the underlying API makes
# it impossible to distinguish these two cases.
#
# === Parameters
# * +maxlen+ - the number of bytes to receive from the socket
Expand Down

0 comments on commit b2fc1b0

Please sign in to comment.