harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r722940 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared: OSNetworkSystem.c nethelp.c
Date Wed, 03 Dec 2008 15:47:30 GMT
Author: tellison
Date: Wed Dec  3 07:47:30 2008
New Revision: 722940

URL: http://svn.apache.org/viewvc?rev=722940&view=rev
Log:
Code tidy-up.  Functionally equivalent

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c?rev=722940&r1=722939&r2=722940&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/OSNetworkSystem.c
Wed Dec  3 07:47:30 2008
@@ -163,9 +163,8 @@
   jfieldID descriptorFID;
   descriptorCLS = (*env)->FindClass(env, "java/lang/Long");
   descriptorFID = (*env)->GetFieldID(env, descriptorCLS, "value", "J");
-  (*env)->SetLongField(env, longclass, descriptorFID,
-                       (jlong) ((IDATA) context));
-};
+  (*env)->SetLongField(env, longclass, descriptorFID, (jlong) (IDATA) context);
+}
 
 /**
  * A helper method, to get the connect context.
@@ -180,9 +179,8 @@
   jfieldID descriptorFID;
   descriptorCLS = (*env)->FindClass(env, "java/lang/Long");
   descriptorFID = (*env)->GetFieldID(env, descriptorCLS, "value", "J");
-  return (void
-          *) ((IDATA) ((*env)->GetLongField(env, longclass, descriptorFID)));
-};
+  return (void *) (IDATA) ((*env)->GetLongField(env, longclass, descriptorFID));
+}
 
 /**
  * A helper method, to set the remote address into the socketImpl.
@@ -420,7 +418,7 @@
   }
 
   /* If no bytes are read, return -1 to signal 'endOfFile' to the Java input stream */
-  return (0 == result) ? (jint) - 1 : (jint) result;
+  return (0 == result) ? (jint) -1 : (jint) result;
 }
 
 
@@ -512,47 +510,49 @@
  */
 JNIEXPORT jint JNICALL
 Java_org_apache_harmony_luni_platform_OSNetworkSystem_connect
-  (JNIEnv * env, jobject thiz, jobject fileDescriptor, jint trafficClass,
+  (JNIEnv * env, jobject thiz, jobject fd, jint trafficClass,
    jobject inetAddress, jint remotePort)
 {
   PORT_ACCESS_FROM_ENV(env);
-  jbyte nAddrBytes[HYSOCK_INADDR6_LEN];
-  int length;
+  U_8 nAddrBytes[HYSOCK_INADDR6_LEN];
+  I_32 length = 0;
   U_16 nPort;
   I_32 result;
   hysocket_t socketP;
   hysockaddr_struct sockaddrP;
   U_32 scope_id = 0;
 
-  socketP = getJavaIoFileDescriptorContentsAsAPointer(env, fileDescriptor);
+  socketP = getJavaIoFileDescriptorContentsAsAPointer(env, fd);
   if (!hysock_socketIsValid(socketP)) {
     throwJavaNetSocketException(env, HYPORT_ERROR_SOCKET_BADSOCKET);
     return -1;
-  } else {
-    netGetJavaNetInetAddressValue(env, inetAddress, (U_8 *) nAddrBytes,
-                                  (U_32 *) & length);
+  }
 
-    nPort = hysock_htons((U_16) remotePort);
-    if (length == HYSOCK_INADDR_LEN) {
-      hysock_sockaddr_init6(&sockaddrP, (U_8 *) nAddrBytes, length,
-                            HYADDR_FAMILY_AFINET4, nPort, 0, scope_id,
-                            socketP);
-    } else {
-      netGetJavaNetInetAddressScopeId(env, inetAddress, &scope_id);
-      hysock_sockaddr_init6(&sockaddrP, (U_8 *) nAddrBytes, length,
-                            HYADDR_FAMILY_AFINET6, nPort,
-                            (trafficClass & 0xFF) << 20, scope_id, socketP);
-    }
+  netGetJavaNetInetAddressValue(env, inetAddress, nAddrBytes, &length);
+  nPort = hysock_htons((U_16) remotePort);
 
-    result = hysock_connect(socketP, &sockaddrP);
-    if (0 != result) {
-      throwJavaNetConnectException(env, result);
-      return result;
-    }
+  if (length == HYSOCK_INADDR_LEN) {
+    // IPv4
+    hysock_sockaddr_init6(&sockaddrP, nAddrBytes, length,
+                          HYADDR_FAMILY_AFINET4, nPort, 0, 0, socketP);
+  } else {
+    // IPv6
+    netGetJavaNetInetAddressScopeId(env, inetAddress, &scope_id);
+    hysock_sockaddr_init6(&sockaddrP, nAddrBytes, length,
+                          HYADDR_FAMILY_AFINET6, nPort,
+                          (trafficClass & 0xFF) << 20, scope_id, socketP);
   }
+
+  result = hysock_connect(socketP, &sockaddrP);
+  if (0 != result) {
+    throwJavaNetConnectException(env, result);
+    return result;
+  }
+
   return result;
 }
 
+
 /*
  * Class:     org_apache_harmony_luni_platform_OSNetworkSystem
  * Method:    connectWithTimeout
@@ -806,6 +806,7 @@
    */
   if (result < 0) {
     throwJavaNetSocketException(env, result);
+    return;
   }
 }
 
@@ -997,11 +998,11 @@
   if (result < 0 && result != HYPORT_ERROR_SOCKET_MSGSIZE) {
     throwJavaNetSocketException(env, result);
     return (jint) 0;
-  } else {
-    updateAddress(env, &sockaddrP, senderAddress);
-    hport = (jint) hysock_ntohs(hysock_sockaddr_port(&sockaddrP));
-    return hport;
   }
+
+  updateAddress(env, &sockaddrP, senderAddress);
+  hport = (jint) hysock_ntohs(hysock_sockaddr_port(&sockaddrP));
+  return hport;
 }
 
 /*
@@ -1090,12 +1091,12 @@
   if (result < 0) {
     throwJavaNetSocketException(env, result);
     return (jint) 0;
-  } else {
-    if (datagramPacket != NULL) {
-      updatePacket(env, &sockaddrP, datagramPacket, result);
-    }
-    return (jint) result;
   }
+
+  if (datagramPacket != NULL) {
+    updatePacket(env, &sockaddrP, datagramPacket, result);
+  }
+  return (jint) result;
 }
 
 /*

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c?rev=722940&r1=722939&r2=722940&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/nethelp.c Wed
Dec  3 07:47:30 2008
@@ -665,17 +665,14 @@
  * @param[in]  anInetAddress  the object to access the 'value' field of
  * @param[out] buffer         bytes from the address jbyte array
  * @param[out] length         length of the address in stored in buffer
- *
  */
-
 void
-netGetJavaNetInetAddressValue (JNIEnv * env, jobject anInetAddress,
-             U_8 * buffer, U_32 * length)
+netGetJavaNetInetAddressValue
+  (JNIEnv * env, jobject anInetAddress, U_8 * buffer, U_32 * length)
 {
   jbyteArray byte_array =
     (jbyteArray) ((*env)->GetObjectField (env, anInetAddress,
-            HARMONY_CACHE_GET (env,
-               FID_java_net_InetAddress_address)));
+            HARMONY_CACHE_GET (env, FID_java_net_InetAddress_address)));
   *length = (*env)->GetArrayLength (env, byte_array);
   (*env)->GetByteArrayRegion (env, byte_array, 0, *length, (jbyte *)buffer);
 }



Mime
View raw message