Skip to content

Commit

Permalink
Only set EAGAIN when written == 0 and length > 0. Fixes #2957
Browse files Browse the repository at this point in the history
Because we use NIO channels for all IO, but need to behave like
POSIX IO functions, we emulate errno behavior for various cases.
This particular issue is an edge case, when writing zero bytes to
a stream marked as nonblocking (as happens after it is used in an
IO.select operation); we see that it's nonblocking and nothing was
written and unconditionally treat that as EAGAIN. Instead, we
should only set EAGAIN when zero bytes are written and we actually
did have bytes to write.
headius committed May 21, 2015
1 parent ae31756 commit f156123
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
@@ -91,7 +91,7 @@ public int write(ChannelFD fd, byte[] bytes, int offset, int length, boolean non

int written = fd.chWrite.write(tmp);

if (written == 0) {
if (written == 0 && length > 0) {
// if it's a nonblocking write against a file and we've hit EOF, do EAGAIN
if (nonblock) {
errno = Errno.EAGAIN;

0 comments on commit f156123

Please sign in to comment.