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

Commits on Aug 7, 2015

  1. Copy the full SHA
    aeed6c5 View commit details
  2. Implement Socket::Option#int.

    eregon committed Aug 7, 2015
    Copy the full SHA
    a4952c7 View commit details
  3. Copy the full SHA
    5367332 View commit details
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/ext/socket/Option.java
Original file line number Diff line number Diff line change
@@ -170,9 +170,9 @@ public IRubyObject rb_int(ThreadContext context, IRubyObject self) {
return context.nil;
}

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

@JRubyMethod(meta = true)
2 changes: 1 addition & 1 deletion spec/ruby/library/socket/tcpserver/new_spec.rb
Original file line number Diff line number Diff line change
@@ -87,6 +87,6 @@ def t.to_str; SocketSpecs.port.to_s; end

it "sets SO_REUSEADDR on the resulting server" do
@server = TCPServer.new('127.0.0.1', SocketSpecs.port)
@server.getsockopt(:SOCKET, :REUSEADDR).should == 1
@server.getsockopt(:SOCKET, :REUSEADDR).int.should == 1
end
end
Original file line number Diff line number Diff line change
@@ -65,6 +65,11 @@ public long typeSize(int type) {
}
}

@Specialization
public Object fallback(Object type) {
return null; // Primitive failure
}

}

}
Original file line number Diff line number Diff line change
@@ -10,16 +10,22 @@
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;

import jnr.constants.platform.Fcntl;
import jnr.ffi.Pointer;

import org.jruby.RubyEncoding;
import org.jruby.platform.Platform;
import org.jruby.truffle.nodes.constants.GetConstantNode;
import org.jruby.truffle.nodes.core.CoreClass;
import org.jruby.truffle.nodes.core.CoreMethod;
import org.jruby.truffle.nodes.core.CoreMethodArrayArgumentsNode;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.nodes.core.SymbolNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.core.RubyBasicObject;
@@ -1038,4 +1044,27 @@ public int getSockName(int socket, RubyBasicObject address, RubyBasicObject addr

}

@CoreMethod(names = "_getsockopt", isModuleFunction = true, required = 5)
public abstract static class GetSockOptNode extends CoreMethodArrayArgumentsNode {

public GetSockOptNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@CompilerDirectives.TruffleBoundary
@Specialization(guards = { "isRubyPointer(optval)", "isRubyPointer(optlen)" })
public int getSockOptions(int sockfd, int level, int optname, RubyBasicObject optval, RubyBasicObject optlen) {
return nativeSockets().getsockopt(sockfd, level, optname, PointerNodes.getPointer(optval), PointerNodes.getPointer(optlen));
}

// This should probably done at a higher-level, but rubysl/socket does not handle it.
@Specialization(guards = { "isRubySymbol(level)", "isRubySymbol(optname)", "isRubyPointer(optval)", "isRubyPointer(optlen)" })
public int getSockOptionsSymbols(VirtualFrame frame, int sockfd, RubyBasicObject level, RubyBasicObject optname, RubyBasicObject optval, RubyBasicObject optlen) {
int levelInt = (int) ruby(frame, "Socket::SOL_" + SymbolNodes.getString(level));
int optnameInt = (int) ruby(frame, "Socket::SO_" + SymbolNodes.getString(optname));
return getSockOptions(sockfd, levelInt, optnameInt, optval, optlen);
}

}

}
Original file line number Diff line number Diff line change
@@ -105,6 +105,13 @@ public interface NativeSockets {

int getsockname(int socket, Pointer address, Pointer address_len);

/*
* int getsockopt(int sockfd, int level, int optname,
* void *optval, socklen_t *optlen);
*/
int getsockopt(int sockfd, int level, int optname, Pointer optval, Pointer optlen);


/**
* int connect(int sockfd, const struct sockaddr *addr,
* socklen_t addrlen);