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: 69f8c030fdd0
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2dc0ffa46904
Choose a head ref
  • 3 commits
  • 2 files changed
  • 1 contributor

Commits on Jan 4, 2016

  1. Move this down to IPSocket.

    headius committed Jan 4, 2016
    Copy the full SHA
    cbe5da7 View commit details
  2. Copy the full SHA
    a6838d3 View commit details
  3. Copy the full SHA
    2dc0ffa View commit details
Showing with 27 additions and 18 deletions.
  1. +7 −18 core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
  2. +20 −0 core/src/main/java/org/jruby/ext/socket/RubyIPSocket.java
25 changes: 7 additions & 18 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -395,6 +395,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) {
@@ -404,6 +408,8 @@ 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]);
@@ -735,24 +741,7 @@ protected static SocketLevel levelFromArg(IRubyObject _level) {
return level;
}

protected IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse) {
final Ruby runtime = context.runtime;
IRubyObject[] ret = new IRubyObject[4];
if (addr.getAddress() instanceof Inet6Address) {
ret[0] = runtime.newString("AF_INET6");
} else {
ret[0] = runtime.newString("AF_INET");
}
ret[1] = runtime.newFixnum(addr.getPort());
String hostAddress = addr.getAddress().getHostAddress();
if (!reverse || doNotReverseLookup(context)) {
ret[2] = runtime.newString(hostAddress);
} else {
ret[2] = runtime.newString(addr.getHostName());
}
ret[3] = runtime.newString(hostAddress);
return runtime.newArrayNoCopy(ret);
}
protected abstract IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse);

@Deprecated
public IRubyObject recv(IRubyObject[] args) {
20 changes: 20 additions & 0 deletions core/src/main/java/org/jruby/ext/socket/RubyIPSocket.java
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
import org.jruby.util.io.BadDescriptorException;
import org.jruby.util.io.Sockaddr;

import java.net.Inet6Address;
import java.net.InetSocketAddress;

/**
@@ -196,6 +197,25 @@ private Boolean doReverseLookup(ThreadContext context, IRubyObject noreverse) {
}
}

protected IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse) {
final Ruby runtime = context.runtime;
IRubyObject[] ret = new IRubyObject[4];
if (addr.getAddress() instanceof Inet6Address) {
ret[0] = runtime.newString("AF_INET6");
} else {
ret[0] = runtime.newString("AF_INET");
}
ret[1] = runtime.newFixnum(addr.getPort());
String hostAddress = addr.getAddress().getHostAddress();
if (!reverse || doNotReverseLookup(context)) {
ret[2] = runtime.newString(hostAddress);
} else {
ret[2] = runtime.newString(addr.getHostName());
}
ret[3] = runtime.newString(hostAddress);
return runtime.newArrayNoCopy(ret);
}

@Deprecated
public IRubyObject addr() {
return addr(getRuntime().getCurrentContext());