Skip to content

Commit

Permalink
Showing 12 changed files with 343 additions and 330 deletions.
61 changes: 32 additions & 29 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -3960,40 +3960,43 @@ public RaiseException newStandardError(String message) {
* TODO: Should ECONNABORTED get thrown earlier in the descriptor itself or is it ok to handle this late?
* TODO: Should we include this into Errno code somewhere do we can use this from other places as well?
*/
public RaiseException newIOErrorFromException(IOException e) {
if (e instanceof ClosedChannelException || "Bad file descriptor".equals(e.getMessage())) {
throw newErrnoEBADFError();
}

// TODO: this is kinda gross
if(e.getMessage() != null) {
String errorMessage = e.getMessage();
public RaiseException newIOErrorFromException(final IOException ex) {
final String errorMessage = ex.getMessage();
if ( errorMessage != null ) {
// All errors to sysread should be SystemCallErrors, but on a closed stream
// Ruby returns an IOError. Java throws same exception for all errors so
// we resort to this hack...
if ("File not open".equals(errorMessage)) {
return newIOError(e.getMessage());
} else if ("An established connection was aborted by the software in your host machine".equals(errorMessage)) {
return newErrnoECONNABORTEDError();
} else if (e.getMessage().equals("Broken pipe")) {
return newErrnoEPIPEError();
} else if ("Connection reset by peer".equals(e.getMessage())
|| "An existing connection was forcibly closed by the remote host".equals(e.getMessage()) ||
(Platform.IS_WINDOWS && e.getMessage().contains("connection was aborted"))) {
return newErrnoECONNRESETError();
} else if ("Too many levels of symbolic links".equals(e.getMessage())) {
return newErrnoELOOPError();
} else if ("Too many open files".equals(e.getMessage())) {
return newErrnoEMFILEError();
} else if ("Too many open files in system".equals(e.getMessage())) {
return newErrnoENFILEError();
} else if ("Network is unreachable".equals(e.getMessage())) {
return newErrnoENETUNREACHError();
switch ( errorMessage ) {
case "Bad file descriptor" :
if ( ex instanceof ClosedChannelException ) throw newErrnoEBADFError();
break;
case "File not open" :
return newIOError(errorMessage);
case "An established connection was aborted by the software in your host machine" :
return newErrnoECONNABORTEDError();
case "Broken pipe" :
return newErrnoEPIPEError();
case "Connection reset by peer" :
case "An existing connection was forcibly closed by the remote host" :
return newErrnoECONNRESETError();
case "Too many levels of symbolic links" :
return newErrnoELOOPError();
case "Too many open files" :
return newErrnoEMFILEError();
case "Too many open files in system" :
return newErrnoENFILEError();
case "Network is unreachable" :
return newErrnoENETUNREACHError();
default :
if ( Platform.IS_WINDOWS ) {
if ( errorMessage.contains("connection was aborted") ) {
return newErrnoECONNRESETError();
}
}
}
return newRaiseException(getIOError(), e.getMessage());
} else {
return newRaiseException(getIOError(), "IO Error");
return newRaiseException(getIOError(), errorMessage);
}
return newRaiseException(getIOError(), "IO Error");
}

public RaiseException newTypeError(IRubyObject receivedObject, RubyClass expectedType) {
36 changes: 14 additions & 22 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -2891,21 +2891,15 @@ private IRubyObject getPartial(ThreadContext context, IRubyObject[] args, boolea
// MRI: rb_io_sysread
@JRubyMethod(name = "sysread", required = 1, optional = 1)
public IRubyObject sysread(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
IRubyObject len, str;
OpenFile fptr;
int ilen, n;
// struct read_internal_arg arg;

len = args.length >= 1 ? args[0] : context.nil;
str = args.length >= 2 ? args[1] : context.nil;
ilen = RubyNumeric.num2int(len);
final Ruby runtime = context.runtime;

str = EncodingUtils.setStrBuf(runtime, str, (int)ilen);
if (ilen == 0) return str;
final int length = RubyNumeric.num2int(args.length >= 1 ? args[0] : context.nil);
RubyString str = EncodingUtils.setStrBuf(runtime, args.length >= 2 ? args[1] : context.nil, length);
if (length == 0) return str;

fptr = getOpenFileChecked();
final OpenFile fptr = getOpenFileChecked();

final int n;
boolean locked = fptr.lock();
try {
fptr.checkByteReadable(context);
@@ -2926,23 +2920,21 @@ public IRubyObject sysread(ThreadContext context, IRubyObject[] args) {

fptr.checkClosed();

str = EncodingUtils.setStrBuf(runtime, str, ilen);
ByteList strByteList = ((RubyString) str).getByteList();
n = OpenFile.readInternal(context, fptr, fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), ilen);
ByteList strByteList = str.getByteList();
n = OpenFile.readInternal(context, fptr, fptr.fd(), strByteList.unsafeBytes(), strByteList.begin(), length);

if (n == -1) {
throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath());
}
} finally {
}
finally {
if (locked) fptr.unlock();
}

((RubyString)str).setReadLength(n);
if (n == 0 && ilen > 0) {
throw runtime.newEOFError();
}
if (n == 0 && length > 0) throw runtime.newEOFError();

str.setReadLength(n);
str.setTaint(true);

return str;
}

@@ -4654,7 +4646,7 @@ private static int rb_io_fptr_finalize(Ruby runtime, OpenFile fptr) {
return 1;
}

private static final byte[] NEWLINE_BYTES = {(byte)'\n'};
private static final byte[] NEWLINE_BYTES = { (byte) '\n' };

@Deprecated
public IRubyObject getline(Ruby runtime, ByteList separator) {
26 changes: 11 additions & 15 deletions core/src/main/java/org/jruby/ext/socket/RubyBasicSocket.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2007 Ola Bini <ola@ologix.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -28,10 +28,6 @@

package org.jruby.ext.socket;

import static jnr.constants.platform.IPProto.IPPROTO_TCP;
import static jnr.constants.platform.IPProto.IPPROTO_IP;
import static jnr.constants.platform.TCP.TCP_NODELAY;

import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetSocketAddress;
@@ -44,6 +40,9 @@
import jnr.constants.platform.Fcntl;
import jnr.constants.platform.ProtocolFamily;
import jnr.constants.platform.Sock;
import jnr.constants.platform.SocketLevel;
import jnr.constants.platform.SocketOption;

import org.jruby.Ruby;
import org.jruby.RubyBoolean;
import org.jruby.RubyClass;
@@ -64,13 +63,12 @@
import org.jruby.util.Pack;
import org.jruby.util.io.BadDescriptorException;
import org.jruby.util.io.ChannelFD;
import org.jruby.util.io.FilenoUtil;
import org.jruby.util.io.OpenFile;

import jnr.constants.platform.SocketLevel;
import jnr.constants.platform.SocketOption;
import org.jruby.util.io.Sockaddr;

import static jnr.constants.platform.IPProto.IPPROTO_TCP;
import static jnr.constants.platform.IPProto.IPPROTO_IP;
import static jnr.constants.platform.TCP.TCP_NODELAY;

/**
* Implementation of the BasicSocket class from Ruby.
@@ -166,7 +164,7 @@ public IRubyObject recv(ThreadContext context, IRubyObject _length) {

return RubyString.newString(runtime, bytes);
}

@JRubyMethod
public IRubyObject recv(ThreadContext context, IRubyObject _length, IRubyObject _flags) {
// TODO: implement flags
@@ -199,8 +197,6 @@ public IRubyObject getsockopt(ThreadContext context, IRubyObject _level, IRubyOb
SocketLevel level = levelFromArg(_level);
SocketOption opt = optionFromArg(_opt);

int value = 0;

try {
Channel channel = getOpenChannel();

@@ -215,8 +211,8 @@ public IRubyObject getsockopt(ThreadContext context, IRubyObject _level, IRubyOb
throw runtime.newErrnoENOPROTOOPTError();
}

value = SocketType.forChannel(channel).getSocketOption(channel, opt);
int value = SocketType.forChannel(channel).getSocketOption(channel, opt);

return new Option(runtime, ProtocolFamily.PF_INET, level, opt, value);

default:
@@ -626,7 +622,7 @@ protected void initSocket(ChannelFD fd) {
// see rsock_init_sock in MRI; sockets are initialized to binary
setAscii8bitBinmode();
}

private Channel getOpenChannel() {
return getOpenFileChecked().channel();
}
101 changes: 48 additions & 53 deletions core/src/main/java/org/jruby/ext/socket/RubySocket.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,25 @@
***** END LICENSE BLOCK *****/
package org.jruby.ext.socket;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ConnectionPendingException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SocketChannel;
import java.util.Enumeration;
import java.util.regex.Pattern;

import jnr.constants.platform.AddressFamily;
import jnr.constants.platform.INAddr;
import jnr.constants.platform.IPProto;
@@ -40,45 +59,22 @@
import jnr.netdb.Protocol;
import jnr.unixsocket.UnixSocketAddress;
import jnr.unixsocket.UnixSocketChannel;

import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
import org.jruby.RubyModule;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.io.ChannelFD;
import org.jruby.util.io.FilenoUtil;
import org.jruby.util.io.ModeFlags;
import org.jruby.util.io.Sockaddr;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.channels.AlreadyConnectedException;
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ConnectionPendingException;
import java.nio.channels.DatagramChannel;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SocketChannel;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import org.jruby.RubyArray;

import static org.jruby.runtime.Helpers.arrayOf;

/**
@@ -212,7 +208,7 @@ public IRubyObject connect(ThreadContext context, IRubyObject arg) {

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

if (arg instanceof Addrinfo){
Addrinfo addr = (Addrinfo) arg;
@@ -390,7 +386,7 @@ private void initFieldsFromArgs(Ruby runtime, IRubyObject domain, IRubyObject ty

initType(runtime, type);

initProtocol(runtime, protocol);
initProtocol(protocol);
}

private void initFieldsFromArgs(Ruby runtime, IRubyObject domain, IRubyObject type) {
@@ -408,39 +404,38 @@ protected void initFromServer(Ruby runtime, RubyServerSocket serverSocket, Socke
}

protected ChannelFD initChannelFD(Ruby runtime) {
Channel channel;

try {
if(soType == Sock.SOCK_STREAM) {

if (soProtocolFamily == ProtocolFamily.PF_UNIX ||
soProtocolFamily == ProtocolFamily.PF_LOCAL) {
channel = UnixSocketChannel.open();
} else if (soProtocolFamily == ProtocolFamily.PF_INET ||
soProtocolFamily == ProtocolFamily.PF_INET6 ||
soProtocolFamily == ProtocolFamily.PF_UNSPEC) {
channel = SocketChannel.open();
} else {
throw runtime.newArgumentError("unsupported protocol family `" + soProtocolFamily + "'");
}

} else if(soType == Sock.SOCK_DGRAM) {
channel = DatagramChannel.open();

} else {
throw runtime.newArgumentError("unsupported socket type `" + soType + "'");

Channel channel;
switch (soType) {
case SOCK_STREAM:
if ( soProtocolFamily == ProtocolFamily.PF_UNIX ||
soProtocolFamily == ProtocolFamily.PF_LOCAL ) {
channel = UnixSocketChannel.open();
}
else if ( soProtocolFamily == ProtocolFamily.PF_INET ||
soProtocolFamily == ProtocolFamily.PF_INET6 ||
soProtocolFamily == ProtocolFamily.PF_UNSPEC ) {
channel = SocketChannel.open();
}
else {
throw runtime.newArgumentError("unsupported protocol family `" + soProtocolFamily + "'");
}
break;
case SOCK_DGRAM:
channel = DatagramChannel.open();
break;
default:
throw runtime.newArgumentError("unsupported socket type `" + soType + "'");
}

return newChannelFD(runtime, channel);

} catch(IOException e) {
}
catch(IOException e) {
throw SocketUtils.sockerr(runtime, "initialize: " + e.toString());

}
}

private void initProtocol(Ruby runtime, IRubyObject protocol) {
private void initProtocol(IRubyObject protocol) {
soProtocol = SocketUtils.protocolFromArg(protocol);
}

@@ -501,7 +496,7 @@ protected void doConnect(ThreadContext context, Channel channel, SocketAddress a
if (channel instanceof SocketChannel) {
SocketChannel socket = (SocketChannel)channel;
boolean result;

if (socket.isConnectionPending()) {
// connection initiated but not finished
result = socket.finishConnect();
92 changes: 49 additions & 43 deletions core/src/main/java/org/jruby/ext/socket/RubyUDPSocket.java
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2007 Damian Steer <pldms@mac.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -51,6 +51,7 @@
import org.jruby.RubyString;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
@@ -66,7 +67,7 @@ public class RubyUDPSocket extends RubyIPSocket {

static void createUDPSocket(Ruby runtime) {
RubyClass rb_cUDPSocket = runtime.defineClass("UDPSocket", runtime.getClass("IPSocket"), UDPSOCKET_ALLOCATOR);

rb_cUDPSocket.includeModule(runtime.getClass("Socket").getConstant("Constants"));

rb_cUDPSocket.defineAnnotatedMethods(RubyUDPSocket.class);
@@ -196,7 +197,7 @@ public IRubyObject connect(ThreadContext context, IRubyObject host, IRubyObject

@JRubyMethod
public IRubyObject recvfrom_nonblock(ThreadContext context, IRubyObject _length) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

try {
int length = RubyNumeric.fix2int(_length);
@@ -206,17 +207,18 @@ public IRubyObject recvfrom_nonblock(ThreadContext context, IRubyObject _length)
IRubyObject addressArray = addrFor(context, tuple.sender, false);

return runtime.newArray(tuple.result, addressArray);

} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known");

} catch (PortUnreachableException e) {
}
catch (PortUnreachableException e) {
throw runtime.newErrnoECONNREFUSEDError();

} catch (IOException e) {
}
catch (IOException e) { // SocketException
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
}
catch (RaiseException e) { throw e; }
catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}
@@ -230,7 +232,7 @@ public IRubyObject recvfrom_nonblock(ThreadContext context, IRubyObject _length,
@JRubyMethod
public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _flags) {
// TODO: implement flags
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

try {
int written;
@@ -241,17 +243,18 @@ public IRubyObject send(ThreadContext context, IRubyObject _mesg, IRubyObject _f
written = ((DatagramChannel) this.getChannel()).write(buf);

return runtime.newFixnum(written);

} catch (NotYetConnectedException nyce) {
}
catch (NotYetConnectedException e) {
throw runtime.newErrnoEDESTADDRREQError("send(2)");

} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "send: name or service not known");

} catch (IOException e) {
}
catch (IOException e) { // SocketException
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
}
catch (RaiseException e) { throw e; }
catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}
@@ -274,7 +277,7 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args) {
if (args.length == 2 || args.length == 3) {
return send(context, _mesg, _flags);
}

IRubyObject _host = args[2];
IRubyObject _port = args[3];

@@ -317,13 +320,15 @@ public IRubyObject send(ThreadContext context, IRubyObject[] args) {

return runtime.newFixnum(written);

} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "send: name or service not known");

} catch (IOException e) {
}
catch (IOException e) { // SocketException
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
}
catch (RaiseException e) { throw e; }
catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}
@@ -351,7 +356,7 @@ public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObj
*/
@Override
public IRubyObject recvfrom(ThreadContext context, IRubyObject _length) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

try {
int length = RubyNumeric.fix2int(_length);
@@ -361,17 +366,18 @@ public IRubyObject recvfrom(ThreadContext context, IRubyObject _length) {
IRubyObject addressArray = addrFor(context, tuple.sender, false);

return runtime.newArray(tuple.result, addressArray);

} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
throw SocketUtils.sockerr(runtime, "recvfrom: name or service not known");

} catch (PortUnreachableException e) {
}
catch (PortUnreachableException e) {
throw runtime.newErrnoECONNREFUSEDError();

} catch (IOException e) {
}
catch (IOException e) { // SocketException
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
}
catch (RaiseException e) { throw e; }
catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());
}
}
@@ -390,17 +396,17 @@ public IRubyObject recvfrom(ThreadContext context, IRubyObject _length, IRubyObj
*/
@Override
public IRubyObject recv(ThreadContext context, IRubyObject _length) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

try {
return doReceive(runtime, RubyNumeric.fix2int(_length));

} catch (IOException e) {
}
catch (IOException e) { // SocketException
throw runtime.newIOErrorFromException(e);

} catch (Exception e) {
}
catch (RaiseException e) { throw e; }
catch (Exception e) {
throw SocketUtils.sockerr(runtime, e.getLocalizedMessage());

}
}

@@ -435,8 +441,8 @@ private ReceiveTuple doReceiveNonblockTuple(Ruby runtime, int length) throws IOE

try {
return doReceiveTuple(runtime, length);

} finally {
}
finally {
channel.configureBlocking(oldBlocking);
}
}
26 changes: 13 additions & 13 deletions core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Original file line number Diff line number Diff line change
@@ -129,18 +129,18 @@ public static IRubyObject getservbyname(ThreadContext context, IRubyObject[] arg
}

public static IRubyObject pack_sockaddr_in(ThreadContext context, IRubyObject port, IRubyObject host) {
int portNum = 0;

if(!port.isNil()){
portNum = port instanceof RubyString ?
Integer.parseInt(port.convertToString().toString()) :
RubyNumeric.fix2int(port);
final int portNum;
if ( ! port.isNil() ) {
portNum = port instanceof RubyString ?
Integer.parseInt(port.convertToString().toString()) :
RubyNumeric.fix2int(port);
}
else {
portNum = 0;
}

return Sockaddr.pack_sockaddr_in(
context,
portNum,
host.isNil() ? null : host.convertToString().toString());
final String hostStr = host.isNil() ? null : host.convertToString().toString();
return Sockaddr.pack_sockaddr_in(context, portNum, hostStr);
}

public static IRubyObject unpack_sockaddr_in(ThreadContext context, IRubyObject addr) {
@@ -318,7 +318,7 @@ public static void buildAddrinfoList(ThreadContext context, IRubyObject[] args,
} else if ("numeric".equals(reverseString)) {
reverseLookup = false;
} else {
throw runtime.newArgumentError("invalid reverse_lookup flag: :" +
throw runtime.newArgumentError("invalid reverse_lookup flag: :" +
reverseString);
}
}
@@ -555,7 +555,7 @@ public static int getPortFrom(ThreadContext context, IRubyObject _port) {
private static String getHostAddress(ThreadContext context, InetAddress addr, Boolean reverse) {
String ret;
if (reverse == null) {
ret = context.runtime.isDoNotReverseLookupEnabled() ?
ret = context.runtime.isDoNotReverseLookupEnabled() ?
addr.getHostAddress() : addr.getCanonicalHostName();
} else if (reverse) {
ret = addr.getCanonicalHostName();
@@ -632,7 +632,7 @@ static Protocol protocolFromArg(IRubyObject protocol) {

return proto;
}

public static int portToInt(IRubyObject port) {
return port.isNil() ? 0 : RubyNumeric.fix2int(port);
}
278 changes: 139 additions & 139 deletions core/src/main/java/org/jruby/util/io/EncodingUtils.java

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions core/src/main/java/org/jruby/util/io/Sockaddr.java
Original file line number Diff line number Diff line change
@@ -125,15 +125,15 @@ public static IRubyObject packSockaddrFromAddress(ThreadContext context, InetSoc
}
}

public static IRubyObject pack_sockaddr_in(ThreadContext context, int iport, String host) {
public static IRubyObject pack_sockaddr_in(ThreadContext context, int port, String host) {
ByteArrayOutputStream bufS = new ByteArrayOutputStream();
try {
DataOutputStream ds = new DataOutputStream(bufS);

try {
if(host != null && "".equals(host)) {
if ( host != null && host.length() == 0 ) {
writeSockaddrHeader(AddressFamily.AF_INET, ds);
writeSockaddrPort(ds, iport);
writeSockaddrPort(ds, port);
ds.writeInt(0);
} else {
InetAddress[] addrs = InetAddress.getAllByName(host);
@@ -145,16 +145,18 @@ public static IRubyObject pack_sockaddr_in(ThreadContext context, int iport, Str
writeSockaddrHeader(AddressFamily.AF_INET6, ds);
}

writeSockaddrPort(ds, iport);
writeSockaddrPort(ds, port);

ds.write(addr, 0, addr.length);
}
} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
throw sockerr(context.runtime, "getaddrinfo: No address associated with nodename");
}

writeSockaddrFooter(ds);
} catch (IOException e) {
}
catch (IOException e) {
throw sockerr(context.runtime, "pack_sockaddr_in: internal error");
}

4 changes: 2 additions & 2 deletions lib/pom.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ def initialize( name, version, default_spec = true )

default_gems =
[
ImportedGem.new( 'jruby-openssl', '0.9.12' ),
ImportedGem.new( 'jruby-openssl', '0.9.13' ),
ImportedGem.new( 'jruby-readline', '1.0', false ),
ImportedGem.new( 'rake', '${rake.version}' ),
ImportedGem.new( 'rdoc', '${rdoc.version}' ),
@@ -186,7 +186,7 @@ def initialize( name, version, default_spec = true )

specname = File.basename( specfile )
puts "copy to specifications/default: #{specname}"

spec = Gem::Package.new( Dir[ File.join( cache, "#{g.name}-#{version}*.gem" ) ].first ).spec
File.open( File.join( default_specs, specname ), 'w' ) do |f|
f.print( spec.to_ruby )
2 changes: 1 addition & 1 deletion lib/pom.xml
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>jruby-openssl</artifactId>
<version>0.9.12</version>
<version>0.9.13</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
14 changes: 11 additions & 3 deletions lib/ruby/stdlib/resolv.rb
Original file line number Diff line number Diff line change
@@ -34,10 +34,10 @@
# * /etc/nsswitch.conf is not supported.

class Resolv

##
# Tests whether we're running on Windows

WINDOWS = /mswin|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM || ::RbConfig::CONFIG['host_os'] =~ /mswin/

##
@@ -1187,7 +1187,7 @@ def inspect
end

def ==(other)
return @downcase == other.downcase
return self.class == other.class && @downcase == other.downcase
end

def eql?(other)
@@ -1223,6 +1223,14 @@ def self.create(arg)
end

def initialize(labels, absolute=true) # :nodoc:
labels = labels.map {|label|
case label
when String then Label::Str.new(label)
when Label::Str then label
else
raise ArgumentError, "unexpected label: #{label.inspect}"
end
}
@labels = labels
@absolute = absolute
end
19 changes: 15 additions & 4 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ def help
puts 'jt tag all spec/ruby/language tag all specs in this file, without running them'
puts 'jt untag spec/ruby/language untag passing specs in this directory'
puts 'jt untag spec/ruby/language/while_spec.rb untag passing specs in this file'
puts 'jt bench debug [--ruby-backtrace] benchmark run a single benchmark with options for compiler debugging'
puts 'jt bench debug [--ruby-backtrace] [vm-args] benchmark run a single benchmark with options for compiler debugging'
puts 'jt bench reference [benchmarks] run a set of benchmarks and record a reference point'
puts 'jt bench compare [benchmarks] run a set of benchmarks and compare against a reference point'
puts ' benchmarks can be any benchmarks or group of benchmarks supported'
@@ -444,13 +444,24 @@ def bench(command, *args)
bench_args = ["#{bench_dir}/bin/bench9000"]
case command
when 'debug'
vm_args = ['-Djvmci.option.TraceTruffleCompilation=true', '-Djvmci.option.DumpOnError=true']
if args.delete '--ruby-backtrace'
compilation_exceptions_behaviour = '-J-Djvmci.option.TruffleCompilationExceptionsAreThrown=true'
vm_args.push '-Djvmci.option.TruffleCompilationExceptionsAreThrown=true'
else
compilation_exceptions_behaviour = '-J-Djvmci.option.TruffleCompilationExceptionsAreFatal=true'
vm_args.push '-Djvmci.option.TruffleCompilationExceptionsAreFatal=true'
end
remaining_args = []
args.each do |arg|
if arg.start_with? '-'
vm_args.push arg
else
remaining_args.push arg
end
end
env_vars["JRUBY_OPTS"] = vm_args.map{ |a| '-J' + a }.join(' ')
bench_args += ['score', '--config', "#{bench_dir}/benchmarks/default.config.rb", 'jruby-dev-truffle-graal', '--show-commands', '--show-samples']
raise 'specify a single benchmark for run - eg classic-fannkuch-redux' if args.size != 1
raise 'specify a single benchmark for run - eg classic-fannkuch-redux' if remaining_args.size != 1
args = remaining_args
when 'reference'
bench_args += ['reference', '--config', "#{bench_dir}/benchmarks/default.config.rb", 'jruby-dev-truffle-graal', '--show-commands']
args << "5" if args.empty?

0 comments on commit 4930716

Please sign in to comment.