tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r603556 - in /tomcat/connectors/trunk/jk/native/common: jk_ajp_common.c jk_connect.c jk_connect.h
Date Wed, 12 Dec 2007 11:03:48 GMT
Author: rjung
Date: Wed Dec 12 03:03:47 2007
New Revision: 603556

URL: http://svn.apache.org/viewvc?rev=603556&view=rev
Log:
Move ajp_is_input_event() to jk_connect and
rename to jk_is_input_event().

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
    tomcat/connectors/trunk/jk/native/common/jk_connect.c
    tomcat/connectors/trunk/jk/native/common/jk_connect.h

Modified: tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c?rev=603556&r1=603555&r2=603556&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_ajp_common.c Wed Dec 12 03:03:47 2007
@@ -749,46 +749,6 @@
 }
 
 /*
- * Wait input event on ajp_endpoint for timeout ms
- */
-static int ajp_is_input_event(ajp_endpoint_t * ae, int timeout, jk_logger_t *l)
-{
-    fd_set rset;
-    struct timeval tv;
-    int rc;
-
-    FD_ZERO(&rset);
-    FD_SET(ae->sd, &rset);
-    tv.tv_sec = timeout / 1000;
-    tv.tv_usec = (timeout % 1000) * 1000;
-
-    do {
-        rc = select((int)ae->sd + 1, &rset, NULL, NULL, &tv);
-    } while (rc < 0 && errno == EINTR);
-
-    ae->last_errno = 0;
-    if (rc == 0) {
-        /* Timeout. Set the errno to timeout */
-#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
-        errno = WSAETIMEDOUT - WSABASEERR;
-#else
-        errno = ETIMEDOUT;
-#endif
-        ae->last_errno = errno;
-        return JK_FALSE;
-    }
-    else if (rc < 0) {
-        ae->last_errno = errno;
-        jk_log(l, JK_LOG_WARNING,
-               "error during select (errno=%d)", ae->last_errno);
-        return JK_FALSE;
-    }
-    else
-        return JK_TRUE;
-}
-
-
-/*
  * Handle the CPING/CPONG initial query
  */
 static int ajp_handle_cping_cpong(ajp_endpoint_t * ae, int timeout, jk_logger_t *l)
@@ -823,8 +783,12 @@
 
     /* wait for Pong reply for timeout milliseconds
      */
-    if (ajp_is_input_event(ae, timeout, l) == JK_FALSE) {
+    if (jk_is_input_event(ae->sd, timeout, l) == JK_FALSE) {
+        ae->last_errno = errno;
         jk_log(l, JK_LOG_INFO, "timeout in reply pong");
+        /* We can't trust this connection any more. */
+        jk_shutdown_socket(ae->sd, l);
+        ae->sd = JK_INVALID_SOCKET;
         JK_TRACE_EXIT(l);
         return JK_FALSE;
     }
@@ -880,7 +844,7 @@
         }
         /* should we send a CPING to validate connection ? */
         if (ae->worker->connect_timeout > 0) {
-            rc = ajp_handle_cping_cpong (ae,
+            rc = ajp_handle_cping_cpong(ae,
                         ae->worker->connect_timeout, l);
             JK_TRACE_EXIT(l);
             return rc;
@@ -1660,12 +1624,16 @@
 
         /* If we set a reply timeout, check if something is available */
         if (p->worker->reply_timeout > 0) {
-            if (ajp_is_input_event(p, p->worker->reply_timeout, l) ==
+            if (jk_is_input_event(p->sd, p->worker->reply_timeout, l) ==
                 JK_FALSE) {
+                p->last_errno = errno;
                 jk_log(l, JK_LOG_ERROR,
                        "(%s) Timeout with waiting reply from tomcat. "
                        "Tomcat is down, stopped or network problems (errno=%d)",
                        p->worker->name, p->last_errno);
+                /* We can't trust this connection any more. */
+                jk_shutdown_socket(p->sd, l);
+                p->sd = JK_INVALID_SOCKET;
                 if (headeratclient == JK_FALSE) {
                     if (p->worker->recovery_opts & RECOVER_ABORT_IF_TCGETREQUEST)
                         op->recoverable = JK_FALSE;

Modified: tomcat/connectors/trunk/jk/native/common/jk_connect.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_connect.c?rev=603556&r1=603555&r2=603556&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_connect.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_connect.c Wed Dec 12 03:03:47 2007
@@ -789,6 +789,55 @@
     return buf;
 }
 
+/** Wait for input event on socket until timeout
+ * @param sd      socket to use
+ * @param timeout wait timeout in milliseconds
+ * @param l       logger
+ * @return        JK_FALSE: Timeout expired without something to read
+ *                JK_FALSE: Error during waiting
+ *                JK_TRUE: success
+ */
+int jk_is_input_event(jk_sock_t sd, int timeout, jk_logger_t *l)
+{
+    fd_set rset;
+    struct timeval tv;
+    int rc;
+    int save_errno;
+
+    JK_TRACE_ENTER(l);
+
+    FD_ZERO(&rset);
+    FD_SET(sd, &rset);
+    tv.tv_sec = timeout / 1000;
+    tv.tv_usec = (timeout % 1000) * 1000;
+
+    do {
+        rc = select((int)sd + 1, &rset, NULL, NULL, &tv);
+    } while (rc < 0 && errno == EINTR);
+
+    errno = 0;
+    if (rc == 0) {
+        /* Timeout. Set the errno to timeout */
+#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
+        errno = WSAETIMEDOUT - WSABASEERR;
+#else
+        errno = ETIMEDOUT;
+#endif
+        JK_TRACE_EXIT(l);
+        return JK_FALSE;
+    }
+    else if (rc < 0) {
+        save_errno = errno;
+        jk_log(l, JK_LOG_WARNING,
+               "error during select on socket sd = %d (errno=%d)", sd, errno);
+        errno = save_errno;
+        JK_TRACE_EXIT(l);
+        return JK_FALSE;
+    }
+    JK_TRACE_EXIT(l);
+    return JK_TRUE;
+}
+
 /** Test if a socket is still connected
  * @param sd   socket to use
  * @param l    logger

Modified: tomcat/connectors/trunk/jk/native/common/jk_connect.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_connect.h?rev=603556&r1=603555&r2=603556&view=diff
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_connect.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_connect.h Wed Dec 12 03:03:47 2007
@@ -53,6 +53,8 @@
 
 char *jk_dump_hinfo(struct sockaddr_in *saddr, char *buf);
 
+int jk_is_input_event(jk_sock_t sd, int timeout, jk_logger_t *l);
+
 int jk_is_socket_connected(jk_sock_t sd, jk_logger_t *l);
 
 



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


Mime
View raw message