commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1100178 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/shared/ test/org/apache/commons/runtime/
Date Fri, 06 May 2011 11:44:52 GMT
Author: mturk
Date: Fri May  6 11:44:51 2011
New Revision: 1100178

URL: http://svn.apache.org/viewvc?rev=1100178&view=rev
Log:
Use proper name for local endpoint address

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
      - copied, changed from r1100174, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
Modified:
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
    commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java

Copied: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
(from r1100174, commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java)
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java?p2=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java&p1=commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java&r1=1100174&r2=1100178&rev=1100178&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalSocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpointAddress.java
Fri May  6 11:44:51 2011
@@ -25,16 +25,18 @@ import org.apache.commons.runtime.Status
 import org.apache.commons.runtime.InvalidArgumentException;
 
 /**
- * This class represents a local socket endpoint described by a name.
+ * This class represents a local Endpoint address described by a name.
  * <p>
+ * Local endpoint depends on the Operating System and is either
+ * Unix domain socket or a Windows pipe.
  * </p>
  */
-public final class LocalSocketAddress extends EndpointAddress
+public final class LocalEndpointAddress extends EndpointAddress
 {
 
     private native int sockaddr0(String name);
     
-    private LocalSocketAddress()
+    private LocalEndpointAddress()
     {
         // No instance
     }
@@ -42,7 +44,7 @@ public final class LocalSocketAddress ex
     /**
      * Create a new local socket adrress.
      */
-    public LocalSocketAddress(String name)
+    public LocalEndpointAddress(String name)
         throws NetworkException, InvalidArgumentException
     {
         super(AddressFamily.LOCAL);
@@ -60,7 +62,7 @@ public final class LocalSocketAddress ex
     /**
      * Create a new local socket adrress.
      */
-    public LocalSocketAddress(File path)
+    public LocalEndpointAddress(File path)
         throws NetworkException, InvalidArgumentException
     {
         super(AddressFamily.LOCAL);

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1100178&r1=1100177&r2=1100178&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Fri May  6 11:44:51 2011
@@ -777,6 +777,62 @@ AcrSetSockaddr(JNI_STDARGS, acr_sockaddr
     return rc;
 }
 
+ACR_NET_EXPORT(jint, LocalEndpointAddress, sockaddr0)(JNI_STDARGS, jstring hostname)
+{
+    acr_sockaddr_t *sa = 0;
+    char *np;
+    int   rc = 0;
+
+    WITH_CSTR(hostname) {
+#if HAVE_SYS_UN_H
+        sa = calloc(1, sizeof(acr_sockaddr_t));
+        if (sa == 0)
+            return ACR_ENOMEM;
+        if (*J2S(hostname) != '/') {
+            size_t i = (int)strlcpy(sa->hostname, VAR_RUN_PATH "/", sizeof(sa->hostname));
+            strlcat(sa->hostname, J2S(hostname), sizeof(sa->hostname));
+            np = sa->hostname + i;
+            while (*np != '\0') {
+                if (*np == '/' || *np == ' ')
+                    *np = '_';
+                np++;
+            }
+        }
+        else
+            strlcpy(sa->hostname, J2S(hostname), sizeof(sa->hostname));
+        strlcpy(sa->sa.unx.sun_path, sa->hostname, sizeof(sa->sa.unx.sun_path));
+        sa->sa.unx.sun_family = AF_LOCAL;
+        sa->family  = AF_LOCAL;
+        sa->salen   = ISIZEOF(struct sockaddr_un);
+        sa->addrlen = ISIZEOF(sa->sa.unx.sun_path);
+        sa->ipaddr  = &(sa->sa.unx.sun_path);
+        sa->iplen   = sa->addrlen;
+#elif defined(WINDOWS)
+        sa = calloc(1, sizeof(acr_sockaddr_t));
+        if (sa == 0)
+            return ACR_ENOMEM;
+        strlcpy(sa->hostname, "\\\\.\\pipe\\", sizeof(sa->hostname));
+        strlcat(sa->hostname, J2S(hostname), sizeof(sa->hostname));
+        np = sa->hostname + 9;
+        while (*np != '\0') {
+            if (*np == '/' || *np == '\\'|| *np == ' ')
+                *np = '_';
+            np++;
+        }
+        sa->family  = AF_LOCAL;
+        sa->addrlen = ISIZEOF(sa->hostname);
+        sa->ipaddr  = &(sa->hostname);
+        sa->iplen   = sa->addrlen;
+#else
+        sa = 0;
+        rc = ACR_ENOTIMPL;
+#endif
+    } DONE_WITH_STR(hostname);
+
+    if (rc == 0)
+        rc = AcrSetSockaddr(env, obj, sa);
+    return rc;
+}
 
 ACR_NET_EXPORT(jstring, SocketAddress, hostname0)(JNI_STDARGS)
 {
@@ -913,60 +969,3 @@ ACR_NET_EXPORT(jint, SocketAddress, next
         sa->next = 0;
     return rc;
 }
-
-ACR_NET_EXPORT(jint, LocalSocketAddress, sockaddr0)(JNI_STDARGS, jstring hostname)
-{
-    acr_sockaddr_t *sa = 0;
-    char *np;
-    int   rc = 0;
-
-    WITH_CSTR(hostname) {        
-#if HAVE_SYS_UN_H
-        sa = calloc(1, sizeof(acr_sockaddr_t));
-        if (sa == 0)
-            return ACR_ENOMEM;
-        if (*J2S(hostname) != '/') {
-            size_t i = (int)strlcpy(sa->hostname, VAR_RUN_PATH "/", sizeof(sa->hostname));
-            strlcat(sa->hostname, J2S(hostname), sizeof(sa->hostname));
-            np = sa->hostname + i;
-            while (*np != '\0') {
-                if (*np == '/' || *np == ' ')
-                    *np = '_';
-                np++;
-            }
-        }
-        else
-            strlcpy(sa->hostname, J2S(hostname), sizeof(sa->hostname));
-        strlcpy(sa->sa.unx.sun_path, sa->hostname, sizeof(sa->sa.unx.sun_path));
-        sa->sa.unx.sun_family = AF_LOCAL;
-        sa->family  = AF_LOCAL;
-        sa->salen   = ISIZEOF(struct sockaddr_un);
-        sa->addrlen = ISIZEOF(sa->sa.unx.sun_path);
-        sa->ipaddr  = &(sa->sa.unx.sun_path);
-        sa->iplen   = sa->addrlen;
-#elif defined(WINDOWS)
-        sa = calloc(1, sizeof(acr_sockaddr_t));
-        if (sa == 0)
-            return ACR_ENOMEM;
-        strlcpy(sa->hostname, "\\\\.\\pipe\\", sizeof(sa->hostname));
-        strlcat(sa->hostname, J2S(hostname), sizeof(sa->hostname));
-        np = sa->hostname + 9;
-        while (*np != '\0') {
-            if (*np == '/' || *np == '\\'|| *np == ' ')
-                *np = '_';
-            np++;
-        }
-        sa->family  = AF_LOCAL;
-        sa->addrlen = ISIZEOF(sa->hostname);
-        sa->ipaddr  = &(sa->hostname);
-        sa->iplen   = sa->addrlen;
-#else
-        sa = 0;
-        rc = ACR_ENOTIMPL;
-#endif
-    } DONE_WITH_STR(hostname);
-
-    if (rc == 0)
-        rc = AcrSetSockaddr(env, obj, sa);
-    return rc;
-}

Modified: commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java?rev=1100178&r1=1100177&r2=1100178&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestAddress.java
Fri May  6 11:44:51 2011
@@ -30,7 +30,7 @@ public class TestAddress extends Assert
     public void posixLocalAddress()
         throws IOException
     {
-        LocalSocketAddress la = new LocalSocketAddress("foo/bar");
+        LocalEndpointAddress la = new LocalEndpointAddress("foo/bar");
         assertNotNull(la);
         assertEquals(la.toString(), "/var/run/foo_bar");
         assertEquals(la.getFamily(), AddressFamily.LOCAL);
@@ -42,7 +42,7 @@ public class TestAddress extends Assert
     public void windowsLocalAddress()
         throws IOException
     {
-        LocalSocketAddress la = new LocalSocketAddress("foo/bar");
+        LocalEndpointAddress la = new LocalEndpointAddress("foo/bar");
         assertNotNull(la);
         assertEquals(la.toString(), "\\\\.\\pipe\\foo_bar");
         la = null;



Mime
View raw message