tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native2/common jk_channel_apr_socket.c
Date Wed, 02 Oct 2002 12:50:05 GMT
mturk       2002/10/02 05:50:05

  Modified:    jk/native2/common jk_channel_apr_socket.c
  Log:
  Enable connecting to other IP addreses of the same host
  if the first one is down, checking all of them.
  This is only the case when the specified server name is not
  in the dot-ip notation.
  
  Revision  Changes    Path
  1.26      +45 -41    jakarta-tomcat-connectors/jk/native2/common/jk_channel_apr_socket.c
  
  Index: jk_channel_apr_socket.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_channel_apr_socket.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- jk_channel_apr_socket.c	27 Sep 2002 13:07:28 -0000	1.25
  +++ jk_channel_apr_socket.c	2 Oct 2002 12:50:05 -0000	1.26
  @@ -219,51 +219,55 @@
       apr_socket_t *sock=endpoint->channelData;
       apr_status_t ret;
       apr_int32_t timeout = (apr_int32_t)(socketInfo->timeout * APR_USEC_PER_SEC);
  -    char msg[128];
  +    char msg[128];
  +    int connected = 0;
  +
  +    while (remote_sa && !connected) {
  +        if ((ret = apr_socket_create(&sock, remote_sa->family, SOCK_STREAM,
  +                                     (apr_pool_t *)env->globalPool->_private))
  +                                    != APR_SUCCESS) {
  +            env->l->jkLog(env, env->l, remote_sa->next ? JK_LOG_DEBUG : JK_LOG_ERROR,
  +                         "channelApr.open(): error %d creating socket %d %s\n",
  +                          ret, socketInfo->host);
  +            remote_sa = remote_sa->next;
  +            continue;
  +        }
  +
   
  -    if (apr_socket_create(&sock, remote_sa->family, SOCK_STREAM,
  -                          (apr_pool_t *)env->globalPool->_private)
  -                         != APR_SUCCESS) {
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR,
  -                 "channelApr.open(): can't create socket %d %s\n",
  -                 errno, strerror( errno ) );
  -        return JK_ERR;
  -    } 
  -    env->l->jkLog(env, env->l, JK_LOG_INFO,
  -                  "channelApr.open(): create tcp socket %d\n", sock );
  -
  -    /* the default timeout (0) will set the socket to blocking with
  -       infinite timeouts.
  -     */
  -    if (timeout <= 0)
  -        timeout = -1;
  -    if (apr_setsocketopt(sock, APR_SO_TIMEOUT, timeout)!= APR_SUCCESS) {
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR,
  -                 "channelApr.open(): can't set timeout %d %s\n",
  -                 errno, strerror( errno ) );
  -        return JK_ERR;
  -    }
  -
  -    /* Tries to connect to JServ (continues trying while error is EINTR) */
  -    do {
           env->l->jkLog(env, env->l, JK_LOG_INFO,
  -                      "channelApr.open() connect on %d\n",sock);
  -        ret = apr_connect(sock, remote_sa);
  -        env->l->jkLog(env, env->l, JK_LOG_INFO,
  -                      "jk2_channel_apr_open: %d %s %s\n",ret, strerror( errno ),
  -                      socketInfo->host);
  -
  -    } while (ret == APR_EINTR);
  +            "channelApr.open(): create tcp socket %d\n", sock );
  +        
  +        /* the default timeout (0) will set the socket to blocking with
  +           infinite timeouts.
  +        */
  +        if (timeout <= 0)
  +            apr_socket_timeout_set(sock, 0);
  +        else
  +            apr_socket_timeout_set(sock, timeout);
  +
  +        /* make the connection out of the socket */
  +        do { 
  +            ret = apr_connect(sock, remote_sa);
  +        } while (APR_STATUS_IS_EINTR(ret));
  +        
  +        /* if an error occurred, loop round and try again */
  +        if (ret != APR_SUCCESS) {
  +            apr_socket_close(sock);
  +            env->l->jkLog(env, env->l, remote_sa->next ? JK_LOG_DEBUG : JK_LOG_ERROR,
  +                         "channelApr.open() attempt to connect to %pI (%s) failed %d\n",
  +                         remote_sa,
  +                         socketInfo->host,
  +                         ret);
  +            remote_sa = remote_sa->next;
  +            continue;
  +        }
  +        connected = 1;
  +    }
   
  -    /* Check if we connected */
  -    if(ret != APR_SUCCESS ) {
  -        apr_socket_close(sock);
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR,
  -                      "channelApr.open() connect failed %d %s\n",
  -                      ret, apr_strerror( ret, msg, sizeof(msg) ) );
  -        return JK_ERR;
  +    if (!connected) {
  +        apr_socket_close(sock);   
  +        return JK_ERR;
       }
  -    
       /* enable the use of keep-alive packets on TCP connection */
       if(keepalive) {
           int set = 1;
  
  
  

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


Mime
View raw message