You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/06/08 07:35:51 UTC

svn commit: r1133252 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/os/unix/ test/org/apache/commons/runtime/

Author: mturk
Date: Wed Jun  8 05:35:50 2011
New Revision: 1133252

URL: http://svn.apache.org/viewvc?rev=1133252&view=rev
Log:
Presume that by default the sockets are blocking

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java Wed Jun  8 05:35:50 2011
@@ -42,10 +42,10 @@ public class LocalEndpoint extends Endpo
     private final LocalDescriptor       sd;
     private EndpointAddress             ea;
     private SelectionKeyImpl            key;
-    private boolean                     blocking  = false;
+    private boolean                     blocking  = true;
     private boolean                     connected = false;
 
-    private static native int           nonblock0(int fd, boolean block);
+    private static native int           block0(int fd, boolean block);
     private static native int           connect0(int fd, byte[] sa, int timeout);
 
     /**
@@ -118,7 +118,7 @@ public class LocalEndpoint extends Endpo
             throw new IllegalBlockingModeException();
         if (blocking == block)
             return sd;
-        int rc = nonblock0(sd.fd(), block);
+        int rc = block0(sd.fd(), block);
         if (rc != 0)
             throw new IOException(Status.describe(rc));
         blocking = block;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java Wed Jun  8 05:35:50 2011
@@ -41,10 +41,10 @@ public class LocalServerEndpoint extends
     private final LocalDescriptor       sd;
     private SelectionKeyImpl            key;
     private EndpointAddress             sa;
-    private boolean                     blocking = false;
+    private boolean                     blocking = true;
     private boolean                     bound    = false;
 
-    private static native int           nonblock0(int fd, boolean block);
+    private static native int           block0(int fd, boolean block);
     private static native void          unlink0(byte[] addr);
 
     /**
@@ -93,7 +93,7 @@ public class LocalServerEndpoint extends
             throw new IllegalBlockingModeException();
         if (blocking == block)
             return sd;
-        int rc = nonblock0(sd.fd(), block);
+        int rc = block0(sd.fd(), block);
         if (rc != 0)
             throw new SocketException(Status.describe(rc));
         blocking = block;

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java Wed Jun  8 05:35:50 2011
@@ -36,10 +36,10 @@ public class SocketEndpoint extends Endp
     private final SocketDescriptor      sd;
     private EndpointAddress             ea;
     private SelectionKeyImpl            key;
-    private boolean                     blocking  = false;
+    private boolean                     blocking  = true;
     private boolean                     connected = false;
 
-    private static native int           nonblock0(int fd, boolean block);
+    private static native int           block0(int fd, boolean block);
     
     /**
      * Creates a new unconnected socket endpoint.
@@ -95,7 +95,7 @@ public class SocketEndpoint extends Endp
             throw new IllegalBlockingModeException();
         if (blocking == block)
             return sd;
-        int rc = nonblock0(sd.fd(), block);
+        int rc = block0(sd.fd(), block);
         if (rc != 0)
             throw new SocketException(Status.describe(rc));
         blocking = block;

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Wed Jun  8 05:35:50 2011
@@ -54,7 +54,7 @@ ACR_NET_EXPORT(jboolean, SocketAddress, 
         return JNI_FALSE;
 }
 
-ACR_NET_EXPORT(jint, SocketEndpoint, nonblock0)(JNI_STDARGS, jint fd, jboolean on)
+ACR_NET_EXPORT(jint, SocketEndpoint, block0)(JNI_STDARGS, jint fd, jboolean on)
 {
-    return AcrNonblock(fd, on);
+    return AcrNonblock(fd,  on == JNI_FALSE);
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/usock.c Wed Jun  8 05:35:50 2011
@@ -90,9 +90,9 @@ ACR_NET_EXPORT(jint, LocalDescriptor, so
     return sd;
 }
 
-ACR_NET_EXPORT(jint, LocalEndpoint, nonblock0)(JNI_STDARGS, jint fd, jboolean on)
+ACR_NET_EXPORT(jint, LocalEndpoint, block0)(JNI_STDARGS, jint fd, jboolean on)
 {
-    return AcrNonblock(fd, on);
+    return AcrNonblock(fd, on == JNI_FALSE);
 }
 
 ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jint fd,
@@ -127,6 +127,12 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
     return rc;
 }
 
+ACR_NET_EXPORT(jint, LocalServerEndpoint, block0)(JNI_STDARGS, jint fd,
+                                                  jboolean on)
+{
+    return AcrNonblock(fd,  on == JNI_FALSE);
+}
+
 ACR_NET_EXPORT(jint, LocalServerEndpoint, bind0)(JNI_STDARGS, jint fd,
                                                  jbyteArray ba,
                                                  jint backlog)

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java?rev=1133252&r1=1133251&r2=1133252&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java (original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java Wed Jun  8 05:35:50 2011
@@ -39,42 +39,63 @@ public class TestPosixEndpoint extends A
 
     class Acceptor extends Thread
     {
+        Selector            ps;
         LocalServerEndpoint ss;
         public volatile boolean running = true;
 
-        public Acceptor(LocalServerEndpoint ss)
+        public Acceptor(LocalServerEndpoint ss, Selector ps)
         {
             this.ss = ss;
+            this.ps = ps;
         }
 
-        public void run() {
-            synchronized(sync) {
+        public void run()
+        {
+            SelectionKey sk;
+            try {
+                 sk = ss.register(ps, SelectionKey.OP_ACCEPT);
+                 assertEquals(ps.size(), 1);
+            } catch (Exception x) {
+                fail("Acceptor setup failed " + x.toString());
+            }
+            synchronized (sync) {
                 // Notify that we are ready to
                 // accept the connections
                 sync.notifyAll();
             }
-            while (running) {
+            while (true) {
                 try {
+                    System.out.println("Accepting connection ...");
                     LocalEndpoint e = ss.accept();
                     assertNotNull(e.descriptor());
                 } catch (Exception x) {
                     fail("Accept failed " + x.toString());
                 }
+                if (!running)
+                    break;
+            }
+            try {
+                ss.close();
+            } catch (Exception x) {
+                fail("Acceptor shutdown failed " + x.toString());
             }
         }
     }
 
     @Test(groups = { "posix" })
     public void connectLocalEndpoint()
-        throws IOException
+        throws Exception
     {
+        Selector             ps = Selector.open(EndpointType.LOCAL);
         LocalServerEndpoint  ss = new LocalServerEndpoint();
         LocalEndpointAddress sa = new LocalEndpointAddress("/tmp/acrposixep1.sock");
         ss.bind(sa);
-        Acceptor w = new Acceptor(ss);
-        w.start();
+        // ss.configureBlocking(false);
+        Acceptor aw = new Acceptor(ss, ps);
+        aw.setName("TestAcceptorThread");
+        aw.start();
         try {
-            synchronized(sync) {
+            synchronized (sync) {
                 // Wait until Acceptor is ready to accept connections
                 //
                 sync.wait();
@@ -82,15 +103,17 @@ public class TestPosixEndpoint extends A
         } catch (InterruptedException x) {
             // Ignore
         }
-        w.running = false;
+        aw.running = false;
         // Create unbound socket
         // FileDescriptor is null until bind call
         //
-        LocalEndpoint s = new LocalEndpoint();
-        s.connect(sa);
-        assertFalse(s.isBlocking());
-        s.close();
-        ss.close();
+        LocalEndpoint cs = new LocalEndpoint();
+        cs.connect(sa);
+        assertTrue(cs.isBlocking());
+        cs.close();
+        ps.close();
+        // Wait for acceptor thread to finish
+        aw.join();
     }
 
 }