commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1100456 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr/netapi.h shared/netaddr.c
Date Sat, 07 May 2011 05:40:27 GMT
Author: mturk
Date: Sat May  7 05:40:27 2011
New Revision: 1100456

URL: http://svn.apache.org/viewvc?rev=1100456&view=rev
Log:
Simplify addr structure. We don't need next pointer cause array is allocated lineary

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h?rev=1100456&r1=1100455&r2=1100456&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netapi.h Sat May  7 05:40:27
2011
@@ -38,12 +38,14 @@ struct acr_sockaddr_t {
     /** How big should the address buffer be?  16 for v4 or 46 for v6
      *  used in inet_ntop... */
     int         addrlen;
+    /**
+     * If multiple addresses were found by AcrGetSockaddrInfo(),
+     * this points to a number of the next address.
+     */
+    int         addrcnt;
     /** This points to the IP address structure within the appropriate
      *  sockaddr structure.  */
     void       *ipaddr;
-    /** If multiple addresses were found by AcrGetSockaddrInfo(), this
-     *  points to a representation of the next address. */
-    acr_sockaddr_t *next;
     /** Union of either IPv4 or IPv6 sockaddr. */
     union {
         /** IPv4 sockaddr structure */

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=1100456&r1=1100455&r2=1100456&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Sat May  7 05:40:27 2011
@@ -474,7 +474,7 @@ call_resolver(acr_sockaddr_t **sa, const
               int family, int port, int flags)
 {
     struct addrinfo hints, *ai, *ai_list;
-    acr_sockaddr_t *prev_sa, *new_sa;
+    acr_sockaddr_t *new_sa;
     int error;
     int ai_len = ISIZEOF(acr_sockaddr_t);
     int ai_cnt = 0;
@@ -533,7 +533,6 @@ call_resolver(acr_sockaddr_t **sa, const
 #endif /* WIN32 */
     }
 
-    prev_sa = 0;
     ai = ai_list;
     while (ai != 0) {
         if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) {
@@ -543,6 +542,11 @@ call_resolver(acr_sockaddr_t **sa, const
         ai_cnt++;
         ai = ai->ai_next;
     }
+    if (ai_cnt == 0) {
+        /* No inet addresses found
+         */
+        return ACR_ENOENT;
+    }
     new_sa = calloc(1, ai_len * ai_cnt);
     if (sa == 0)
         return ACR_ENOMEM;
@@ -558,18 +562,15 @@ call_resolver(acr_sockaddr_t **sa, const
         memcpy(&new_sa->sa, ai->ai_addr, ai->ai_addrlen);
         sockaddr_vars_set(new_sa, ai->ai_family, port);
 
-        if (!prev_sa) {
+        if (*sa == 0) {
             /* first element in new list */
-            if (hostname != 0)
-                strlcpy(new_sa->hostname, hostname, NI_MAXHOST);
+            new_sa->addrcnt = ai_cnt;
             *sa = new_sa;
         }
-        else {
-            strlcpy(new_sa->hostname, prev_sa->hostname, NI_MAXHOST);
-            prev_sa->next = new_sa;
-        }
+        if (hostname != 0)
+            strlcpy(new_sa->hostname, hostname, NI_MAXHOST);
 
-        prev_sa = new_sa++;
+        new_sa++;
         ai = ai->ai_next;
     }
     freeaddrinfo(ai_list);
@@ -732,20 +733,14 @@ static jbyteArray
 sockaddr_to_byte_array(JNI_STDENV, acr_sockaddr_t *sa)
 {
     jbyteArray ba;
-    acr_sockaddr_t *ai;
-    int ai_len = ISIZEOF(acr_sockaddr_t);
-    int ai_cnt = 0;
+    jsize ai_len;
 
-    ai = sa;
-    while (ai != 0) {
-        ai_cnt++;
-        ai = ai->next;
-    }
-    if (ai_cnt == 0)
+    if (sa == 0)
         return 0;
-    ba = (*env)->NewByteArray(env, ai_len * ai_cnt);
+    ai_len =  sa->addrcnt * ISIZEOF(acr_sockaddr_t);
+    ba = (*env)->NewByteArray(env, ai_len);
     if (ba != 0)
-        (*env)->SetByteArrayRegion(env, ba, 0, ai_len * ai_cnt, (jbyte *)sa);
+        (*env)->SetByteArrayRegion(env, ba, 0, ai_len, (jbyte *)sa);
     AcrFree(sa);
     return ba;
 }
@@ -877,6 +872,7 @@ ACR_NET_EXPORT(jbyteArray, LocalEndpoint
         ACR_THROW_NET_ERROR(rc);
         return 0;
     }
+    sa.addrcnt = 1;
     ba = (*env)->NewByteArray(env, ISIZEOF(acr_sockaddr_t));
     if (ba != 0)
         (*env)->SetByteArrayRegion(env, ba, 0, ISIZEOF(acr_sockaddr_t), (jbyte *)&sa);



Mime
View raw message