Skip to content

Commit

Permalink
Raise the WaitWritable version of EAGAIN for write_nonblock.
Browse files Browse the repository at this point in the history
Conflicts:

	src/org/jruby/RubyIO.java
  • Loading branch information
headius committed Feb 19, 2012
1 parent 8879729 commit 76b40d5
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1296,8 +1296,8 @@ public IRubyObject syswrite(ThreadContext context, IRubyObject obj) {

@JRubyMethod(name = "write_nonblock", required = 1)
public IRubyObject write_nonblock(ThreadContext context, IRubyObject obj) {
// MRI behavior: always check whether the file is writable
// or not, even if we are to write 0 bytes.
Ruby runtime = context.runtime;

OpenFile myOpenFile = getOpenFileChecked();

try {
Expand All @@ -1314,7 +1314,17 @@ public IRubyObject write_nonblock(ThreadContext context, IRubyObject obj) {
ChannelStream stream = (ChannelStream)myOpenFile.getWriteStream();

int written = stream.writenonblock(str.getByteList());
if (written == 0) throw context.runtime.newErrnoEWOULDBLOCKError();
if (written == 0) {
Ruby ruby = context.getRuntime();
// EAGAIN and EWOULDBLOCK are aliases
RaiseException eagain = ruby.newErrnoEAGAINError("");

if (ruby.is1_9()) {
eagain.getException().extend(new IRubyObject[] {ruby.getIO().getConstant("WaitWritable")});
}

throw eagain;
}

return context.getRuntime().newFixnum(written);
} catch (IOException ex) {
Expand Down Expand Up @@ -2574,7 +2584,6 @@ public IRubyObject read_nonblock(ThreadContext context, IRubyObject[] args) {
Ruby ruby = context.getRuntime();
RaiseException eagain = ruby.newErrnoEAGAINError("");

// FIXME: *oif* 1.9 actually does this
if (ruby.is1_9()) {
eagain.getException().extend(new IRubyObject[] {ruby.getIO().getConstant("WaitReadable")});
}
Expand Down

0 comments on commit 76b40d5

Please sign in to comment.