Skip to content

Commit

Permalink
BasicSocket#*_nonblock(exception: false) should only return a Symbol …
Browse files Browse the repository at this point in the history
…for EAGAIN/EWOULDBLOCK

* Fixes #2400
  • Loading branch information
eregon committed Jul 14, 2021
1 parent 971d4e6 commit 68f5a76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Bug fixes:
* Fix `rb_str_modify_expand` to preserve existing bytes (#2392).
* Fix `String#scrub` when replacement is frozen (#2398, @LillianZ).
* Fix `Dir.mkdir` error handling for `Pathname` paths (#2397).
* `BasicSocket#*_nonblock(exception: false)` now only return `:wait_readable/:wait_writable` for `EAGAIN`/`EWOULDBLOCK` like MRI (#2400).

Compatibility:

Expand Down
18 changes: 9 additions & 9 deletions lib/truffle/socket/basic_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ def send(message, flags, dest_sockaddr = nil)
n_bytes = Truffle::Socket::Foreign.recv(Primitive.io_fd(self), buf, bytes_to_read, flags)

if n_bytes == -1
if exception
Truffle::Socket::Error.read_error('recv(2)', self)
else
if !exception and Errno.errno == Truffle::POSIX::EAGAIN_ERRNO
return :wait_readable
else
Truffle::Socket::Error.read_error('recv(2)', self)
end
end

Expand Down Expand Up @@ -205,10 +205,10 @@ def recv(bytes_to_read, flags = 0, buf = nil)
msg_size = Truffle::Socket::Foreign.recvmsg(Primitive.io_fd(self), header.pointer, flags)

if msg_size < 0
if exception
Truffle::Socket::Error.read_error('recvmsg(2)', self)
else
if !exception and Errno.errno == Truffle::POSIX::EAGAIN_ERRNO
return :wait_readable
else
Truffle::Socket::Error.read_error('recvmsg(2)', self)
end
end

Expand Down Expand Up @@ -271,10 +271,10 @@ def recv(bytes_to_read, flags = 0, buf = nil)
num_bytes = Truffle::Socket::Foreign.sendmsg(Primitive.io_fd(self), header.pointer, flags)

if num_bytes < 0
if exception
Truffle::Socket::Error.read_error('sendmsg(2)', self)
else
if !exception and Errno.errno == Truffle::POSIX::EAGAIN_ERRNO
return :wait_writable
else
Truffle::Socket::Error.read_error('sendmsg(2)', self)
end
end

Expand Down
9 changes: 4 additions & 5 deletions lib/truffle/socket/truffle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ def self.internal_accept(source, new_class, exception)
fd = Truffle::Socket::Foreign.memory_pointer(:int) do |size_p|
size_p.write_int(sockaddr.size)

Truffle::Socket::Foreign
.accept(source.fileno, sockaddr.pointer, size_p)
Truffle::Socket::Foreign.accept(source.fileno, sockaddr.pointer, size_p)
end

if fd < 0
if exception
Error.read_error('accept(2)', source)
else
if !exception and Errno.errno == Truffle::POSIX::EAGAIN_ERRNO
return :wait_readable
else
Error.read_error('accept(2)', source)
end
end

Expand Down

0 comments on commit 68f5a76

Please sign in to comment.