apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/network_io/unix sockets.c sockopt.c
Date Thu, 25 Jan 2001 12:13:37 GMT
dreid       01/01/25 04:13:36

  Modified:    include  apr_network_io.h
               include/arch/os2 networkio.h
               include/arch/unix networkio.h
               include/arch/win32 networkio.h
               network_io/unix sockets.c sockopt.c
  Log:
  Add code to allow APR to track the socket options it has set.  This
  code aims to minimise the number of syscalls required to determine the
  state of a socket.  The next step is to change the os_cork/os_uncork
  code to use basic apr calls and hence make use of this ability.
  
  Revision  Changes    Path
  1.94      +7 -0      apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_network_io.h,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- apr_network_io.h	2001/01/18 20:07:21	1.93
  +++ apr_network_io.h	2001/01/25 12:13:23	1.94
  @@ -95,6 +95,13 @@
   #define APR_SO_RCVBUF        128
   #define APR_SO_DISCONNECTED  256
   #define APR_TCP_NODELAY      512
  +#define APR_TCP_NOPUSH       1024
  +#define APR_RESET_NODELAY    2048 /* This flag is ONLY set internally
  +                                   * when we set APR_TCP_NOPUSH with
  +                                   * APR_TCP_NODELAY set to tell us that
  +                                   * APR_TCP_NODELAY should be truned on
  +                                   * again when NOPUSH is turned off
  +                                   */
   
   #define APR_POLLIN    0x001 
   #define APR_POLLPRI   0x002
  
  
  
  1.17      +1 -0      apr/include/arch/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/networkio.h,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- networkio.h	2000/11/16 18:43:18	1.16
  +++ networkio.h	2001/01/25 12:13:27	1.17
  @@ -72,6 +72,7 @@
       int nonblock;
       int local_port_unknown;
       int local_interface_unknown;
  +    apr_int32_t netmask;
   };
   
   struct apr_pollfd_t {
  
  
  
  1.36      +1 -0      apr/include/arch/unix/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/networkio.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- networkio.h	2000/11/16 14:48:50	1.35
  +++ networkio.h	2001/01/25 12:13:29	1.36
  @@ -130,6 +130,7 @@
   #endif
       int local_port_unknown;
       int local_interface_unknown;
  +    apr_int32_t netmask;
   };
   
   struct apr_pollfd_t {
  
  
  
  1.16      +1 -0      apr/include/arch/win32/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/win32/networkio.h,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- networkio.h	2000/11/16 17:31:24	1.15
  +++ networkio.h	2001/01/25 12:13:31	1.16
  @@ -67,6 +67,7 @@
       apr_int32_t disconnected;
       int local_port_unknown;
       int local_interface_unknown;
  +    apr_int32_t netmask;
   };
   
   struct apr_pollfd_t {
  
  
  
  1.69      +7 -0      apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- sockets.c	2001/01/01 00:09:18	1.68
  +++ sockets.c	2001/01/25 12:13:33	1.69
  @@ -101,6 +101,13 @@
           sock->remote_addr->ipaddr_len = sizeof(struct in6_addr);
       }
   #endif
  +    sock->netmask = 0;
  +#if defined(BEOS) && !defined(BEOS_BONE)
  +    /* BeOS pre-BONE has TCP_NODELAY on by default and it can't be
  +     * switched off!
  +     */
  +    sock->netmask |= APR_TCP_NODELAY;
  +#endif
   }                                                                                     
            
   static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
   {
  
  
  
  1.41      +115 -34   apr/network_io/unix/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockopt.c,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- sockopt.c	2000/12/18 17:00:42	1.40
  +++ sockopt.c	2001/01/25 12:13:34	1.41
  @@ -55,6 +55,19 @@
   #include "networkio.h"
   #include "apr_strings.h"
   
  +static int is_option_set(apr_int32_t mask, apr_int32_t option)
  +{
  +    return (mask & option) == option;
  +}
  +
  +static void set_option(apr_int32_t *mask, apr_int32_t option, int on)
  +{
  +    if (on)
  +        *mask |= option;
  +    else
  +        *mask &= ~option;
  +}
  +
   static apr_status_t soblock(int sd)
   {
   /* BeOS uses setsockopt at present for non blocking... */
  @@ -121,49 +134,67 @@
           one = 0;
       if (opt & APR_SO_KEEPALIVE) {
   #ifdef SO_KEEPALIVE
  -        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_KEEPALIVE, (void *)&one,
sizeof(int)) == -1) {
  -            return errno;
  +        if (on != is_option_set(sock->netmask, APR_SO_KEEPALIVE)){
  +            if (setsockopt(sock->socketdes, SOL_SOCKET, SO_KEEPALIVE, (void *)&one,
sizeof(int)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask,APR_SO_KEEPALIVE, on);
           }
   #else
           return APR_ENOTIMPL;
   #endif
       }
       if (opt & APR_SO_DEBUG) {
  -        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int))
== -1) {
  -            return errno;
  +        if (on != is_option_set(sock->netmask, APR_SO_DEBUG)){
  +            if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (void *)&one,
sizeof(int)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_SO_DEBUG, on);
           }
       }
       if (opt & APR_SO_REUSEADDR) {
  -        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
sizeof(int)) == -1) {
  -            return errno;
  +        if (on != is_option_set(sock->netmask, APR_SO_REUSEADDR)){
  +            if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (void *)&one,
sizeof(int)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_SO_REUSEADDR, on);
           }
       }
       if (opt & APR_SO_SNDBUF) {
   #ifdef SO_SNDBUF
  -        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_SNDBUF, (void *)&on, sizeof(int))
== -1) {
  -            return errno;
  +        if (is_option_set(sock->netmask, APR_SO_SNDBUF) != on){
  +            if (setsockopt(sock->socketdes, SOL_SOCKET, SO_SNDBUF, (void *)&on,
sizeof(int)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_SO_SNDBUF, on);
           }
   #else
           return APR_ENOTIMPL;
   #endif
       }
       if (opt & APR_SO_NONBLOCK) {
  -        if (on) {
  -            if ((stat = sononblock(sock->socketdes)) != APR_SUCCESS) 
  -                return stat;
  -        }
  -        else {
  -            if ((stat = soblock(sock->socketdes)) != APR_SUCCESS)
  -                return stat;
  +        if (is_option_set(sock->netmask, APR_SO_NONBLOCK) != on){
  +            if (on) {
  +                if ((stat = sononblock(sock->socketdes)) != APR_SUCCESS) 
  +                    return stat;
  +            }
  +            else {
  +                if ((stat = soblock(sock->socketdes)) != APR_SUCCESS)
  +                    return stat;
  +            }
  +            set_option(&sock->netmask, APR_SO_NONBLOCK, on);
           }
       }
       if (opt & APR_SO_LINGER) {
   #ifdef SO_LINGER
  -        struct linger li;
  -        li.l_onoff = on;
  -        li.l_linger = MAX_SECS_TO_LINGER;
  -        if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct
linger)) == -1) {
  -            return errno;
  +        if (is_option_set(sock->netmask, APR_SO_LINGER) != on){
  +            struct linger li;
  +            li.l_onoff = on;
  +            li.l_linger = MAX_SECS_TO_LINGER;
  +            if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li,
sizeof(struct linger)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_SO_LINGER, on);
           }
   #else
           return APR_ENOTIMPL;
  @@ -171,20 +202,30 @@
       }
       if (opt & APR_SO_TIMEOUT) { 
           /* don't do the fcntl foo more than needed */ 
  -        if (on >= 0 && sock->timeout < 0 
  -                && (stat = sononblock(sock->socketdes)) != APR_SUCCESS) { 
  -            return stat; 
  +        if (on >= 0 && sock->timeout < 0){
  +            if (is_option_set(sock->netmask, APR_SO_NONBLOCK) != 1){
  +                if ((stat = sononblock(sock->socketdes)) != APR_SUCCESS){
  +                    return stat;
  +                }
  +            }
           } 
  -        else if (on < 0 && sock->timeout >= 0 
  -                && (stat = soblock(sock->socketdes)) != APR_SUCCESS) { 
  -            return stat; 
  -        } 
  +        else if (on < 0 && sock->timeout >= 0){
  +            if (is_option_set(sock->netmask, APR_SO_NONBLOCK) != 0){ 
  +                if ((stat = soblock(sock->socketdes)) != APR_SUCCESS) { 
  +                    return stat; 
  +                }
  +            } 
  +        }
           sock->timeout = on; 
  +        set_option(&sock->netmask, APR_SO_TIMEOUT, on);
       } 
       if (opt & APR_TCP_NODELAY) {
   #if defined(TCP_NODELAY)
  -        if (setsockopt(sock->socketdes, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(int))
== -1) {
  -            return errno;
  +        if (is_option_set(sock->netmask, APR_TCP_NODELAY) != on){
  +            if (setsockopt(sock->socketdes, IPPROTO_TCP, TCP_NODELAY, (void *)&on,
sizeof(int)) == -1) {
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_TCP_NODELAY, on);
           }
   #else
           /* BeOS pre-BONE has TCP_NODELAY set by default.
  @@ -199,17 +240,57 @@
           return APR_ENOTIMPL;
   #endif
       }
  +    if (opt & APR_TCP_NOPUSH){
  +#if APR_TCP_NOPUSH_FLAG
  +        if (is_option_set(sock->netmask, APR_TCP_NOPUSH) != on){
  +            /* OK we're going to change some settings here... */
  +            /* TCP_NODELAY is mutually exclusive, so do we have it set? */
  +            if (is_option_set(sock->netmask, APR_TCP_NODELAY) == 1 && on){
  +                /* If we want to set NOPUSH then if we have the TCP_NODELAY
  +                 * flag set we need to switch it off...
  +                 */
  +                int tmpflag = 1;
  +                if (setsockopt(sock->socketdes, IPPROTO_TCP, TCP_NODELAY,
  +                               (void*)&tmpflag, sizeof(int)) == -1){
  +                    return errno;
  +                }
  +                set_option(&sock->netmask, APR_RESET_NODELAY, 1);
  +                set_option(&sock->netmask, APR_TCP_NODELAY, 0);
  +            } else if (on){
  +                set_option(&sock->netmask, APR_RESET_NODELAY, 0);
  +            }
  +            /* OK, now we can just set the TCP_NOPUSH flag accordingly...*/
  +            if (setsockopt(sock->socketdes, IPPROTO_TCP, APR_TCP_NOPUSH_FLAG,
  +                           (void*)&on, sizeof(int)) == -1){
  +                return errno;
  +            }
  +            set_option(&sock->netmask, APR_TCP_NOPUSH, on);
  +            if (!on && is_option_set(sock->netmask, APR_RESET_NODELAY)){
  +                int tmpflag = 1;
  +                if (setsockopt(sock->socketdes, IPPROTO_TCP, TCP_NODELAY,
  +                               (void*)&tmpflag, sizeof(int)) == -1){
  +                    return errno;
  +                }
  +                set_option(&sock->netmask, APR_RESET_NODELAY,0);
  +                set_option(&sock->netmask, APR_TCP_NODELAY, 1);
  +            }
  +        }
  +#else
  +        return APR_ENOTIMPL;
  +#endif
  +    }
  +
       return APR_SUCCESS; 
   }         
   
   apr_status_t apr_getsocketopt(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
   {
       switch(opt) {
  -    case APR_SO_TIMEOUT:
  -        *on = sock->timeout;
  -        break;
  -    default:
  -        return APR_EINVAL;
  +        case APR_SO_TIMEOUT:
  +            *on = sock->timeout;
  +            break;
  +        default:
  +            *on = is_option_set(sock->netmask, opt);
       }
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message