Permalink
Browse files

Spec cleanup relating to recent socket work.

* Untag a bunch of specs for things now working
* Tag some UNIXSocket specs that need work
* Update to enxio 2.0-SNAPSHOT
  • Loading branch information...
1 parent 72eafa4 commit cd18b42dfe59e8823275f4e10fcd43f084a7fec3 @headius headius committed Mar 13, 2012
Showing with 109 additions and 61 deletions.
  1. +6 −2 build.xml
  2. BIN build_lib/jnr-enxio-0.1.jar
  3. BIN build_lib/jnr-enxio.jar
  4. BIN build_lib/{jnr-unixsocket-0.1.jar → jnr-unixsocket.jar}
  5. +11 −6 shared.iml
  6. +0 −1 spec/jruby.1.8.mspec
  7. +0 −1 spec/jruby.1.9.mspec
  8. +0 −2 spec/tags/1.8/ruby/library/socket/socket/getaddrinfo_tags.txt
  9. +1 −1 spec/tags/1.8/ruby/library/socket/socket/gethostbyname_tags.txt
  10. +0 −1 spec/tags/1.8/ruby/library/socket/tcpserver/accept_nonblock_tags.txt
  11. +0 −1 spec/tags/1.8/ruby/library/socket/tcpsocket/recv_nonblock_tags.txt
  12. +0 −2 spec/tags/1.8/ruby/library/socket/udpsocket/send_tags.txt
  13. +0 −2 spec/tags/1.8/ruby/library/socket/unixserver/accept_tags.txt
  14. +0 −1 spec/tags/1.9/ruby/library/socket/basicsocket/send_tags.txt
  15. +1 −1 spec/tags/1.9/ruby/library/socket/socket/gethostbyname_tags.txt
  16. +0 −1 spec/tags/1.9/ruby/library/socket/tcpserver/accept_nonblock_tags.txt
  17. +0 −1 spec/tags/1.9/ruby/library/socket/tcpserver/gets_tags.txt
  18. +0 −1 spec/tags/1.9/ruby/library/socket/tcpsocket/recv_nonblock_tags.txt
  19. +0 −3 spec/tags/1.9/ruby/library/socket/udpsocket/send_tags.txt
  20. +0 −2 spec/tags/1.9/ruby/library/socket/unixserver/accept_tags.txt
  21. +1 −1 src/org/jruby/RubyIO.java
  22. +10 −5 src/org/jruby/ext/socket/RubyBasicSocket.java
  23. +21 −1 src/org/jruby/ext/socket/RubyTCPServer.java
  24. +2 −2 src/org/jruby/ext/socket/RubyTCPSocket.java
  25. +20 −7 src/org/jruby/ext/socket/RubyUNIXServer.java
  26. +2 −0 src/org/jruby/ext/socket/RubyUNIXSocket.java
  27. +12 −5 src/org/jruby/ext/socket/SocketType.java
  28. +22 −11 src/org/jruby/ext/socket/SocketUtils.java
View
@@ -346,8 +346,8 @@
<zipfileset src="${build.lib.dir}/jnr-netdb.jar"/>
<zipfileset src="${build.lib.dir}/jnr-posix.jar"/>
<zipfileset src="${build.lib.dir}/jnr-ffi.jar"/>
- <zipfileset src="${build.lib.dir}/jnr-enxio-0.1.jar"/>
- <zipfileset src="${build.lib.dir}/jnr-unixsocket-0.1.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-enxio.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-unixsocket.jar"/>
<zipfileset src="${build.lib.dir}/jffi.jar"/>
<zipfileset src="${build.lib.dir}/jffi-i386-Linux.jar"/>
<zipfileset src="${build.lib.dir}/jffi-x86_64-Linux.jar"/>
@@ -452,6 +452,8 @@
<zipfileset src="${build.lib.dir}/jnr-netdb.jar"/>
<zipfileset src="${build.lib.dir}/jnr-posix.jar"/>
<zipfileset src="${build.lib.dir}/jnr-ffi.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-enxio.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-unixsocket.jar"/>
<zipfileset src="${build.lib.dir}/jffi.jar"/>
<zipfileset src="${build.lib.dir}/jffi-i386-Linux.jar"/>
<zipfileset src="${build.lib.dir}/jffi-x86_64-Linux.jar"/>
@@ -608,6 +610,8 @@
<zipfileset src="${build.lib.dir}/jnr-netdb.jar"/>
<zipfileset src="${build.lib.dir}/jnr-posix.jar"/>
<zipfileset src="${build.lib.dir}/jnr-ffi.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-enxio.jar"/>
+ <zipfileset src="${build.lib.dir}/jnr-unixsocket.jar"/>
<zipfileset src="${build.lib.dir}/jffi.jar"/>
<zipfileset src="${build.lib.dir}/jffi-i386-Linux.jar"/>
<zipfileset src="${build.lib.dir}/jffi-x86_64-Linux.jar"/>
View
Binary file not shown.
View
Binary file not shown.
File renamed without changes.
View
@@ -499,14 +499,19 @@
<orderEntry type="module-library">
<library>
<CLASSES>
- <root url="jar://$MODULE_DIR$/build_lib/jnr-unixsocket-0.1.jar!/" />
- <root url="jar://$MODULE_DIR$/build_lib/jnr-enxio-0.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/build_lib/jnr-enxio.jar!/" />
</CLASSES>
<JAVADOC />
- <SOURCES>
- <root url="file://$MODULE_DIR$/build_lib" />
- </SOURCES>
- <jarDirectory url="file://$MODULE_DIR$/build_lib" recursive="false" type="SOURCES" />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/build_lib/jnr-unixsocket.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
</library>
</orderEntry>
</component>
View
@@ -53,7 +53,6 @@ class MSpecScript
'^' + SPEC_DIR + '/library/readline',
# unstable
- '^' + SPEC_DIR + '/library/socket',
'^' + SPEC_DIR + '/library/syslog',
# 1.9 feature
View
@@ -55,7 +55,6 @@ class MSpecScript
'^' + SPEC_DIR + '/library/readline',
# unstable
- '^' + SPEC_DIR + '/library/socket',
'^' + SPEC_DIR + '/library/syslog',
# obsolete libraries
@@ -1,2 +0,0 @@
-fails:Socket#getaddrinfo accepts empty addresses for IPv6 passive sockets
-fails:Socket#getaddrinfo accepts empty addresses for IPv6 non-passive sockets
@@ -1 +1 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
+fails(minor text mismatch):Socket#gethostbyname returns broadcast address info for '<broadcast>'
@@ -1 +0,0 @@
-fails(JRUBY-4819):Socket::TCPServer.accept_nonblock accepts non blocking connections
@@ -1 +0,0 @@
-fails:TCPSocket#recv_nonblock returns a String read from the socket
@@ -1,2 +0,0 @@
-fails(JRUBY-2758):UDPSocket.send sends data in ad hoc mode
-fails(JRUBY-2758):UDPSocket.send sends data in connection mode
@@ -1,2 +0,0 @@
-critical(JRUBY-4291):UNIXServer#accept can be interrupted by Thread#kill
-critical(JRUBY-4291):UNIXServer#accept can be interrupted by Thread#raise
@@ -1,2 +1 @@
fails:BasicSocket#send accepts flags to specify unusual sending behaviour
-fails:BasicSocket#send accepts a sockaddr as recipient address
@@ -1 +1 @@
-fails:Socket#gethostbyname returns broadcast address info for '<broadcast>'
+fails(minor text mismatch):Socket#gethostbyname returns broadcast address info for '<broadcast>'
@@ -1 +0,0 @@
-fails:Socket::TCPServer.accept_nonblock accepts non blocking connections
@@ -1 +0,0 @@
-fails:TCPServer#gets raises Errno::ENOTCONN on gets
@@ -1 +0,0 @@
-fails:TCPSocket#recv_nonblock returns a String read from the socket
@@ -1,3 +0,0 @@
-fails:UDPSocket.send sends data in ad hoc mode
-fails:UDPSocket.send sends data in ad hoc mode (with port given as a String)
-fails:UDPSocket.send sends data in connection mode
@@ -1,2 +0,0 @@
-critical(JRUBY-4291):UNIXServer#accept can be interrupted by Thread#kill
-critical(JRUBY-4291):UNIXServer#accept can be interrupted by Thread#raise
@@ -1091,7 +1091,7 @@ private static Encoding getEncodingCommon(ThreadContext context, IRubyObject enc
return context.getRuntime().getEncodingService().getEncodingFromObject(encoding);
}
- @JRubyMethod(required = 1, optional = 2, meta = true)
+ @JRubyMethod(required = 1, rest = true, meta = true)
public static IRubyObject open(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
Ruby runtime = context.getRuntime();
RubyClass klass = (RubyClass)recv;
@@ -252,17 +252,22 @@ public IRubyObject setsockopt(ThreadContext context, IRubyObject _level, IRubyOb
case SOL_TCP:
case SOL_UDP:
- int number = asNumber(val);
if (opt == SocketOption.SO_LINGER) {
- // massage args into something appropriate
if(val instanceof RubyBoolean && !val.isTrue()) {
- number = -1;
+ socketType.setSoLinger(channel, false, 0);
} else {
- number = asNumber(val);
+ int num = asNumber(val);
+ if(num == -1) {
+ socketType.setSoLinger(channel, false, 0);
+ } else {
+ socketType.setSoLinger(channel, true, num);
+ }
}
+
+ } else {
+ socketType.setSocketOption(channel, opt, asNumber(val));
}
- socketType.setSocketOption(channel, opt, asNumber(val));
break;
default:
@@ -99,7 +99,7 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
host = _host.convertToString().toString();
}
- int port = SocketUtils.getPortFrom(runtime, _port);
+ int port = SocketUtils.getPortFrom(context, _port);
try {
InetAddress addr = InetAddress.getByName(host);
@@ -246,6 +246,26 @@ public IRubyObject gets(ThreadContext context) {
throw context.getRuntime().newErrnoENOTCONNError();
}
+ @Override
+ public IRubyObject gets(ThreadContext context, IRubyObject sep) {
+ throw context.getRuntime().newErrnoENOTCONNError();
+ }
+
+ @Override
+ public IRubyObject gets19(ThreadContext context) {
+ throw context.getRuntime().newErrnoENOTCONNError();
+ }
+
+ @Override
+ public IRubyObject gets19(ThreadContext context, IRubyObject sep) {
+ throw context.getRuntime().newErrnoENOTCONNError();
+ }
+
+ @Override
+ public IRubyObject gets19(ThreadContext context, IRubyObject sep, IRubyObject limit) {
+ throw context.getRuntime().newErrnoENOTCONNError();
+ }
+
@Deprecated
public IRubyObject accept() {
return accept(getRuntime().getCurrentContext());
@@ -84,10 +84,10 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args) {
IRubyObject _port = args[1];
String remoteHost = _host.isNil()? "localhost" : _host.convertToString().toString();
- int remotePort = SocketUtils.getPortFrom(runtime, _port);
+ int remotePort = SocketUtils.getPortFrom(context, _port);
String localHost = (args.length >= 3 && !args[2].isNil()) ? args[2].convertToString().toString() : null;
- int localPort = (args.length == 4 && !args[3].isNil()) ? SocketUtils.getPortFrom(runtime, args[3]) : 0;
+ int localPort = (args.length == 4 && !args[3].isNil()) ? SocketUtils.getPortFrom(context, args[3]) : 0;
try {
// This is a bit convoluted because (1) SocketChannel.bind is only in jdk 7 and
@@ -42,6 +42,7 @@
import java.io.IOException;
import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
@JRubyClass(name="UNIXServer", parent="UNIXSocket")
public class RubyUNIXServer extends RubyUNIXSocket {
@@ -72,18 +73,30 @@ public IRubyObject initialize(ThreadContext context, IRubyObject path) {
@JRubyMethod
public IRubyObject accept(ThreadContext context) {
+ Ruby runtime = context.getRuntime();
+
try {
- UnixSocketChannel socketChannel = asUnixServer().accept();
- Ruby runtime = context.getRuntime();
- RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
+ while (true) { // select loop to allow interrupting
+ boolean ready = context.getThread().select(this, SelectionKey.OP_ACCEPT);
+
+ if (!ready) {
+ // we were woken up without being selected...poll for thread events and go back to sleep
+ context.pollThreadEvents();
+
+ } else {
+ UnixSocketChannel socketChannel = asUnixServer().accept();
- sock.channel = socketChannel;
- sock.fpath = "";
+ RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
- sock.init_sock(context.getRuntime());
+ sock.channel = socketChannel;
+ sock.fpath = "";
- return sock;
+ sock.init_sock(context.getRuntime());
+
+ return sock;
+ }
+ }
} catch (IOException ioe) {
throw context.runtime.newIOErrorFromException(ioe);
@@ -181,10 +181,12 @@ public static IRubyObject socketpair(ThreadContext context, IRubyObject recv, IR
RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
sock.channel = sp[0];
+ sock.fpath = "";
sock.init_sock(runtime);
RubyUNIXSocket sock2 = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
sock2.channel = sp[1];
+ sock2.fpath = "";
sock2.init_sock(runtime);
return runtime.newArray(sock, sock2);
@@ -232,11 +232,11 @@ private UnixSocketChannel toSocket(Channel channel) {
}
public void shutdownInput(Channel channel)throws IOException {
-// toSocket(channel).shutdownInput();
+ toSocket(channel).shutdownInput();
}
- public void shutdownOutput(Channel channel)throws IOException {
-// toSocket(channel).shutdownInput();
+ public void shutdownOutput(Channel channel) throws IOException {
+ toSocket(channel).shutdownOutput();
}
},
@@ -252,8 +252,7 @@ public static SocketType forChannel(Channel channel) {
} else if (channel instanceof DatagramChannel) {
return DATAGRAM;
- } else if (channel instanceof UnixServerSocketChannel
- || channel instanceof UnixSocketChannel) {
+ } else if (channel instanceof UnixSocketChannel) {
return UNIX;
}
@@ -359,28 +358,36 @@ public void setSocketOption(Channel channel, SocketOption option, int value) thr
case SO_BROADCAST:
setBroadcast(channel, asBoolean(value));
+ break;
case SO_KEEPALIVE:
setKeepAlive(channel, asBoolean(value));
+ break;
case SO_LINGER:
setSoLinger(channel, value <= 0, value);
+ break;
case SO_OOBINLINE:
setOOBInline(channel, asBoolean(value));
+ break;
case SO_RCVBUF:
setReceiveBufferSize(channel, value);
+ break;
case SO_REUSEADDR:
setReuseAddress(channel, asBoolean(value));
+ break;
case SO_SNDBUF:
setSendBufferSize(channel, value);
+ break;
case SO_RCVTIMEO:
case SO_SNDTIMEO:
setSoTimeout(channel, value);
+ break;
// can't set these
case SO_TYPE:
@@ -32,6 +32,7 @@
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyFixnum;
+import org.jruby.RubyInteger;
import org.jruby.RubyNumeric;
import org.jruby.RubyString;
import org.jruby.anno.JRubyMethod;
@@ -388,10 +389,13 @@ public static IRubyObject ip_address_list(ThreadContext context) {
}
public static InetAddress getRubyInetAddress(ByteList address) throws UnknownHostException {
- if (address.equal(BROADCAST)) {
+ // switched to String because the ByteLists were not comparing properly in 1.9 mode (encoding?
+ String addressString = address.toString();
+
+ if (addressString.equals(BROADCAST)) {
return InetAddress.getByAddress(INADDR_BROADCAST);
- } else if (address.equal(ANY)) {
+ } else if (addressString.equals(ANY)) {
return InetAddress.getByAddress(INADDR_ANY);
} else {
@@ -412,15 +416,22 @@ public static RuntimeException sockerr(Ruby runtime, String msg) {
return new RaiseException(runtime, runtime.getClass("SocketError"), msg, true);
}
- public static int getPortFrom(Ruby runtime, IRubyObject arg) {
- if (arg instanceof RubyString) {
- Service service = Service.getServiceByName(arg.asJavaString(), "tcp");
- return service != null ?
- service.getPort() :
- RubyNumeric.fix2int(RubyNumeric.str2inum(runtime, (RubyString) arg, 0, true));
+ public static int getPortFrom(ThreadContext context, IRubyObject _port) {
+ int port;
+ if (_port instanceof RubyInteger) {
+ port = RubyNumeric.fix2int(_port);
+ } else {
+ IRubyObject portString = _port.convertToString();
+ IRubyObject portInteger = portString.convertToInteger( "to_i");
+ port = RubyNumeric.fix2int(portInteger);
+
+ if (port <= 0) {
+ port = RubyNumeric.fix2int(RubySocket.getservbyname(
+ context, context.runtime.getObject(), new IRubyObject[] {portString}));
+ }
}
- return RubyNumeric.fix2int(arg);
+ return port;
}
private static String getHostAddress(ThreadContext context, InetAddress addr) {
@@ -433,8 +444,8 @@ private static String getHostAddress(ThreadContext context, InetAddress addr) {
private static final int IPV4_HOST_GROUP = 3;
private static final int IPV4_PORT_GROUP = 5;
- private static final ByteList BROADCAST = new ByteList("<broadcast>".getBytes());
+ private static final String BROADCAST = "<broadcast>";
private static final byte[] INADDR_BROADCAST = new byte[] {-1,-1,-1,-1}; // 255.255.255.255
- private static final ByteList ANY = new ByteList("<any>".getBytes());
+ private static final String ANY = "<any>";
private static final byte[] INADDR_ANY = new byte[] {0,0,0,0}; // 0.0.0.0
}

0 comments on commit cd18b42

Please sign in to comment.