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 2005/02/19 10:13:35 UTC

cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

mturk       2005/02/19 01:13:35

  Modified:    jk/native/common jk_ajp_common.c jk_connect.c
  Log:
  Use alternative is_socket_connected implementation using
  select with 1 microsecond timeout. It should be both faster and
  usable on netware too.
  
  Revision  Changes    Path
  1.91      +7 -9      jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c
  
  Index: jk_ajp_common.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- jk_ajp_common.c	18 Feb 2005 08:27:21 -0000	1.90
  +++ jk_ajp_common.c	19 Feb 2005 09:13:35 -0000	1.91
  @@ -847,10 +847,9 @@
               if (ae->worker->cache_timeout > 0 || ae->worker->recycle_timeout > 0)
                   ae->last_access = time(NULL);
               if (ae->worker->socket_timeout > 0) {
  -                int rc = 0;
  -                if ((rc = jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) != 1) {
  -                        jk_log(l, JK_LOG_INFO,
  -                            "Socket is not connected any more (status=%d)", rc);
  +                if (!jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) {
  +                    jk_log(l, JK_LOG_INFO,
  +                           "Socket is not connected any more (errno=%d)", errno);
                       jk_close_socket(ae->sd);
                       ae->sd = -1;
                       JK_TRACE_EXIT(l);
  @@ -1161,10 +1160,9 @@
       while ((ae->sd > 0)) {
           err = 0;
           if (ae->worker->socket_timeout) {
  -            int rc = 0;
  -            if ((rc = jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) != 1) {
  -                    jk_log(l, JK_LOG_INFO,
  -                           "Socket is not connected any more (status=%d)", rc);
  +            if (!jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) {
  +                jk_log(l, JK_LOG_INFO,
  +                       "Socket is not connected any more (errno=%d)", errno);
                   jk_close_socket(ae->sd);
                   ae->sd = -1;
                   err++;
  
  
  
  1.43      +48 -2     jakarta-tomcat-connectors/jk/native/common/jk_connect.c
  
  Index: jk_connect.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.c,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- jk_connect.c	17 Feb 2005 08:26:42 -0000	1.42
  +++ jk_connect.c	19 Feb 2005 09:13:35 -0000	1.43
  @@ -194,18 +194,36 @@
                      sock_buf);
       }
   
  -#ifdef WIN32
       if (timeout > 0) {
  +#ifdef WIN32
           timeout = timeout * 1000;
           setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
                      (char *) &timeout, sizeof(int));
           setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
                      (char *) &timeout, sizeof(int));
  +#else
  +        /* TODO: How to set the timeout for other platforms? */
  +#endif
           if (JK_IS_DEBUG_LEVEL(l))
               jk_log(l, JK_LOG_DEBUG,
                      "timeout %d set for socket=%d",
                      timeout, sock);
       }
  +#ifdef SO_NOSIGPIPE
  +    /* The preferred method on Mac OS X (10.2 and later) to prevent SIGPIPEs when
  +     * sending data to a dead peer. Possibly also existing and in use on other BSD
  +     * systems?
  +    */
  +    set = 1;
  +    if (setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (const char *)&set,
  +                   sizeof(int))) {
  +        JK_GET_SOCKET_ERRNO();
  +        jk_log(l, JK_LOG_ERROR,
  +                "failed setting SO_NOSIGPIPE with errno=%d", errno);
  +        jk_close_socket(sock);
  +        JK_TRACE_EXIT(l);
  +        return -1;
  +    }
   #endif
       /* Tries to connect to Tomcat (continues trying while error is EINTR) */
       do {
  @@ -405,6 +423,32 @@
       return 0;
   }
   
  +#if 1
  +int jk_is_socket_connected(int sd, int timeout)
  +{
  +    fd_set fd;
  +    struct timeval tv;
  + 
  +    FD_ZERO(&fd);
  +    FD_SET(sd, &fd);
  +
  +    /* Wait one microsecond */
  +    tv.tv_sec  = 0;
  +    tv.tv_usec = 1;
  +
  +    /* If we get a timeout, then we are still connected */
  +    if (select(1, &fd, NULL, NULL, &tv) == 0)
  +        return 1;
  +    else {
  +#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
  +        errno = WSAGetLastError() - WSABASEERR;
  +#endif
  +        return 0;
  +    }
  +}
  +
  +#else
  +
   #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
   #define EWOULDBLOCK (WSAEWOULDBLOCK - WSABASEERR)
   #endif
  @@ -434,3 +478,5 @@
       else
           return rc;
   }
  +
  +#endif
  
  
  

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


Re: cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

Posted by NormW <no...@bocnet.com.au>.
Greetings,
Will see... :-)
N.

mturk@apache.org wrote:
> mturk       2005/02/19 01:13:35
> 
>   Modified:    jk/native/common jk_ajp_common.c jk_connect.c
>   Log:
>   Use alternative is_socket_connected implementation using
>   select with 1 microsecond timeout. It should be both faster and
>   usable on netware too.
>   
>   Revision  Changes    Path
>   1.91      +7 -9      jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c
>   
>   Index: jk_ajp_common.c
>   ===================================================================
>   RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_ajp_common.c,v
>   retrieving revision 1.90
>   retrieving revision 1.91
>   diff -u -r1.90 -r1.91
>   --- jk_ajp_common.c	18 Feb 2005 08:27:21 -0000	1.90
>   +++ jk_ajp_common.c	19 Feb 2005 09:13:35 -0000	1.91
>   @@ -847,10 +847,9 @@
>                if (ae->worker->cache_timeout > 0 || ae->worker->recycle_timeout > 0)
>                    ae->last_access = time(NULL);
>                if (ae->worker->socket_timeout > 0) {
>   -                int rc = 0;
>   -                if ((rc = jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) != 1) {
>   -                        jk_log(l, JK_LOG_INFO,
>   -                            "Socket is not connected any more (status=%d)", rc);
>   +                if (!jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) {
>   +                    jk_log(l, JK_LOG_INFO,
>   +                           "Socket is not connected any more (errno=%d)", errno);
>                        jk_close_socket(ae->sd);
>                        ae->sd = -1;
>                        JK_TRACE_EXIT(l);
>   @@ -1161,10 +1160,9 @@
>        while ((ae->sd > 0)) {
>            err = 0;
>            if (ae->worker->socket_timeout) {
>   -            int rc = 0;
>   -            if ((rc = jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) != 1) {
>   -                    jk_log(l, JK_LOG_INFO,
>   -                           "Socket is not connected any more (status=%d)", rc);
>   +            if (!jk_is_socket_connected(ae->sd, ae->worker->socket_timeout)) {
>   +                jk_log(l, JK_LOG_INFO,
>   +                       "Socket is not connected any more (errno=%d)", errno);
>                    jk_close_socket(ae->sd);
>                    ae->sd = -1;
>                    err++;
>   
>   
>   
>   1.43      +48 -2     jakarta-tomcat-connectors/jk/native/common/jk_connect.c
>   
>   Index: jk_connect.c
>   ===================================================================
>   RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_connect.c,v
>   retrieving revision 1.42
>   retrieving revision 1.43
>   diff -u -r1.42 -r1.43
>   --- jk_connect.c	17 Feb 2005 08:26:42 -0000	1.42
>   +++ jk_connect.c	19 Feb 2005 09:13:35 -0000	1.43
>   @@ -194,18 +194,36 @@
>                       sock_buf);
>        }
>    
>   -#ifdef WIN32
>        if (timeout > 0) {
>   +#ifdef WIN32
>            timeout = timeout * 1000;
>            setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO,
>                       (char *) &timeout, sizeof(int));
>            setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
>                       (char *) &timeout, sizeof(int));
>   +#else
>   +        /* TODO: How to set the timeout for other platforms? */
>   +#endif
>            if (JK_IS_DEBUG_LEVEL(l))
>                jk_log(l, JK_LOG_DEBUG,
>                       "timeout %d set for socket=%d",
>                       timeout, sock);
>        }
>   +#ifdef SO_NOSIGPIPE
>   +    /* The preferred method on Mac OS X (10.2 and later) to prevent SIGPIPEs when
>   +     * sending data to a dead peer. Possibly also existing and in use on other BSD
>   +     * systems?
>   +    */
>   +    set = 1;
>   +    if (setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (const char *)&set,
>   +                   sizeof(int))) {
>   +        JK_GET_SOCKET_ERRNO();
>   +        jk_log(l, JK_LOG_ERROR,
>   +                "failed setting SO_NOSIGPIPE with errno=%d", errno);
>   +        jk_close_socket(sock);
>   +        JK_TRACE_EXIT(l);
>   +        return -1;
>   +    }
>    #endif
>        /* Tries to connect to Tomcat (continues trying while error is EINTR) */
>        do {
>   @@ -405,6 +423,32 @@
>        return 0;
>    }
>    
>   +#if 1
>   +int jk_is_socket_connected(int sd, int timeout)
>   +{
>   +    fd_set fd;
>   +    struct timeval tv;
>   + 
>   +    FD_ZERO(&fd);
>   +    FD_SET(sd, &fd);
>   +
>   +    /* Wait one microsecond */
>   +    tv.tv_sec  = 0;
>   +    tv.tv_usec = 1;
>   +
>   +    /* If we get a timeout, then we are still connected */
>   +    if (select(1, &fd, NULL, NULL, &tv) == 0)
>   +        return 1;
>   +    else {
>   +#if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
>   +        errno = WSAGetLastError() - WSABASEERR;
>   +#endif
>   +        return 0;
>   +    }
>   +}
>   +
>   +#else
>   +
>    #if defined(WIN32) || (defined(NETWARE) && defined(__NOVELL_LIBC__))
>    #define EWOULDBLOCK (WSAEWOULDBLOCK - WSABASEERR)
>    #endif
>   @@ -434,3 +478,5 @@
>        else
>            return rc;
>    }
>   +
>   +#endif
>   
>   
>   
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 
> .
> 


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


Re: cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

Posted by NormW <no...@bocnet.com.au>.
Hi again...
Mladen Turk wrote:
> NormW wrote:
> 
>> Good evening,
>> Can confirm a clean build for 2.1 and 2.0.53 Apache. Time is short now 
>> but will test them for basic ops in the morning. I assume these still 
>> need the socket_timeout at zero?
> Well, new is_socket_connected implementation should be available
> for netware too (that was the purpose after all).
> Tell me if it works when you set the socket_timeout to a positive value.
Okay - there is time enough to try in the morning and there will be a 
message shortly thereafter...
> 
> Regards,
> Mladen.
Norm

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


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


Re: cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

Posted by NormW <no...@bocnet.com.au>.
Good morning,
AFAICT this is working fine with a socket timeout of 15. Neither 
/server-info/ or /status/ show the setting in use, but 15 is what's in 
the properties file and /server-info/ says that's the file in use.

Regards,
Norm

Mladen Turk wrote:
> NormW wrote:
> 
>> Good evening,
>> Can confirm a clean build for 2.1 and 2.0.53 Apache. Time is short now 
>> but will test them for basic ops in the morning. I assume these still 
>> need the socket_timeout at zero?
> 
> 
> Well, new is_socket_connected implementation should be available
> for netware too (that was the purpose after all).
> Tell me if it works when you set the socket_timeout to a positive value.
> 
> Regards,
> Mladen.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
> 
> .
> 


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


Re: cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

Posted by Mladen Turk <mt...@apache.org>.
NormW wrote:
> Good evening,
> Can confirm a clean build for 2.1 and 2.0.53 Apache. Time is short now 
> but will test them for basic ops in the morning. I assume these still 
> need the socket_timeout at zero?

Well, new is_socket_connected implementation should be available
for netware too (that was the purpose after all).
Tell me if it works when you set the socket_timeout to a positive value.

Regards,
Mladen.

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


Re: cvs commit: jakarta-tomcat-connectors/jk/native/common jk_ajp_common.c jk_connect.c

Posted by NormW <no...@bocnet.com.au>.
Good evening,
Can confirm a clean build for 2.1 and 2.0.53 Apache. Time is short now 
but will test them for basic ops in the morning. I assume these still 
need the socket_timeout at zero?
Regards,
Norm

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