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

Commits on Aug 10, 2016

  1. Fix Socket::Option.new

    etehtsea committed Aug 10, 2016
    Copy the full SHA
    68da516 View commit details
  2. Copy the full SHA
    4c9cc20 View commit details

Commits on Aug 11, 2016

  1. Remove test_bool from excludes. Fixes #2997

    - Fix Socket::Option.int
    - Fix Socket::Option.bool
    - Fix Socket::Option#bool
    etehtsea committed Aug 11, 2016
    Copy the full SHA
    6b07e3c View commit details
  2. Copy the full SHA
    c27003e View commit details
  3. Remove Socket test_initialize from excludes

    Fix socket initialization with type passed as a string (for ex.
    'SOCK_STREAM')
    etehtsea committed Aug 11, 2016
    Copy the full SHA
    6f143cd View commit details
  4. Merge pull request #4038 from etehtsea/socket-options

    Fix some parts of Socket::Option
    enebo authored Aug 11, 2016
    Copy the full SHA
    1482ff8 View commit details
41 changes: 26 additions & 15 deletions core/src/main/java/org/jruby/ext/socket/Option.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import org.jruby.RubyClass;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.RubyNumeric;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
@@ -47,25 +48,25 @@ public Option(Ruby runtime, ProtocolFamily family, SocketLevel level, SocketOpti

public Option(Ruby runtime, RubyClass klass, ProtocolFamily family, SocketLevel level, SocketOption option, int data) {
super(runtime, klass);

this.family = family;
this.level = level;
this.option = option;
this.intData = data;
ByteList result = new ByteList(4);
this.data = Pack.packInt_i(result, data);
}

@JRubyMethod(required = 4, visibility = Visibility.PRIVATE)
public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
family = ProtocolFamily.valueOf(args[0].convertToInteger().getLongValue());
level = SocketLevel.valueOf(args[1].convertToInteger().getLongValue());
option = SocketOption.valueOf(args[2].convertToInteger().getLongValue());
family = SocketUtils.protocolFamilyFromArg(args[0]);
level = SocketUtils.levelFromArg(args[1]);
option = SocketUtils.optionFromArg(args[2]);
data = args[3].convertToString().getByteList();
intData = Pack.unpackInt_i(ByteBuffer.wrap(data.bytes()));
return context.nil;
return this;
}

@JRubyMethod
public IRubyObject family(ThreadContext context) {
return context.runtime.newFixnum(family.longValue());
@@ -166,24 +167,34 @@ private String optionValue() {
return "";
}

@JRubyMethod(meta = true)
public IRubyObject rb_int(ThreadContext context, IRubyObject self) {
return context.nil;
@JRubyMethod(name = "int", required = 4, meta = true)
public static IRubyObject rb_int(ThreadContext context, IRubyObject self, IRubyObject[] args) {
ProtocolFamily family = SocketUtils.protocolFamilyFromArg(args[0]);
SocketLevel level = SocketUtils.levelFromArg(args[1]);
SocketOption option = SocketUtils.optionFromArg(args[2]);
int intData = RubyNumeric.fix2int(args[3]);

return new Option(context.getRuntime(), family, level, option, intData);
}

@JRubyMethod(name = "int")
public IRubyObject asInt(ThreadContext context) {
return context.getRuntime().newFixnum((int) intData);
}

@JRubyMethod(meta = true)
public IRubyObject bool(ThreadContext context, IRubyObject self) {
return context.nil;
@JRubyMethod(required = 4, meta = true)
public static IRubyObject bool(ThreadContext context, IRubyObject self, IRubyObject[] args) {
ProtocolFamily family = SocketUtils.protocolFamilyFromArg(args[0]);
SocketLevel level = SocketUtils.levelFromArg(args[1]);
SocketOption option = SocketUtils.optionFromArg(args[2]);
int intData = args[3].isTrue() ? 1 : 0;

return new Option(context.getRuntime(), family, level, option, intData);
}

@JRubyMethod
public IRubyObject bool(ThreadContext context) {
return context.nil;
return context.getRuntime().newBoolean(intData != 0);
}

@JRubyMethod(meta = true)
28 changes: 4 additions & 24 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -248,8 +248,8 @@ protected final IRubyObject recv_nonblock(ThreadContext context,
public IRubyObject getsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt) {
Ruby runtime = context.runtime;

SocketLevel level = levelFromArg(_level);
SocketOption opt = optionFromArg(_opt);
SocketLevel level = SocketUtils.levelFromArg(_level);
SocketOption opt = SocketUtils.optionFromArg(_opt);

try {
Channel channel = getOpenChannel();
@@ -282,8 +282,8 @@ public IRubyObject getsockopt(ThreadContext context, IRubyObject _level, IRubyOb
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
Ruby runtime = context.runtime;

SocketLevel level = levelFromArg(_level);
SocketOption opt = optionFromArg(_opt);
SocketLevel level = SocketUtils.levelFromArg(_level);
SocketOption opt = SocketUtils.optionFromArg(_opt);

try {
Channel channel = getOpenChannel();
@@ -708,26 +708,6 @@ protected boolean asBoolean(IRubyObject val) {
return val.isTrue();
}

protected static SocketOption optionFromArg(IRubyObject _opt) {
SocketOption opt;
if (_opt instanceof RubyString || _opt instanceof RubySymbol) {
opt = SocketOption.valueOf("SO_" + _opt.toString());
} else {
opt = SocketOption.valueOf(RubyNumeric.fix2int(_opt));
}
return opt;
}

protected static SocketLevel levelFromArg(IRubyObject _level) {
SocketLevel level;
if (_level instanceof RubyString || _level instanceof RubySymbol) {
level = SocketLevel.valueOf("SOL_" + _level.toString());
} else {
level = SocketLevel.valueOf(RubyNumeric.fix2int(_level));
}
return level;
}

protected IRubyObject addrFor(ThreadContext context, InetSocketAddress addr, boolean reverse) {
final Ruby runtime = context.runtime;
IRubyObject ret0, ret1, ret2, ret3;
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
@@ -289,8 +289,8 @@ public static IRubyObject socketpair(ThreadContext context, IRubyObject recv, IR

@Override
public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyObject _opt, IRubyObject val) {
SocketLevel level = levelFromArg(_level);
SocketOption opt = optionFromArg(_opt);
SocketLevel level = SocketUtils.levelFromArg(_level);
SocketOption opt = SocketUtils.optionFromArg(_opt);

switch(level) {
case SOL_SOCKET:
25 changes: 24 additions & 1 deletion core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@
import jnr.constants.platform.AddressFamily;
import jnr.constants.platform.ProtocolFamily;
import jnr.constants.platform.Sock;
import jnr.constants.platform.SocketLevel;
import jnr.constants.platform.SocketOption;
import jnr.netdb.Protocol;
import jnr.netdb.Service;
import org.jruby.Ruby;
@@ -586,7 +588,8 @@ static Sock sockFromArg(IRubyObject type) {

if(type instanceof RubyString || type instanceof RubySymbol) {
String typeString = type.toString();
sockType = Sock.valueOf("SOCK_" + typeString);
if (!typeString.startsWith("SOCK_")) typeString = "SOCK_" + typeString;
sockType = Sock.valueOf(typeString);
} else {
int typeInt = RubyNumeric.fix2int(type);
sockType = Sock.valueOf(typeInt);
@@ -624,6 +627,26 @@ static Protocol protocolFromArg(IRubyObject protocol) {
return proto;
}

static SocketLevel levelFromArg(IRubyObject _level) {
SocketLevel level;
if (_level instanceof RubyString || _level instanceof RubySymbol) {
level = SocketLevel.valueOf("SOL_" + _level.toString());
} else {
level = SocketLevel.valueOf(RubyNumeric.fix2int(_level));
}
return level;
}

static SocketOption optionFromArg(IRubyObject _opt) {
SocketOption opt;
if (_opt instanceof RubyString || _opt instanceof RubySymbol) {
opt = SocketOption.valueOf("SO_" + _opt.toString());
} else {
opt = SocketOption.valueOf(RubyNumeric.fix2int(_opt));
}
return opt;
}

public static int portToInt(IRubyObject port) {
return port.isNil() ? 0 : RubyNumeric.fix2int(port);
}
1 change: 0 additions & 1 deletion test/mri/excludes/TestSocket.rb
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
exclude :test_getaddrinfo, "needs investigation"
exclude :test_getaddrinfo_raises_no_errors_on_port_argument_of_0, "needs investigation"
exclude :test_getnameinfo, "needs investigation"
exclude :test_initialize, "needs investigation"
exclude :test_linger, "needs investigation"
exclude :test_listen_in_rescue, "needs investigation"
exclude :test_recvmsg_udp_no_arg, "needs investigation"
3 changes: 0 additions & 3 deletions test/mri/excludes/TestSocketOption.rb

This file was deleted.