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

Commits on Oct 11, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a65df74 View commit details
  2. Copy the full SHA
    e3c44b1 View commit details
  3. Copy the full SHA
    38ee84d View commit details

Commits on Oct 12, 2016

  1. Fix UNIXServer#accept_nonblock(exception: false)

    Introduced in cc79119
    etehtsea committed Oct 12, 2016
    Copy the full SHA
    57e672c View commit details
  2. Copy the full SHA
    8cd1cbe View commit details
  3. Merge pull request #4221 from etehtsea/unix-socket-improvements

    UNIX sockets improvements
    enebo authored Oct 12, 2016
    Copy the full SHA
    8a8d577 View commit details
15 changes: 6 additions & 9 deletions core/src/main/java/org/jruby/ext/socket/RubySocket.java
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@
import jnr.constants.platform.SocketOption;
import jnr.constants.platform.TCP;
import jnr.netdb.Protocol;
import jnr.unixsocket.UnixServerSocket;
import jnr.unixsocket.UnixServerSocketChannel;
import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;
@@ -224,20 +225,16 @@ public IRubyObject connect(ThreadContext context, IRubyObject arg) {

@JRubyMethod()
public IRubyObject bind(ThreadContext context, IRubyObject arg) {
final InetSocketAddress iaddr;
final SocketAddress sockaddr;

if (arg instanceof Addrinfo) {
Addrinfo addr = (Addrinfo) arg;
if (!addr.ip_p(context).isTrue()) {
throw context.runtime.newTypeError("not an INET or INET6 address: " + addr);
}
iaddr = new InetSocketAddress(addr.getInetAddress().getHostAddress(), addr.getPort());
}
else {
iaddr = Sockaddr.addressFromSockaddr_in(context, arg);
sockaddr = addr.getSocketAddress();
} else {
sockaddr = Sockaddr.addressFromSockaddr(context, arg);
}

doBind(context, iaddr);
doBind(context, sockaddr);

return RubyFixnum.zero(context.runtime);
}
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/ext/socket/RubyUNIXServer.java
Original file line number Diff line number Diff line change
@@ -129,7 +129,10 @@ public IRubyObject accept_nonblock(ThreadContext context, Ruby runtime, boolean
try {
UnixSocketChannel socketChannel = ((UnixServerSocketChannel) selectable).accept();

if (socketChannel == null) throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
if (socketChannel == null) {
if (!ex) return runtime.newSymbol("wait_readable");
throw runtime.newErrnoEAGAINReadableError("accept(2) would block");
}

RubyUNIXSocket sock = (RubyUNIXSocket)(Helpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/ext/socket/RubyUNIXSocket.java
Original file line number Diff line number Diff line change
@@ -119,8 +119,8 @@ public IRubyObject addr(ThreadContext context) {
@JRubyMethod
public IRubyObject peeraddr(ThreadContext context) {
final Ruby runtime = context.runtime;

final RubyString path = openFile.getPath() == null ? RubyString.newEmptyString(runtime) : runtime.newString(openFile.getPath());
final String _path = getUnixRemoteSocket().path();
final RubyString path = (_path == null) ? RubyString.newEmptyString(runtime) : runtime.newString(_path);
return runtime.newArray( runtime.newString("AF_UNIX"), path );
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/socket/SocketType.java
Original file line number Diff line number Diff line change
@@ -246,7 +246,7 @@ public SocketAddress getRemoteSocketAddress(Channel channel) {
}

public SocketAddress getLocalSocketAddress(Channel channel) {
return new UnixSocketAddress(new File("empty-path"));
return new UnixSocketAddress(new File(""));
}
},

61 changes: 48 additions & 13 deletions core/src/main/java/org/jruby/util/io/Sockaddr.java
Original file line number Diff line number Diff line change
@@ -52,17 +52,6 @@ public static String stringFromAddress(Ruby runtime, InetAddress as) {
}
}

public static InetSocketAddress addressFromSockaddr_in(ThreadContext context, IRubyObject arg) {
RubyArray sockaddr = (RubyArray) unpack_sockaddr_in(context, arg);

IRubyObject addr = sockaddr.pop(context);
IRubyObject _port = sockaddr.pop(context);
int port = SocketUtils.portToInt(_port);

return new InetSocketAddress(
addr.convertToString().toString(), port);
}

public static InetSocketAddress addressFromArg(ThreadContext context, IRubyObject arg) {
InetSocketAddress iaddr;
if (arg instanceof Addrinfo) {
@@ -78,9 +67,49 @@ public static InetSocketAddress addressFromArg(ThreadContext context, IRubyObjec
return iaddr;
}

public static InetSocketAddress addressFromSockaddr_in(ThreadContext context, IRubyObject arg) {
ByteList val = arg.convertToString().getByteList();
return addressFromSockaddr_in(context, val);
}

public static InetSocketAddress addressFromSockaddr_in(ThreadContext context, ByteList val) {
RubyArray sockaddr = (RubyArray) unpack_sockaddr_in(context, val);

IRubyObject addr = sockaddr.pop(context);
IRubyObject _port = sockaddr.pop(context);
int port = SocketUtils.portToInt(_port);

return new InetSocketAddress(
addr.convertToString().toString(), port);
}

public static SocketAddress addressFromSockaddr(ThreadContext context, IRubyObject arg) {
Ruby runtime = context.runtime;

ByteList val = arg.convertToString().getByteList();

AddressFamily af = getAddressFamilyFromSockaddr(runtime, val);

switch (af) {
case AF_UNIX:
return addressFromSockaddr_un(context, val);
case AF_INET:
case AF_INET6:
return addressFromSockaddr_in(context, val);
default:
throw runtime.newArgumentError("can't resolve socket address of wrong type");

}
}

public static UnixSocketAddress addressFromSockaddr_un(ThreadContext context, IRubyObject arg) {
byte[] raw = arg.convertToString().getBytes();
String pathStr = pathFromSockaddr_un(context, raw);
ByteList val = arg.convertToString().getByteList();

return addressFromSockaddr_un(context, val);
}

public static UnixSocketAddress addressFromSockaddr_un(ThreadContext context, ByteList bl) {
String pathStr = pathFromSockaddr_un(context, bl.bytes());

return new UnixSocketAddress(new File(pathStr));
}
@@ -200,6 +229,12 @@ public static RubyArray unpack_sockaddr_in(ThreadContext context, IRubyObject ad

ByteList val = addr.convertToString().getByteList();

return unpack_sockaddr_in(context, val);
}

public static RubyArray unpack_sockaddr_in(ThreadContext context, ByteList val) {
final Ruby runtime = context.runtime;

AddressFamily af = getAddressFamilyFromSockaddr(runtime, val);

if (af != AddressFamily.AF_INET &&
3 changes: 0 additions & 3 deletions test/mri/excludes/TestSocket_UNIXSocket.rb
Original file line number Diff line number Diff line change
@@ -3,10 +3,7 @@
exclude :test_fd_passing, "close_on_exec? not implemented"
exclude :test_fd_passing_race_condition, "needs investigation"
exclude :test_getpeereid, "needs investigation"
exclude :test_initialize, "needs investigation"
exclude :test_noname_unpack_sockaddr_un, "needs investigation"
exclude :test_socket_pair_with_block, "needs investigation"
exclude :test_too_long_path, "needs investigation"
exclude :test_unix_server_socket, "needs investigation"
exclude :test_unix_socket_pair_with_block, "needs investigation"
exclude :test_cloexec, "needs investigation"