Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 830c8e628fc1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 143678657001
Choose a head ref
  • 7 commits
  • 5 files changed
  • 1 contributor

Commits on Jan 8, 2015

  1. Copy the full SHA
    b3dad6e View commit details
  2. Copy the full SHA
    440f1d3 View commit details
  3. Copy the full SHA
    191c38f View commit details
  4. Copy the full SHA
    283be75 View commit details
  5. Copy the full SHA
    6d25043 View commit details
  6. For nonblocking read, treat native file channel like selectable.

    We do not try to set the native file channel nonblocking, because
    it wouldn't do anything anyway. Instead, we assume that doing
    nothing is appropriate POSIX behavior for a read against a file
    that is supposed to have been set nonblocking.
    headius committed Jan 8, 2015
    Copy the full SHA
    faadd97 View commit details
  7. Copy the full SHA
    1436786 View commit details
51 changes: 21 additions & 30 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -1351,12 +1351,9 @@ private IRubyObject ioWriteNonblock(ThreadContext context, Ruby runtime, IRubyOb
throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath());

fptr.setNonblock(runtime);
try {
ByteList strByteList = ((RubyString) str).getByteList();
n = fptr.posix.write(fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), strByteList.getRealSize(), true);
} finally {
fptr.setBlock(runtime);
}

ByteList strByteList = ((RubyString) str).getByteList();
n = fptr.posix.write(fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), strByteList.getRealSize(), true);

if (n == -1) {
if (fptr.posix.errno == Errno.EWOULDBLOCK || fptr.posix.errno == Errno.EAGAIN) {
@@ -2740,7 +2737,7 @@ public IRubyObject ungetc(ThreadContext context, IRubyObject c) {
return context.nil;
}

@JRubyMethod(name = "read_nonblock", required = 1, optional = 1)
@JRubyMethod(name = "read_nonblock", required = 1, optional = 2)
public IRubyObject read_nonblock(ThreadContext context, IRubyObject[] args) {
return doReadNonblock(context, args, true);
}
@@ -2832,30 +2829,24 @@ private IRubyObject getPartial(ThreadContext context, IRubyObject[] args, boolea
if (nonblock) {
fptr.setNonblock(runtime);
}
try {
str = EncodingUtils.setStrBuf(runtime, str, len);
strByteList = ((RubyString) str).getByteList();
// arg.fd = fptr->fd;
// arg.str_ptr = RSTRING_PTR(str);
// arg.len = len;
// rb_str_locktmp_ensure(str, read_internal_call, (VALUE)&arg);
// n = arg.len;
n = OpenFile.readInternal(context, fptr, fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), len);
if (n < 0) {
if (!nonblock && fptr.waitReadable(context))
continue again;
if (nonblock && (fptr.errno() == Errno.EWOULDBLOCK || fptr.errno() == Errno.EAGAIN)) {
if (noException)
return runtime.newSymbol("wait_readable");
else
throw runtime.newErrnoEAGAINReadableError("read would block");
}
throw runtime.newEOFError(fptr.getPath());
}
} finally {
if (nonblock) {
fptr.setBlock(runtime);
str = EncodingUtils.setStrBuf(runtime, str, len);
strByteList = ((RubyString) str).getByteList();
// arg.fd = fptr->fd;
// arg.str_ptr = RSTRING_PTR(str);
// arg.len = len;
// rb_str_locktmp_ensure(str, read_internal_call, (VALUE)&arg);
// n = arg.len;
n = OpenFile.readInternal(context, fptr, fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), len);
if (n < 0) {
if (!nonblock && fptr.waitReadable(context))
continue again;
if (nonblock && (fptr.errno() == Errno.EWOULDBLOCK || fptr.errno() == Errno.EAGAIN)) {
if (noException)
return runtime.newSymbol("wait_readable");
else
throw runtime.newErrnoEAGAINReadableError("read would block");
}
throw runtime.newEOFError(fptr.getPath());
}
break;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/io/OpenFile.java
Original file line number Diff line number Diff line change
@@ -510,7 +510,7 @@ public boolean ready(Ruby runtime, RubyThread thread, int ops, long timeout) {
boolean locked = lock();
try {
if (fd.chSelect != null) {
return thread.select(fd.chSelect, this, ops, timeout);
return thread.select(fd.chSelect, this, ops & fd.chSelect.validOps(), timeout);

} else if (fd.chSeek != null) {
return fd.chSeek.position() != -1
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/io/PosixShim.java
Original file line number Diff line number Diff line change
@@ -127,6 +127,8 @@ public int read(ChannelFD fd, byte[] target, int offset, int length, boolean non
errno = Errno.EAGAIN;
return -1;
}
} else if (fd.chNative != null && fd.isNativeFile) {
// it's a native file, so we don't do selection or nonblock
} else {
errno = Errno.EAGAIN;
return -1;
6 changes: 3 additions & 3 deletions lib/ruby/stdlib/io/nonblock.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class IO
public
def nonblock?
JRuby.reference(self).blocking?
!JRuby.reference(self).blocking?
end

def nonblock=(blocking)
JRuby.reference(self).blocking = blocking
def nonblock=(nonblocking)
JRuby.reference(self).blocking = !nonblocking
end

def nonblock(nonblocking = true)
3 changes: 3 additions & 0 deletions test/mri/excludes/TestIO.rb
Original file line number Diff line number Diff line change
@@ -4,12 +4,15 @@
exclude :test_copy_stream_bigcontent_fpos, "needs investigation"
exclude :test_copy_stream_broken_src_read_eof, "needs investigation"
exclude :test_copy_stream_dst_rbuf, "needs investigation"
exclude :test_copy_stream_megacontent_nonblock, "copy_stream does not block against a nonblocking stream (#2439)"
exclude :test_copy_stream_pipe_nonblock, "copy_stream does not block against a nonblocking stream (#2439)"
exclude :test_copy_stream_read_pipe, "needs investigation"
exclude :test_copy_stream_rot13_to_io, "needs investigation"
exclude :test_copy_stream_rot13_to_rot13, "needs investigation"
exclude :test_copy_stream_smaller, "needs investigation"
exclude :test_copy_stream_socket4, "needs investigation"
exclude :test_copy_stream_socket6, "needs investigation"
exclude :test_copy_stream_socket7, "uses fork"
exclude :test_copy_stream_strio_off, "needs investigation"
exclude :test_copy_stream_write_in_binmode, "needs investigation"
exclude :test_cross_thread_close_stdio, "needs investigation"