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: 8a8d5776fe16
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2c86bfd485ce
Choose a head ref
  • 6 commits
  • 2 files changed
  • 3 contributors

Commits on Oct 11, 2016

  1. Properly coerce shutdown argument.

    headius authored and etehtsea committed Oct 11, 2016
    Copy the full SHA
    68e7ba5 View commit details
  2. Copy the full SHA
    7e6e8cc View commit details
  3. Fix up BasicSocket#close_read and close_write.

    Passes specs in rubysl-socket.
    headius authored and etehtsea committed Oct 11, 2016
    Copy the full SHA
    b9d6a49 View commit details
  4. Copy the full SHA
    a4dd94c View commit details

Commits on Oct 12, 2016

  1. Copy the full SHA
    def7839 View commit details
  2. Merge pull request #4222 from etehtsea/basicsocket-improvements

    BasicSocket improvements
    enebo authored Oct 12, 2016
    Copy the full SHA
    2c86bfd View commit details
Showing with 40 additions and 51 deletions.
  1. +40 −50 core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
  2. +0 −1 test/mri/excludes/TestSocket_BasicSocket.rb
90 changes: 40 additions & 50 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -352,9 +352,10 @@ public IRubyObject getpeername(ThreadContext context) {
Ruby runtime = context.runtime;

InetSocketAddress sock = getInetRemoteSocket();
if (sock != null) return runtime.newString(sock.getHostName());

if (sock != null) return Sockaddr.pack_sockaddr_in(context, sock);
UnixSocketAddress unix = getUnixRemoteSocket();
return runtime.newString(unix.path());
return Sockaddr.pack_sockaddr_un(context, unix.path());
}

@JRubyMethod(name = "getpeereid", notImplemented = true)
@@ -405,6 +406,10 @@ public IRubyObject shutdown(ThreadContext context, IRubyObject[] args) {
String howString = null;
if (args[0] instanceof RubyString || args[0] instanceof RubySymbol) {
howString = args[0].asJavaString();
} else {
Ruby runtime = context.runtime;
IRubyObject maybeString = TypeConverter.checkStringType(runtime, args[0]);
if (!maybeString.isNil()) howString = maybeString.toString();
}
if (howString != null) {
if (howString.equals("RD") || howString.equals("SHUT_RD")) {
@@ -413,66 +418,47 @@ public IRubyObject shutdown(ThreadContext context, IRubyObject[] args) {
how = 1;
} else if (howString.equals("RDWR") || howString.equals("SHUT_RDWR")) {
how = 2;
} else {
throw SocketUtils.sockerr(context.runtime, "`how' should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR");
}
} else {
how = RubyNumeric.fix2int(args[0]);
}
}

try {
return shutdownInternal(context, how);
}
catch (BadDescriptorException e) {
throw context.runtime.newErrnoEBADFError();
}
OpenFile fptr = getOpenFileChecked();

return shutdownInternal(context, fptr, how);
}

@Override
@JRubyMethod
public IRubyObject close_write(ThreadContext context) {
Ruby runtime = context.runtime;
OpenFile fptr;

// if (rb_safe_level() >= 4 && !OBJ_TAINTED(sock)) {
// rb_raise(rb_eSecurityError, "Insecure: can't close socket");
// }
fptr = getOpenFileChecked();
if ((fptr.getMode() & OpenFile.READABLE) == 0) {
return rbIoClose(runtime);
}
// shutdown write
try {
shutdownInternal(context, 1);
}
catch (BadDescriptorException e) {
throw runtime.newErrnoEBADFError();
}

return context.nil;
return closeHalf(context, OpenFile.WRITABLE);
}

@Override
@JRubyMethod
public IRubyObject close_read(ThreadContext context) {
Ruby runtime = context.runtime;
return closeHalf(context, OpenFile.READABLE);
}

if (!openFile.isOpen()) {
throw context.runtime.newIOError("not opened for reading");
}
private IRubyObject closeHalf(ThreadContext context, int closeHalf) {
Ruby runtime = context.runtime;
OpenFile fptr;

if (!openFile.isWritable()) {
close();
int otherHalf = closeHalf == OpenFile.READABLE ? OpenFile.WRITABLE : OpenFile.READABLE;

} else {
// shutdown read
try {
shutdownInternal(context, 0);
}
catch (BadDescriptorException e) {
throw runtime.newErrnoEBADFError();
}
fptr = getOpenFileChecked();
if ((fptr.getMode() & otherHalf) == 0) {
// shutdown fully
return rbIoClose(runtime);
}

// shutdown half
shutdownInternal(context, fptr, 0);
fptr.setMode(fptr.getMode() & ~closeHalf);

return context.nil;
}

@@ -499,7 +485,7 @@ public IRubyObject readmsg_nonblock(ThreadContext context, IRubyObject[] args) {
protected ByteList doRead(ThreadContext context, final ByteBuffer buffer) {
OpenFile fptr;

fptr = getOpenFile();
fptr = getOpenFileInitialized();
fptr.checkReadable(context);

try {
@@ -602,7 +588,11 @@ protected SocketAddress getSocketAddress() {
protected SocketAddress getRemoteSocket() {
Channel channel = getOpenChannel();

return SocketType.forChannel(channel).getRemoteSocketAddress(channel);
SocketAddress address = SocketType.forChannel(channel).getRemoteSocketAddress(channel);

if (address == null) throw getRuntime().newErrnoENOTCONNError();

return address;
}

protected IRubyObject getSocknameCommon(ThreadContext context, String caller) {
@@ -617,40 +607,40 @@ protected IRubyObject getSocknameCommon(ThreadContext context, String caller) {
return Sockaddr.pack_sockaddr_in(context, 0, "0.0.0.0");
}

private IRubyObject shutdownInternal(ThreadContext context, int how) throws BadDescriptorException {
private static IRubyObject shutdownInternal(ThreadContext context, OpenFile fptr, int how) {
Ruby runtime = context.runtime;
Channel channel;

switch (how) {
case 0:
channel = getOpenChannel();
channel = fptr.channel();
try {
SocketType.forChannel(channel).shutdownInput(channel);
}
catch (IOException e) {
// MRI ignores errors from shutdown()
}

openFile.setMode(openFile.getMode() & ~OpenFile.READABLE);
fptr.setMode(fptr.getMode() & ~OpenFile.READABLE);

return RubyFixnum.zero(runtime);

case 1:
channel = getOpenChannel();
channel = fptr.channel();
try {
SocketType.forChannel(channel).shutdownOutput(channel);
}
catch (IOException e) {
// MRI ignores errors from shutdown()
}

openFile.setMode(openFile.getMode() & ~OpenFile.WRITABLE);
fptr.setMode(fptr.getMode() & ~OpenFile.WRITABLE);

return RubyFixnum.zero(runtime);

case 2:
shutdownInternal(context, 0);
shutdownInternal(context, 1);
shutdownInternal(context, fptr, 0);
shutdownInternal(context, fptr, 1);

return RubyFixnum.zero(runtime);

1 change: 0 additions & 1 deletion test/mri/excludes/TestSocket_BasicSocket.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
exclude :test_for_fd, "needs investigation"
exclude :test_getsockopt, "needs investigation"
exclude :test_setsockopt, "needs investigation"
exclude :test_listen, "needs investigation"