commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1099854 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/shared/ test/org/apache/commons/runtime/
Date Thu, 05 May 2011 15:52:19 GMT
Author: mturk
Date: Thu May  5 15:52:18 2011
New Revision: 1099854

URL: http://svn.apache.org/viewvc?rev=1099854&view=rev
Log:
Move Java sockets operations to a single class

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sockets.java
      - copied, changed from r1099828, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/DatagramSocketInstance.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LingerOption.java
    commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
    commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LingerOption.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LingerOption.java?rev=1099854&r1=1099853&r2=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LingerOption.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LingerOption.java
Thu May  5 15:52:18 2011
@@ -21,7 +21,7 @@ package org.apache.commons.runtime.net;
 import java.net.SocketAddress;
 
 /**
- * This class represents a network address.
+ * Specifies whether a socket will remain connected after closed.
  */
 public final class LingerOption
 {

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sockets.java
(from r1099828, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sockets.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sockets.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java&r1=1099828&r2=1099854&rev=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketInstance.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/Sockets.java
Thu May  5 15:52:18 2011
@@ -20,15 +20,19 @@ package org.apache.commons.runtime.net;
 
 import java.io.FileDescriptor;
 import java.io.IOException;
+import java.net.DatagramSocket;
 import java.net.Socket;
 import java.net.SocketImpl;
 import java.net.ServerSocket;
 import java.net.SocketException;
 import org.apache.commons.runtime.Status;
 
-public final class SocketInstance
+/**
+ * Modifes Java Sockets
+ */
+public final class Sockets
 {
-    private SocketInstance()
+    private Sockets()
     {
         // No istance
     }
@@ -39,14 +43,20 @@ public final class SocketInstance
     }
 
     private static native FileDescriptor fd0(Socket s);
-    private static native FileDescriptor fd1(ServerSocket s);
     private static native int            nd0(Socket s);
-    private static native int            nd1(ServerSocket s);
     private static native int            sd0(Socket s, int d);
-    private static native int            sd1(ServerSocket s, int d);
     private static native int            nb0(Socket s, boolean on);
+
+    private static native FileDescriptor fd1(ServerSocket s);
+    private static native int            nd1(ServerSocket s);
+    private static native int            sd1(ServerSocket s, int d);
     private static native int            nb1(ServerSocket s, boolean on);
 
+    private static native FileDescriptor fd3(DatagramSocket s);
+    private static native int            nd3(DatagramSocket s);
+    private static native int            sd3(DatagramSocket s, int d);
+    private static native int            nb3(DatagramSocket s, boolean on);
+
     public static FileDescriptor getFileDescriptor(Socket s)
         throws IllegalArgumentException
     {
@@ -63,6 +73,14 @@ public final class SocketInstance
         return fd1(s);
     }
 
+    public static FileDescriptor getFileDescriptor(DatagramSocket s)
+        throws IllegalArgumentException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        return fd3(s);
+    }
+
     public static int getNativeDescriptor(Socket s)
         throws IllegalArgumentException
     {
@@ -79,6 +97,14 @@ public final class SocketInstance
         return nd1(s);
     }
 
+    public static int getNativeDescriptor(DatagramSocket s)
+        throws IllegalArgumentException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        return nd3(s);
+    }
+
     public static void setNativeDescriptor(Socket s, int desc)
         throws IllegalArgumentException, IOException
     {
@@ -99,6 +125,16 @@ public final class SocketInstance
             throw new IOException(Status.describe(rc));
     }
 
+    public static void setNativeDescriptor(DatagramSocket s, int desc)
+        throws IllegalArgumentException, IOException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        int rc = sd3(s, desc);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
     public static void configureBlocking(Socket s, boolean on)
         throws IllegalArgumentException, IOException
     {
@@ -119,4 +155,14 @@ public final class SocketInstance
             throw new IOException(Status.describe(rc));
     }
 
+    public static void configureBlocking(DatagramSocket s, boolean on)
+        throws IllegalArgumentException, IOException
+    {
+        if (s == null)
+            throw new IllegalArgumentException();
+        int rc = nb3(s, !on);
+        if (rc != 0)
+            throw new IOException(Status.describe(rc));
+    }
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c?rev=1099854&r1=1099853&r2=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/dsock.c Thu May  5 15:52:18 2011
@@ -56,14 +56,7 @@ ACR_CLASS_DTOR(DatagramSocket)
     AcrUnloadClass(env, &_clazzn);
 }
 
-ACR_NET_EXPORT(jboolean, DatagramSocketInstance, init0)(JNI_STDARGS)
-{
-    ACR_CLASS_LOAD(DatagramSocket);
-    ACR_CLASS_LOAD(DatagramSocketImpl);
-    return JNI_TRUE;
-}
-
-ACR_NET_EXPORT(jobject, DatagramSocketInstance, fd0)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jobject, Sockets, fd3)(JNI_STDARGS, jobject sock)
 {
     jobject impl = 0;
 
@@ -103,12 +96,12 @@ AcrGetDatagramSocketFd(JNI_STDARGS)
     return -1;
 }
 
-ACR_NET_EXPORT(jint, DatagramSocketInstance, nd0)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jint, Sockets, nd3)(JNI_STDARGS, jobject sock)
 {
     return AcrGetDatagramSocketFd(env, sock);
 }
 
-ACR_NET_EXPORT(jint, DatagramSocketInstance, sd0)(JNI_STDARGS, jobject sock, jint sd)
+ACR_NET_EXPORT(jint, Sockets, sd3)(JNI_STDARGS, jobject sock, jint sd)
 {
     jobject impl = 0;
     jobject fd;
@@ -129,7 +122,7 @@ ACR_NET_EXPORT(jint, DatagramSocketInsta
     return ACR_EBADF;
 }
 
-ACR_NET_EXPORT(jint, DatagramSocketInstance, nb0)(JNI_STDARGS, jobject sock, jboolean on)
+ACR_NET_EXPORT(jint, Sockets, nb3)(JNI_STDARGS, jobject sock, jboolean on)
 {
     jobject impl = 0;
     jobject fd;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/psock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/psock.c?rev=1099854&r1=1099853&r2=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/psock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/psock.c Thu May  5 15:52:18 2011
@@ -57,15 +57,17 @@ ACR_CLASS_DTOR(Socket)
     AcrUnloadClass(env, &_clazzn);
 }
 
-ACR_NET_EXPORT(jboolean, SocketInstance, init0)(JNI_STDARGS)
+ACR_NET_EXPORT(jboolean, Sockets, init0)(JNI_STDARGS)
 {
     ACR_CLASS_LOAD(Socket);
     ACR_CLASS_LOAD(SocketImpl);
     ACR_CLASS_LOAD(ServerSocket);
+    ACR_CLASS_LOAD(DatagramSocket);
+    ACR_CLASS_LOAD(DatagramSocketImpl);    
     return JNI_TRUE;
 }
 
-ACR_NET_EXPORT(jobject, SocketInstance, fd0)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jobject, Sockets, fd0)(JNI_STDARGS, jobject sock)
 {
     jobject impl = 0;
 
@@ -105,12 +107,12 @@ AcrGetSocketFd(JNI_STDARGS)
     return -1;
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, nd0)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jint, Sockets, nd0)(JNI_STDARGS, jobject sock)
 {
     return AcrGetSocketFd(env, sock);
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, sd0)(JNI_STDARGS, jobject sock, jint sd)
+ACR_NET_EXPORT(jint, Sockets, sd0)(JNI_STDARGS, jobject sock, jint sd)
 {
     jobject impl = 0;
     jobject fd;
@@ -131,7 +133,7 @@ ACR_NET_EXPORT(jint, SocketInstance, sd0
     return ACR_EBADF;
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, nb0)(JNI_STDARGS, jobject sock, jboolean on)
+ACR_NET_EXPORT(jint, Sockets, nb0)(JNI_STDARGS, jobject sock, jboolean on)
 {
     jobject impl = 0;
     jobject fd;

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c?rev=1099854&r1=1099853&r2=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/ssock.c Thu May  5 15:52:18 2011
@@ -56,7 +56,7 @@ ACR_CLASS_DTOR(ServerSocket)
     AcrUnloadClass(env, &_clazzn);
 }
 
-ACR_NET_EXPORT(jobject, SocketInstance, fd1)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jobject, Sockets, fd1)(JNI_STDARGS, jobject sock)
 {
     jobject impl = 0;
 
@@ -96,12 +96,12 @@ AcrGetServerSocketFd(JNI_STDARGS)
     return -1;
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, nd1)(JNI_STDARGS, jobject sock)
+ACR_NET_EXPORT(jint, Sockets, nd1)(JNI_STDARGS, jobject sock)
 {
     return AcrGetServerSocketFd(env, sock);
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, sd1)(JNI_STDARGS, jobject sock, jint sd)
+ACR_NET_EXPORT(jint, Sockets, sd1)(JNI_STDARGS, jobject sock, jint sd)
 {
     jobject impl = 0;
     jobject fd;
@@ -122,7 +122,7 @@ ACR_NET_EXPORT(jint, SocketInstance, sd1
     return ACR_EBADF;
 }
 
-ACR_NET_EXPORT(jint, SocketInstance, nb1)(JNI_STDARGS, jobject sock, jboolean on)
+ACR_NET_EXPORT(jint, Sockets, nb1)(JNI_STDARGS, jobject sock, jboolean on)
 {
     jobject impl = 0;
     jobject fd;

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java?rev=1099854&r1=1099853&r2=1099854&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestNetworkImpl.java
Thu May  5 15:52:18 2011
@@ -42,8 +42,8 @@ public class TestNetworkImpl extends Ass
         // Create socket bound to the first free port
         //
         ServerSocket ss = new ServerSocket(0);
-        assertNotNull(SocketInstance.getFileDescriptor(ss));
-        assertFalse(SocketInstance.getNativeDescriptor(ss) == -1);
+        assertNotNull(Sockets.getFileDescriptor(ss));
+        assertFalse(Sockets.getNativeDescriptor(ss) == -1);
     }
 
     @Test(groups = { "core" })
@@ -54,11 +54,11 @@ public class TestNetworkImpl extends Ass
         // FileDescriptor is null until bind call
         //
         ServerSocket ss = new ServerSocket();
-        assertNull(SocketInstance.getFileDescriptor(ss));
-        assertTrue(SocketInstance.getNativeDescriptor(ss) == -1);
+        assertNull(Sockets.getFileDescriptor(ss));
+        assertTrue(Sockets.getNativeDescriptor(ss) == -1);
         ss.bind(null);
-        assertNotNull(SocketInstance.getFileDescriptor(ss));
-        assertFalse(SocketInstance.getNativeDescriptor(ss) == -1);
+        assertNotNull(Sockets.getFileDescriptor(ss));
+        assertFalse(Sockets.getNativeDescriptor(ss) == -1);
     }
 
     @Test(groups = { "core" })
@@ -69,7 +69,7 @@ public class TestNetworkImpl extends Ass
         // FileDescriptor is null until bind call
         //
         Socket s = new Socket();
-        assertNull(SocketInstance.getFileDescriptor(s));
+        assertNull(Sockets.getFileDescriptor(s));
     }
 
     class Worker extends Thread
@@ -83,7 +83,7 @@ public class TestNetworkImpl extends Ass
         public void run() {
             try {
                 Socket s = ss.accept();
-                assertNotNull(SocketInstance.getFileDescriptor(s));
+                assertNotNull(Sockets.getFileDescriptor(s));
             } catch (Exception x) {
                 fail("Accept failed " + x.toString());
             }
@@ -108,15 +108,15 @@ public class TestNetworkImpl extends Ass
         //
         Socket s = new Socket("127.0.0.1", ss.getLocalPort());
         // Check various FileDescriptor instances for the Socket
-        FileDescriptor fd = SocketInstance.getFileDescriptor(s);
+        FileDescriptor fd = Sockets.getFileDescriptor(s);
         assertNotNull(fd);
         FileOutputStream fs = (FileOutputStream)s.getOutputStream();
         FileInputStream  fi = (FileInputStream)s.getInputStream();
         assertEquals(fd, fs.getFD());
         assertEquals(fd, fi.getFD());
         assertEquals(fs.getFD(), fi.getFD());
-        SocketInstance.configureBlocking(s, false);
-        SocketInstance.configureBlocking(s, true);
+        Sockets.configureBlocking(s, false);
+        Sockets.configureBlocking(s, true);
         s.close();
     }
 
@@ -138,15 +138,15 @@ public class TestNetworkImpl extends Ass
         //
         Socket s = new Socket("::1", ss.getLocalPort());
         // Check various FileDescriptor instances for the Socket
-        FileDescriptor fd = SocketInstance.getFileDescriptor(s);
+        FileDescriptor fd = Sockets.getFileDescriptor(s);
         assertNotNull(fd);
         FileOutputStream fs = (FileOutputStream)s.getOutputStream();
         FileInputStream  fi = (FileInputStream)s.getInputStream();
         assertEquals(fd, fs.getFD());
         assertEquals(fd, fi.getFD());
         assertEquals(fs.getFD(), fi.getFD());
-        SocketInstance.configureBlocking(s, false);
-        SocketInstance.configureBlocking(s, true);
+        Sockets.configureBlocking(s, false);
+        Sockets.configureBlocking(s, true);
         s.close();
     }
 
@@ -157,7 +157,7 @@ public class TestNetworkImpl extends Ass
         // Create datagram socket bound to the first free port
         //
         DatagramSocket s = new DatagramSocket();
-        assertNotNull(DatagramSocketInstance.getFileDescriptor(s));
+        assertNotNull(Sockets.getFileDescriptor(s));
     }
 
 }



Mime
View raw message