You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2009/12/23 11:19:31 UTC

svn commit: r893456 - /tomcat/jk/trunk/native/common/jk_connect.c

Author: mturk
Date: Wed Dec 23 10:19:31 2009
New Revision: 893456

URL: http://svn.apache.org/viewvc?rev=893456&view=rev
Log:
In case the read was transient use 2ms timeout for a second attempt.

Modified:
    tomcat/jk/trunk/native/common/jk_connect.c

Modified: tomcat/jk/trunk/native/common/jk_connect.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_connect.c?rev=893456&r1=893455&r2=893456&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_connect.c (original)
+++ tomcat/jk/trunk/native/common/jk_connect.c Wed Dec 23 10:19:31 2009
@@ -671,7 +671,6 @@
 #define MAX_SECS_TO_LINGER 30
 #endif
 #define SECONDS_TO_LINGER  2
-
 #ifndef SHUT_WR
 #ifdef SD_SEND
 #define SHUT_WR SD_SEND
@@ -696,6 +695,7 @@
     int rd = 0;
     int rp = 0;
     int save_errno;
+    int timeout = SECONDS_TO_LINGER * 1000;
     struct timeval tv;
     time_t start = time(NULL);
 
@@ -739,12 +739,12 @@
          * close the connection.
          */
         FD_SET(sd, &rs);
-        tv.tv_sec  = SECONDS_TO_LINGER;
-        tv.tv_usec = 0;
+        tv.tv_sec  = timeout / 1000;
+        tv.tv_usec = (timeout % 1000) * 1000;
 #endif
         rp = 0;
 #ifdef HAVE_POLL
-        if (poll(&fds, 1, SECONDS_TO_LINGER * 1000) > 0)
+        if (poll(&fds, 1, timeout) > 0)
 #else
         if (select((int)sd + 1, &rs, NULL, NULL, &tv) > 0)
 #endif
@@ -768,6 +768,13 @@
             break;
         rd += rp;
         if (rp < sizeof(dummy)) {
+            if (timeout > SECONDS_TO_LINGER) {
+                /* Try once again with 1000 times smaller timeout
+                 * In our case 2 msec.
+                 */
+                timeout = SECONDS_TO_LINGER;
+                continue;
+            }
             /* We have readed less then size of buffer
              * It's a good chance there will be no more data
              * to read.
@@ -787,6 +794,7 @@
             shutdown(sd, SHUT_RD);
             break;
         }
+        timeout = SECONDS_TO_LINGER * 1000;
     } while (difftime(time(NULL), start) < MAX_SECS_TO_LINGER);
 
     rc = jk_close_socket(sd, l);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org