harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r441311 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native: luni/shared/socket.c port/linux/hysock.c
Date Fri, 08 Sep 2006 00:51:36 GMT
Author: geirm
Date: Thu Sep  7 17:51:36 2006
New Revision: 441311

URL: http://svn.apache.org/viewvc?view=rev&rev=441311
Log:
modifications to hysock_select() to report when 
interrupted, and then in pollSelectRead() in 
socket.c for linux only to handle the 
interrupt return code.

This passes all tests and also fixes the problem
with tomcat.  I'd like to continue with the other
uses of hysock_select() in socket.c and elsewhere
but want to commit to let others review before
I go further


Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/linux/hysock.c

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c?view=diff&rev=441311&r1=441310&r2=441311
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/socket.c
Thu Sep  7 17:51:36 2006
@@ -837,67 +837,127 @@
   else if (0 > result)
     throwJavaNetSocketException (env, result);
 #else
-  PORT_ACCESS_FROM_ENV (env);
-  if (!poll)
-    {
-      /* A zero timeout means wait forever. If not polling, return success */
-      /* and call receive() or accept() to block. */
-      if (!timeout)
-        return 0;
-      hysocketP =
-        getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
-      if (!hysock_socketIsValid (hysocketP))
-        {
-          throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_BADSOCKET);
-          return (jint) - 1;
+    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;
         }
-      result =
-        hysock_select_read (hysocketP, timeout / 1000,
+
+        finishTime = hytime_msec_clock() + (UDATA) timeout;
+    
+        SELECT_NOPOLL:
+              
+        hysocketP = getJavaIoFileDescriptorContentsAsPointer (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 (HYPORT_ERROR_SOCKET_TIMEOUT == result)
-        throwJavaIoInterruptedIOException (env, result);
-      else if (0 > result)
-        throwJavaNetSocketException (env, result);
+    
+        /*
+         *  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
+  else  /* we are polling */
     {
-      I_32 pollTimeout = 100000, pollMsec = 100;
+      I_32 pollTimeoutUSec = 100000, pollMsec = 100;
       UDATA finishTime;
       IDATA timeLeft = timeout;
       BOOLEAN hasTimeout = timeout > 0;
-      if (hasTimeout)
+      
+      if (hasTimeout) {
         finishTime = hytime_msec_clock () + (UDATA) timeout;
+      }
+      
     select:
-      /* Fetch the handle every time in case the socket is closed. */
+      
+      /* 
+       * Fetch the handle every time in case the socket is closed.
+       */
+       
       hysocketP =
         getJavaIoFileDescriptorContentsAsPointer (env, fileDescriptor);
+      
       if (!hysock_socketIsValid (hysocketP))
         {
           throwJavaNetSocketException (env, HYPORT_ERROR_SOCKET_INTERRUPTED);
           return (jint) - 1;
         }
+      
       if (hasTimeout)
         {
-          if (timeLeft - 10 < pollMsec)
-            pollTimeout = timeLeft <= 0 ? 0 : (timeLeft * 1000);
-          result = hysock_select_read (hysocketP, 0, pollTimeout, FALSE);
-          if (HYPORT_ERROR_SOCKET_TIMEOUT == result)
+          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)
+              
+              if (timeLeft <= 0) {
                 throwJavaIoInterruptedIOException (env, result);
+              }                
               else
                 {
                   goto select;
                 }
-            }
-          else if (0 > result)
+            }   
+          else if (0 > result) {
             throwJavaNetSocketException (env, result);
+          }
         }
-      else
+      else  /* polling with no timeout (why would you do this?)*/
         {
-          result = hysock_select_read (hysocketP, 0, pollTimeout, FALSE);
-          if (HYPORT_ERROR_SOCKET_TIMEOUT == result)
+          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;
             }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/linux/hysock.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/linux/hysock.c?view=diff&rev=441311&r1=441310&r2=441311
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/linux/hysock.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/port/linux/hysock.c
Thu Sep  7 17:51:36 2006
@@ -2567,31 +2567,33 @@
                hyfdset_t readfds, hyfdset_t writefds, hyfdset_t exceptfds,
                hytimeval_t timeout)
 {
-  I_32 rc = 0;
-  I_32 result = 0;
+    I_32 rc = 0;
+    I_32 result = 0;
 
-  result =
-    select (nfds, readfds == NULL ? NULL : &readfds->handle,
-            writefds == NULL ? NULL : &writefds->handle,
-            exceptfds == NULL ? NULL : &exceptfds->handle,
-            timeout == NULL ? NULL : &timeout->time);
-  if (result == -1)
-    {
-      rc = errno;
-      HYSOCKDEBUG ("<select failed, err=%d>\n", rc);
-      rc =
-        portLibrary->error_set_last_error (portLibrary, rc,
-                                           HYPORT_ERROR_SOCKET_OPFAILED);
-    }
-  else
-    {
-      if (result)
-        {
-          rc = result;
+    result = select (nfds, 
+                        readfds == NULL ? NULL : &readfds->handle,
+                        writefds == NULL ? NULL : &writefds->handle,
+                        exceptfds == NULL ? NULL : &exceptfds->handle,
+                        timeout == NULL ? NULL : &timeout->time);
+
+    if (result == -1) {
+        HYSOCKDEBUG ("<select failed, err=%d>\n", errno);
+
+        if (errno == EINTR) {
+            rc = portLibrary->error_set_last_error(portLibrary, errno, 
+                                            HYPORT_ERROR_SOCKET_INTERRUPTED);
         }
-      else
-        {
-          rc = HYPORT_ERROR_SOCKET_TIMEOUT;
+        else {
+            rc = portLibrary->error_set_last_error (portLibrary, errno,
+                                            HYPORT_ERROR_SOCKET_OPFAILED);
+        }
+    }
+    else {
+        if (result) {
+            rc = result;
+        } 
+        else {
+            rc = HYPORT_ERROR_SOCKET_TIMEOUT;
         }
     }
   return rc;



Mime
View raw message