You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2009/02/25 16:16:36 UTC

svn commit: r747814 - in /harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni: shared/socket.c unix/OSNetworkSystemLinux.c windows/OSNetworkSystemWin32.c

Author: hindessm
Date: Wed Feb 25 15:16:13 2009
New Revision: 747814

URL: http://svn.apache.org/viewvc?rev=747814&view=rev
Log:
Move platform-dependent ifdef to platform tree.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c?rev=747814&r1=747813&r2=747814&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c Wed Feb 25 15:16:13 2009
@@ -800,179 +800,6 @@
 }
 
 /**
- * A helper method, call selectRead with a small timeout until read is ready or an error occurs.
- *
- * @param	env						pointer to the JNI library
- * @param	hysocketP				socket pointer
- * @param	timeout				timeout value
- */
-
-I_32
-pollSelectRead (JNIEnv * env, jobject fileDescriptor, jint timeout,
-                BOOLEAN poll)
-{
-
-  I_32 result;
-  hysocket_t hysocketP;
-
-#if defined(WIN32)
-  PORT_ACCESS_FROM_ENV (env);
-  hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
-  if (!hysock_socketIsValid (hysocketP))
-    {
-      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
-      return (jint) - 1;
-    }
-
-  if (0 == timeout)
-    {
-      result = hysock_select_read (hysocketP, 0, 0, FALSE);
-    }
-  else
-    {
-      result =
-        hysock_select_read (hysocketP, timeout / 1000,
-                            (timeout % 1000) * 1000, FALSE);
-    }
-  if (HYPORT_ERROR_SOCKET_TIMEOUT == result)
-    throwJavaIoInterruptedIOException (env, result);
-  else if (0 > result)
-    throwJavaNetSocketException (env, result);
-#else
-    PORT_ACCESS_FROM_ENV (env);
-    
-    if (!poll) {
-        UDATA finishTime;
-            
-        /* 
-         * A zero timeout means wait forever. If not polling, return success
-         * and call receive() or accept() to block. 
-         */
-      
-        if (!timeout) {
-            return 0;
-        }
-
-        finishTime = hytime_msec_clock() + (UDATA) timeout;
-    
-        SELECT_NOPOLL:
-              
-        hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
-      
-        if (!hysock_socketIsValid (hysocketP)) {
-            throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
-            return (jint) - 1;
-        }
-        
-        result = hysock_select_read (hysocketP, timeout / 1000,
-                            (timeout % 1000) * 1000, FALSE);
-    
-        /*
-         *  if we time out, then throw the InterruptedIO exception
-         *  which gets converted by a caller into the appropriate thing
-         * 
-         *  if we are interrupted, recalculate our timeout and if we 
-         *  have time left or 0, try again.  If no time lest, throw InterruptedIO
-         *  Exception
-         * 
-         *  If some other error, just throw exceptionand bail
-         */
-        if (HYPORT_ERROR_SOCKET_TIMEOUT == result) {
-            throwJavaIoInterruptedIOException (env, result);
-        }
-        else if (HYPORT_ERROR_SOCKET_INTERRUPTED == result) {
-
-            timeout = finishTime - hytime_msec_clock();
-            
-            if (timeout < 0) {
-                throwJavaIoInterruptedIOException (env, result);
-            }
-            else { 
-                goto SELECT_NOPOLL;
-            }
-        }
-        else if (0 > result) {
-            throwJavaNetSocketException (env, result);
-        }
-    }
-  else  /* we are polling */
-    {
-      I_32 pollTimeoutUSec = 100000, pollMsec = 100;
-      UDATA finishTime = 0;
-      IDATA timeLeft = timeout;
-      BOOLEAN hasTimeout = timeout > 0;
-      
-      if (hasTimeout) {
-        finishTime = hytime_msec_clock () + (UDATA) timeout;
-      }
-      
-    select:
-      
-      /* 
-       * Fetch the handle every time in case the socket is closed.
-       */
-       
-      hysocketP =
-        getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
-      
-      if (!hysock_socketIsValid (hysocketP))
-        {
-          throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_INTERRUPTED);
-          return (jint) - 1;
-        }
-      
-      if (hasTimeout)
-        {
-          if (timeLeft - 10 < pollMsec) {
-            pollTimeoutUSec = timeLeft <= 0 ? 0 : (timeLeft * 1000);
-          }
-          
-          result = hysock_select_read (hysocketP, 0, pollTimeoutUSec, FALSE);
-
-          /*
-           *  because we are polling at a time smaller than timeout (presumably)
-           *  lets treat an interrupt and timeout the same - go see if we're done
-           *  timewise, and then just try again if not
-           */         
-          if (HYPORT_ERROR_SOCKET_TIMEOUT == result ||
-                HYPORT_ERROR_SOCKET_INTERRUPTED == result)
-            {
-              timeLeft = finishTime - hytime_msec_clock ();
-              
-              if (timeLeft <= 0) {
-                throwJavaIoInterruptedIOException (env, result);
-              }                
-              else
-                {
-                  goto select;
-                }
-            }   
-          else if (0 > result) {
-            throwJavaNetSocketException (env, result);
-          }
-        }
-      else  /* polling with no timeout (why would you do this?)*/
-        {
-          result = hysock_select_read (hysocketP, 0, pollTimeoutUSec, FALSE);
-
-          /* 
-           *  if interrupted (or a timeout) just retry
-           */
-          if (HYPORT_ERROR_SOCKET_TIMEOUT == result ||
-                HYPORT_ERROR_SOCKET_INTERRUPTED == result)
-            {
-              goto select;
-            }
-          else if (0 > result)
-            throwJavaNetSocketException (env, result);
-        }
-    }
-#endif
-
-  return result;
-}
-
-/**
  * Answer the status of the specified boolean option for the socket argument.
  *
  * @param	env				pointer to the JNI library

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c?rev=747814&r1=747813&r2=747814&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/OSNetworkSystemLinux.c Wed Feb 25 15:16:13 2009
@@ -537,3 +537,151 @@
 
   return (jint) nbytes;
 }
+
+/**
+ * A helper method, call selectRead with a small timeout until read is ready or an error occurs.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	hysocketP				socket pointer
+ * @param	timeout				timeout value
+ */
+
+I_32
+pollSelectRead (JNIEnv * env, jobject fileDescriptor, jint timeout,
+                BOOLEAN poll)
+{
+
+  I_32 result;
+  hysocket_t hysocketP;
+
+    PORT_ACCESS_FROM_ENV (env);
+    
+    if (!poll) {
+        UDATA finishTime;
+            
+        /* 
+         * A zero timeout means wait forever. If not polling, return success
+         * and call receive() or accept() to block. 
+         */
+      
+        if (!timeout) {
+            return 0;
+        }
+
+        finishTime = hytime_msec_clock() + (UDATA) timeout;
+    
+        SELECT_NOPOLL:
+              
+        hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
+      
+        if (!hysock_socketIsValid (hysocketP)) {
+            throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
+            return (jint) - 1;
+        }
+        
+        result = hysock_select_read (hysocketP, timeout / 1000,
+                            (timeout % 1000) * 1000, FALSE);
+    
+        /*
+         *  if we time out, then throw the InterruptedIO exception
+         *  which gets converted by a caller into the appropriate thing
+         * 
+         *  if we are interrupted, recalculate our timeout and if we 
+         *  have time left or 0, try again.  If no time lest, throw InterruptedIO
+         *  Exception
+         * 
+         *  If some other error, just throw exceptionand bail
+         */
+        if (HYPORT_ERROR_SOCKET_TIMEOUT == result) {
+            throwJavaIoInterruptedIOException (env, result);
+        }
+        else if (HYPORT_ERROR_SOCKET_INTERRUPTED == result) {
+
+            timeout = finishTime - hytime_msec_clock();
+            
+            if (timeout < 0) {
+                throwJavaIoInterruptedIOException (env, result);
+            }
+            else { 
+                goto SELECT_NOPOLL;
+            }
+        }
+        else if (0 > result) {
+            throwJavaNetSocketException (env, result);
+        }
+    }
+  else  /* we are polling */
+    {
+      I_32 pollTimeoutUSec = 100000, pollMsec = 100;
+      UDATA finishTime = 0;
+      IDATA timeLeft = timeout;
+      BOOLEAN hasTimeout = timeout > 0;
+      
+      if (hasTimeout) {
+        finishTime = hytime_msec_clock () + (UDATA) timeout;
+      }
+      
+    select:
+      
+      /* 
+       * Fetch the handle every time in case the socket is closed.
+       */
+       
+      hysocketP =
+        getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
+      
+      if (!hysock_socketIsValid (hysocketP))
+        {
+          throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_INTERRUPTED);
+          return (jint) - 1;
+        }
+      
+      if (hasTimeout)
+        {
+          if (timeLeft - 10 < pollMsec) {
+            pollTimeoutUSec = timeLeft <= 0 ? 0 : (timeLeft * 1000);
+          }
+          
+          result = hysock_select_read (hysocketP, 0, pollTimeoutUSec, FALSE);
+
+          /*
+           *  because we are polling at a time smaller than timeout (presumably)
+           *  lets treat an interrupt and timeout the same - go see if we're done
+           *  timewise, and then just try again if not
+           */         
+          if (HYPORT_ERROR_SOCKET_TIMEOUT == result ||
+                HYPORT_ERROR_SOCKET_INTERRUPTED == result)
+            {
+              timeLeft = finishTime - hytime_msec_clock ();
+              
+              if (timeLeft <= 0) {
+                throwJavaIoInterruptedIOException (env, result);
+              }                
+              else
+                {
+                  goto select;
+                }
+            }   
+          else if (0 > result) {
+            throwJavaNetSocketException (env, result);
+          }
+        }
+      else  /* polling with no timeout (why would you do this?)*/
+        {
+          result = hysock_select_read (hysocketP, 0, pollTimeoutUSec, FALSE);
+
+          /* 
+           *  if interrupted (or a timeout) just retry
+           */
+          if (HYPORT_ERROR_SOCKET_TIMEOUT == result ||
+                HYPORT_ERROR_SOCKET_INTERRUPTED == result)
+            {
+              goto select;
+            }
+          else if (0 > result)
+            throwJavaNetSocketException (env, result);
+        }
+    }
+
+  return result;
+}

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c?rev=747814&r1=747813&r2=747814&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSNetworkSystemWin32.c Wed Feb 25 15:16:13 2009
@@ -378,3 +378,47 @@
 
   return (jint) nbytes;
 }
+
+
+/**
+ * A helper method, call selectRead with a small timeout until read is ready or an error occurs.
+ *
+ * @param	env						pointer to the JNI library
+ * @param	hysocketP				socket pointer
+ * @param	timeout				timeout value
+ */
+
+I_32
+pollSelectRead (JNIEnv * env, jobject fileDescriptor, jint timeout,
+                BOOLEAN poll)
+{
+
+  I_32 result;
+  hysocket_t hysocketP;
+  PORT_ACCESS_FROM_ENV (env);
+
+  hysocketP = getJavaIoFileDescriptorContentsAsAPointer (env, fileDescriptor);
+  if (!hysock_socketIsValid (hysocketP))
+    {
+      throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
+      return (jint) - 1;
+    }
+
+  if (0 == timeout)
+    {
+      result = hysock_select_read (hysocketP, 0, 0, FALSE);
+    }
+  else
+    {
+      result =
+        hysock_select_read (hysocketP, timeout / 1000,
+                            (timeout % 1000) * 1000, FALSE);
+    }
+  if (HYPORT_ERROR_SOCKET_TIMEOUT == result)
+    throwJavaIoInterruptedIOException (env, result);
+  else if (0 > result)
+    throwJavaNetSocketException (env, result);
+
+  return result;
+}
+