Permalink
Browse files

Move to using jnr-unixsocket for UNIXSocket and UNIXServer.

  • Loading branch information...
1 parent f3d82d8 commit 71f1b3e2194c7bc60ee2ed057b653f410f5de6e6 @headius headius committed Mar 12, 2012
View
@@ -346,6 +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}/jffi.jar"/>
<zipfileset src="${build.lib.dir}/jffi-i386-Linux.jar"/>
<zipfileset src="${build.lib.dir}/jffi-x86_64-Linux.jar"/>
Binary file not shown.
Binary file not shown.
View
@@ -496,6 +496,19 @@
<SOURCES />
</library>
</orderEntry>
+ <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!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES>
+ <root url="file://$MODULE_DIR$/build_lib" />
+ </SOURCES>
+ <jarDirectory url="file://$MODULE_DIR$/build_lib" recursive="false" type="SOURCES" />
+ </library>
+ </orderEntry>
</component>
</module>
@@ -29,6 +29,8 @@
import jnr.ffi.byref.IntByReference;
+import jnr.unixsocket.UnixServerSocketChannel;
+import jnr.unixsocket.UnixSocketChannel;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyNumeric;
@@ -40,6 +42,8 @@
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
+import java.io.IOException;
+
/**
*
* @author <a href="mailto:ola.bini@gmail.com">Ola Bini</a>
@@ -75,48 +79,54 @@ public IRubyObject accept() {
}
@JRubyMethod
public IRubyObject accept(ThreadContext context) {
- LibCSocket.sockaddr_un from = LibCSocket.sockaddr_un.newInstance();
- int fd2 = INSTANCE.accept(fd, from, new IntByReference(LibCSocket.sockaddr_un.LENGTH));
- if(fd2 < 0) {
- rb_sys_fail(context.getRuntime(), null);
- }
+ try {
+ UnixSocketChannel socketChannel = ((UnixServerSocketChannel) channel).accept();
+// LibCSocket.sockaddr_un from = LibCSocket.sockaddr_un.newInstance();
+// int fd2 = INSTANCE.accept(fd, from, new IntByReference(LibCSocket.sockaddr_un.LENGTH));
+// if(fd2 < 0) {
+// rb_sys_fail(context.getRuntime(), null);
+// }
- Ruby runtime = context.getRuntime();
- RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
-
- sock.fd = fd2;
- sock.fpath = from.path().toString();
+ Ruby runtime = context.getRuntime();
+ RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
+
+ sock.channel = socketChannel;
+ sock.fpath = fpath;
- sock.init_sock(context.getRuntime());
+ sock.init_sock(context.getRuntime());
- return sock;
+ return sock;
+ } catch (IOException ioe) {
+ throw context.runtime.newIOErrorFromException(ioe);
+ }
}
@Deprecated
public IRubyObject accept_nonblock() {
return accept_nonblock(getRuntime().getCurrentContext());
}
@JRubyMethod
public IRubyObject accept_nonblock(ThreadContext context) {
- LibCSocket.sockaddr_un from = LibCSocket.sockaddr_un.newInstance();
- IntByReference fromlen = new IntByReference(LibCSocket.sockaddr_un.LENGTH);
-
- int flags = INSTANCE.fcntl(fd, RubyUNIXSocket.F_GETFL ,0);
- INSTANCE.fcntl(fd, RubyUNIXSocket.F_SETFL, flags | RubyUNIXSocket.O_NONBLOCK);
-
- int fd2 = INSTANCE.accept(fd, from, new IntByReference(LibCSocket.sockaddr_un.LENGTH));
- if(fd2 < 0) {
- rb_sys_fail(context.getRuntime(), null);
- }
-
- Ruby runtime = context.getRuntime();
- RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
-
- sock.fd = fd2;
- sock.fpath = from.path().toString();
-
- sock.init_sock(context.getRuntime());
-
- return sock;
+ return accept(context);
+// LibCSocket.sockaddr_un from = LibCSocket.sockaddr_un.newInstance();
+// IntByReference fromlen = new IntByReference(LibCSocket.sockaddr_un.LENGTH);
+//
+// int flags = INSTANCE.fcntl(fd, RubyUNIXSocket.F_GETFL ,0);
+// INSTANCE.fcntl(fd, RubyUNIXSocket.F_SETFL, flags | RubyUNIXSocket.O_NONBLOCK);
+//
+// int fd2 = INSTANCE.accept(fd, from, new IntByReference(LibCSocket.sockaddr_un.LENGTH));
+// if(fd2 < 0) {
+// rb_sys_fail(context.getRuntime(), null);
+// }
+//
+// Ruby runtime = context.getRuntime();
+// RubyUNIXSocket sock = (RubyUNIXSocket)(RuntimeHelpers.invoke(context, runtime.getClass("UNIXSocket"), "allocate"));
+//
+// sock.fd = fd2;
+// sock.fpath = from.path().toString();
+//
+// sock.init_sock(context.getRuntime());
+//
+// return sock;
}
@Deprecated
public IRubyObject sysaccept() {
@@ -132,9 +142,10 @@ public IRubyObject listen(IRubyObject log) {
}
@JRubyMethod
public IRubyObject listen(ThreadContext context, IRubyObject log) {
- if(INSTANCE.listen(fd, RubyNumeric.fix2int(log)) < 0) {
- rb_sys_fail(context.getRuntime(), "listen(2)");
- }
+// ((UnixServerSocketChannel)channel)
+// if(INSTANCE.listen(fd, RubyNumeric.fix2int(log)) < 0) {
+// rb_sys_fail(context.getRuntime(), "listen(2)");
+// }
return context.getRuntime().newFixnum(0);
}
}// RubyUNIXServer
Oops, something went wrong.

0 comments on commit 71f1b3e

Please sign in to comment.