Skip to content

Commit

Permalink
simple fix. Socket read return -1 for error.
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed May 31, 2024
1 parent 0fcbf68 commit 5a8ab05
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ private IRubyObject recv(ThreadContext context, IRubyObject length,
return null; // not reached
}
} else {
bytes = doRead(context, buffer);
bytes = doRead(context, buffer);
if (bytes == null) return context.nil;
}
if (bytes == null) return context.nil;

if (str != null) {
str.setValue(bytes);
Expand Down Expand Up @@ -738,8 +738,7 @@ protected ByteList doRead(ThreadContext context, final ByteBuffer buffer) {
context.getThread().beforeBlockingCall(context);

int read = openFile.readChannel().read(buffer);

if (read == 0) return null;
if (read <= 0) return null;

return new ByteList(buffer.array(), 0, buffer.position(), false);
} catch (Exception e) {
Expand Down

0 comments on commit 5a8ab05

Please sign in to comment.