Skip to content

Commit ced0a0e

Browse files
committed
Refactor #accept_nonblock to avoid raising with exception: false
1 parent fbcfeb8 commit ced0a0e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/truffle/socket/truffle.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def self.sockaddr_class_for_socket(socket)
6666
end
6767
end
6868

69-
def self.accept(source, new_class)
69+
def self.internal_accept(source, new_class, exception)
7070
raise IOError, 'socket has been closed' if source.closed?
7171

7272
sockaddr = sockaddr_class_for_socket(source).new
@@ -79,7 +79,13 @@ def self.accept(source, new_class)
7979
.accept(source.fileno, sockaddr.pointer, size_p)
8080
end
8181

82-
Error.read_error('accept(2)', source) if fd < 0
82+
if fd < 0
83+
if exception
84+
Error.read_error('accept(2)', source)
85+
else
86+
return :wait_readable
87+
end
88+
end
8389

8490
socket = new_class.for_fd(fd)
8591

@@ -91,19 +97,16 @@ def self.accept(source, new_class)
9197
sockaddr.free
9298
end
9399
end
100+
private_class_method :internal_accept
101+
102+
def self.accept(source, new_class)
103+
internal_accept(source, new_class, true)
104+
end
94105

95106
def self.accept_nonblock(source, new_class, exception)
96107
source.fcntl(::Fcntl::F_SETFL, ::Fcntl::O_NONBLOCK)
97108

98-
begin
99-
accept(source, new_class)
100-
rescue Errno::EAGAIN
101-
if exception
102-
raise ::IO::EAGAINWaitReadable
103-
else
104-
return :wait_readable
105-
end
106-
end
109+
internal_accept(source, new_class, exception)
107110
end
108111

109112
def self.listen(source, backlog)

0 commit comments

Comments
 (0)