apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From traw...@apache.org
Subject cvs commit: apr/test server.c
Date Fri, 18 Oct 2002 12:04:00 GMT
trawick     2002/10/18 05:04:00

  Modified:    .        CHANGES
               include  apr_network_io.h apr_portable.h
               include/arch/os2 networkio.h
               include/arch/unix networkio.h
               include/arch/win32 networkio.h
               network_io/os2 sockets.c
               network_io/unix sockets.c
               network_io/win32 sockets.c
               test     server.c
  Log:
  Add apr_socket_create_ex() to allow protocol to be specified for the
  socket.  With APR 1.0, this function will be removed and apr_socket_create()
  will have the additional parameter.
  
  Submitted by:        Randall Stewart <randall@stewart.chicago.il.us>
  Reviewed/mangled by: Jeff Trawick
  
  Revision  Changes    Path
  1.346     +5 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.345
  retrieving revision 1.346
  diff -u -r1.345 -r1.346
  --- CHANGES	16 Oct 2002 11:47:53 -0000	1.345
  +++ CHANGES	18 Oct 2002 12:03:59 -0000	1.346
  @@ -1,5 +1,10 @@
   Changes with APR 0.9.2
   
  +  *) Add apr_socket_create_ex() to allow protocol to be specified for the
  +     socket.  With APR 1.0, this function will be removed and apr_socket_create()
  +     will have the additional parameter.
  +     [Randall Stewart <randall@stewart.chicago.il.us>]
  +
     *) Fix the detection of INT64_C() when defined in <stdint.h>.
        [Joe Orton <joe@manyfish.co.uk>]
   
  
  
  
  1.130     +33 -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.129
  retrieving revision 1.130
  diff -u -r1.129 -r1.130
  --- apr_network_io.h	11 Oct 2002 20:41:23 -0000	1.129
  +++ apr_network_io.h	18 Oct 2002 12:03:59 -0000	1.130
  @@ -168,6 +168,16 @@
   #endif
   
   /**
  + * @defgroup IP_Proto IP Protocol Definitions for use when creating sockets
  + * @{
  + */
  +#define APR_PROTO_TCP       6
  +#define APR_PROTO_UDP      17
  +#define APR_PROTO_SCTP    132
  +/** @} */
  +
  +
  +/**
    * Enum to tell us if we're interested in remote or local socket
    */
   typedef enum {
  @@ -265,6 +275,7 @@
   
   /**
    * Create a socket.
  + * @remark With APR 1.0, this function will pick up a new protocol parameter.
    * @param new_sock The new socket that has been set up.
    * @param family The address family of the socket (e.g., APR_INET).
    * @param type The type of the socket (e.g., SOCK_STREAM).
  @@ -275,6 +286,20 @@
                                               apr_pool_t *cont);
   
   /**
  + * Create a socket.
  + * @remark With APR 1.0, this function will be removed.
  + * @param new_sock The new socket that has been set up.
  + * @param family The address family of the socket (e.g., APR_INET).
  + * @param type The type of the socket (e.g., SOCK_STREAM).
  + * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
  + * @param cont The pool to use
  + */
  +APR_DECLARE(apr_status_t) apr_socket_create_ex(apr_socket_t **new_sock, 
  +                                               int family, int type,
  +                                               int protocol,
  +                                               apr_pool_t *cont);
  +
  +/**
    * Shutdown either reading, writing, or both sides of a socket.
    * @param thesocket The socket to close 
    * @param how How to shutdown the socket.  One of:
  @@ -728,6 +753,14 @@
   apr_status_t apr_socket_accept_filter(apr_socket_t *sock, char *name,
                                         char *args);
   #endif
  +
  +/**
  + * Return the protocol of the socket.
  + * @param sock The socket to query.
  + * @param protocol The returned protocol (e.g., APR_PROTO_TCP).
  + */
  +APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
  +                                                  int *protocol);
   
   /**
    * Set a socket to be inherited by child processes.
  
  
  
  1.82      +6 -3      apr/include/apr_portable.h
  
  Index: apr_portable.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_portable.h,v
  retrieving revision 1.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- apr_portable.h	3 Oct 2002 17:55:42 -0000	1.81
  +++ apr_portable.h	18 Oct 2002 12:03:59 -0000	1.82
  @@ -201,7 +201,7 @@
   #endif
   
   /**
  - * @typedef apr_os_sock_t
  + * @typedef apr_os_sock_info_t
    * @brief alias for local OS socket
    */
   /**
  @@ -212,8 +212,11 @@
       apr_os_sock_t *os_sock; /**< always required */
       struct sockaddr *local; /**< NULL if not yet bound */
       struct sockaddr *remote; /**< NULL if not connected */
  -    int family;             /**< always required (APR_INET, APR_INET6, etc. */
  -    int type;               /**< always required (SOCK_STREAM, SOCK_DGRAM, etc. */
  +    int family;             /**< always required (APR_INET, APR_INET6, etc.) */
  +    int type;               /**< always required (SOCK_STREAM, SOCK_DGRAM, etc.) */
  +#ifdef APR_ENABLE_FOR_1_0   /**< enable with APR 1.0 */
  +    int protocol;           /**< 0 or actual protocol (APR_PROTO_SCTP, APR_PROTO_TCP,
etc.) */
  +#endif
   };
   
   typedef struct apr_os_sock_info_t apr_os_sock_info_t;
  
  
  
  1.27      +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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- networkio.h	11 Jul 2002 06:28:40 -0000	1.26
  +++ networkio.h	18 Oct 2002 12:03:59 -0000	1.27
  @@ -67,6 +67,7 @@
       apr_pool_t *cntxt;
       int socketdes;
       int type;
  +    int protocol;
       apr_sockaddr_t *local_addr;
       apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout;
  
  
  
  1.55      +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.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- networkio.h	11 Jul 2002 05:19:44 -0000	1.54
  +++ networkio.h	18 Oct 2002 12:03:59 -0000	1.55
  @@ -120,6 +120,7 @@
       apr_pool_t *cntxt;
       int socketdes;
       int type;
  +    int protocol;
       apr_sockaddr_t *local_addr;
       apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout; 
  
  
  
  1.29      +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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- networkio.h	15 Jul 2002 07:26:12 -0000	1.28
  +++ networkio.h	18 Oct 2002 12:03:59 -0000	1.29
  @@ -62,6 +62,7 @@
       apr_pool_t         *cntxt;
       SOCKET              socketdes;
       int                 type; /* SOCK_STREAM, SOCK_DGRAM */
  +    int                 protocol;
       apr_sockaddr_t     *local_addr;
       apr_sockaddr_t     *remote_addr;
       int                 timeout_ms; /* MUST MATCH if timeout > 0 */
  
  
  
  1.57      +26 -9     apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sockets.c,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- sockets.c	30 Jul 2002 13:56:14 -0000	1.56
  +++ sockets.c	18 Oct 2002 12:03:59 -0000	1.57
  @@ -84,9 +84,10 @@
       }
   }
   
  -static void set_socket_vars(apr_socket_t *sock, int family, int type)
  +static void set_socket_vars(apr_socket_t *sock, int family, int type, int protocol)
   {
       sock->type = type;
  +    sock->protocol = protocol;
       apr_sockaddr_vars_set(sock->local_addr, family, 0);
       apr_sockaddr_vars_set(sock->remote_addr, family, 0);
   }
  @@ -103,8 +104,14 @@
       (*new)->remote_addr->pool = p;
   }
   
  -APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int type,
  -                                            apr_pool_t *cont)
  +APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
  +{
  +    *protocol = sock->protocol;
  +    return APR_SUCCESS;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_socket_create_ex(apr_socket_t **new, int family, int type,
  +                                               int protocol, apr_pool_t *cont)
   {
       int downgrade = (family == AF_UNSPEC);
   
  @@ -118,18 +125,18 @@
   
       alloc_socket(new, cont);
   
  -    (*new)->socketdes = socket(family, type, 0);
  +    (*new)->socketdes = socket(family, type, protocol);
   #if APR_HAVE_IPV6
       if ((*new)->socketdes < 0 && downgrade) {
           family = AF_INET;
  -        (*new)->socketdes = socket(family, type, 0);
  +        (*new)->socketdes = socket(family, type, protocol);
       }
   #endif
   
       if ((*new)->socketdes < 0) {
           return APR_OS2_STATUS(sock_errno());
       }
  -    set_socket_vars(*new, family, type);
  +    set_socket_vars(*new, family, type, protocol);
   
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
  @@ -138,6 +145,12 @@
       return APR_SUCCESS;
   } 
   
  +APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family, int type,
  +                                            apr_pool_t *cont)
  +{
  +    return apr_socket_create_ex(new, family, type, 0, cont);
  +}
  +
   APR_DECLARE(apr_status_t) apr_shutdown(apr_socket_t *thesocket, apr_shutdown_how_e how)
   {
       if (shutdown(thesocket->socketdes, how) == 0) {
  @@ -177,7 +190,7 @@
   APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t
*connection_context)
   {
       alloc_socket(new, connection_context);
  -    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM, sock->protocol);
   
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
  @@ -246,7 +259,11 @@
                                              apr_pool_t *cont)
   {
       alloc_socket(apr_sock, cont);
  -    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type);
  +#ifdef APR_ENABLE_FOR_1_0 /* no protocol field yet */
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, 0);
  +#else
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, os_sock_info->protocol);
  +#endif
       (*apr_sock)->timeout = -1;
       (*apr_sock)->socketdes = *os_sock_info->os_sock;
       if (os_sock_info->local) {
  @@ -280,7 +297,7 @@
       }
       if ((*sock) == NULL) {
           alloc_socket(sock, cont);
  -        set_socket_vars(*sock, AF_INET, SOCK_STREAM);
  +        set_socket_vars(*sock, AF_INET, SOCK_STREAM, APR_PROTO_TCP);
           (*sock)->timeout = -1;
       }
   
  
  
  
  1.102     +26 -9     apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.101
  retrieving revision 1.102
  diff -u -r1.101 -r1.102
  --- sockets.c	30 Jul 2002 13:56:14 -0000	1.101
  +++ sockets.c	18 Oct 2002 12:03:59 -0000	1.102
  @@ -77,9 +77,10 @@
       }
   }
   
  -static void set_socket_vars(apr_socket_t *sock, int family, int type)
  +static void set_socket_vars(apr_socket_t *sock, int family, int type, int protocol)
   {
       sock->type = type;
  +    sock->protocol = protocol;
       apr_sockaddr_vars_set(sock->local_addr, family, 0);
       apr_sockaddr_vars_set(sock->remote_addr, family, 0);
       sock->netmask = 0;
  @@ -103,8 +104,14 @@
       (*new)->remote_addr->pool = p;
   }
   
  -apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
  -                               apr_pool_t *cont)
  +apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol)
  +{
  +    *protocol = sock->protocol;
  +    return APR_SUCCESS;
  +}
  +
  +apr_status_t apr_socket_create_ex(apr_socket_t **new, int ofamily, int type,
  +                                  int protocol, apr_pool_t *cont)
   {
       int family = ofamily;
   
  @@ -118,19 +125,19 @@
   
       alloc_socket(new, cont);
   
  -    (*new)->socketdes = socket(family, type, 0);
  +    (*new)->socketdes = socket(family, type, protocol);
   
   #if APR_HAVE_IPV6
       if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
           family = APR_INET;
  -        (*new)->socketdes = socket(family, type, 0);
  +        (*new)->socketdes = socket(family, type, protocol);
       }
   #endif
   
       if ((*new)->socketdes < 0) {
           return errno;
       }
  -    set_socket_vars(*new, family, type);
  +    set_socket_vars(*new, family, type, protocol);
   
       (*new)->timeout = -1;
       (*new)->inherit = 0;
  @@ -139,6 +146,12 @@
       return APR_SUCCESS;
   } 
   
  +apr_status_t apr_socket_create(apr_socket_t **new, int family, int type,
  +                               apr_pool_t *cont)
  +{
  +    return apr_socket_create_ex(new, family, type, 0, cont);
  +}
  +
   apr_status_t apr_shutdown(apr_socket_t *thesocket, apr_shutdown_how_e how)
   {
       return (shutdown(thesocket->socketdes, how) == -1) ? errno : APR_SUCCESS;
  @@ -176,7 +189,7 @@
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
       alloc_socket(new, connection_context);
  -    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM, sock->protocol);
   
   #ifndef HAVE_POLL
       (*new)->connected = 1;
  @@ -322,7 +335,11 @@
                                 apr_pool_t *cont)
   {
       alloc_socket(apr_sock, cont);
  -    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type);
  +#ifdef APR_ENABLE_FOR_1_0 /* no protocol field yet */
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, os_sock_info->protocol);
  +#else
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, 0);
  +#endif
       (*apr_sock)->timeout = -1;
       (*apr_sock)->socketdes = *os_sock_info->os_sock;
       if (os_sock_info->local) {
  @@ -360,7 +377,7 @@
           /* XXX IPv6 figure out the family here! */
           /* XXX figure out the actual socket type here */
           /* *or* just decide that apr_os_sock_put() has to be told the family and type */
  -        set_socket_vars(*sock, APR_INET, SOCK_STREAM);
  +        set_socket_vars(*sock, APR_INET, SOCK_STREAM, APR_PROTO_TCP);
           (*sock)->timeout = -1;
       }
       (*sock)->local_port_unknown = (*sock)->local_interface_unknown = 1;
  
  
  
  1.86      +29 -9     apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.85
  retrieving revision 1.86
  diff -u -r1.85 -r1.86
  --- sockets.c	30 Jul 2002 13:56:17 -0000	1.85
  +++ sockets.c	18 Oct 2002 12:04:00 -0000	1.86
  @@ -76,9 +76,10 @@
       return APR_SUCCESS;
   }
   
  -static void set_socket_vars(apr_socket_t *sock, int family, int type)
  +static void set_socket_vars(apr_socket_t *sock, int family, int type, int protocol)
   {
       sock->type = type;
  +    sock->protocol = protocol;
       apr_sockaddr_vars_set(sock->local_addr, family, 0);
       apr_sockaddr_vars_set(sock->remote_addr, family, 0);
   }                                                                                     
            
  @@ -94,8 +95,16 @@
       (*new)->remote_addr->pool = p;
   }
   
  -APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family,
  -                                            int type, apr_pool_t *cont)
  +APR_DECLARE(apr_status_t) apr_socket_protocol_get(apr_socket_t *sock,
  +                                                  int *protocol)
  +{
  +    *protocol = sock->protocol;
  +    return APR_SUCCESS;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_socket_create_ex(apr_socket_t **new, int family,
  +                                               int type, int protocol, 
  +                                               apr_pool_t *cont)
   {
       int downgrade = (family == AF_UNSPEC);
   
  @@ -112,11 +121,11 @@
       /* For right now, we are not using socket groups.  We may later.
        * No flags to use when creating a socket, so use 0 for that parameter as well.
        */
  -    (*new)->socketdes = socket(family, type, 0);
  +    (*new)->socketdes = socket(family, type, protocol);
   #if APR_HAVE_IPV6
       if ((*new)->socketdes == INVALID_SOCKET && downgrade) {
           family = AF_INET;
  -        (*new)->socketdes = socket(family, type, 0);
  +        (*new)->socketdes = socket(family, type, protocol);
       }
   #endif
   
  @@ -159,7 +168,7 @@
   
   #endif /* def WIN32 */
   
  -    set_socket_vars(*new, family, type);
  +    set_socket_vars(*new, family, type, protocol);
   
       (*new)->timeout = -1;
       (*new)->disconnected = 0;
  @@ -170,6 +179,12 @@
       return APR_SUCCESS;
   } 
   
  +APR_DECLARE(apr_status_t) apr_socket_create(apr_socket_t **new, int family,
  +                                            int type, apr_pool_t *cont)
  +{
  +    return apr_socket_create_ex(new, family, type, protocol, cont);
  +}
  +
   APR_DECLARE(apr_status_t) apr_shutdown(apr_socket_t *thesocket,
                                          apr_shutdown_how_e how)
   {
  @@ -246,7 +261,8 @@
       }
   
       alloc_socket(new, p);
  -    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM, 
  +                    sock->protocol);
   
       (*new)->timeout = -1;   
       (*new)->disconnected = 0;
  @@ -408,7 +424,11 @@
                                              apr_pool_t *cont)
   {
       alloc_socket(apr_sock, cont);
  -    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type);
  +#ifdef APR_ENABLE_FOR_1_0 /* no protocol field yet */
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, 0);
  +#else
  +    set_socket_vars(*apr_sock, os_sock_info->family, os_sock_info->type, os_sock_info->protocol);
  +#endif
       (*apr_sock)->timeout = -1;
       (*apr_sock)->disconnected = 0;
       (*apr_sock)->socketdes = *os_sock_info->os_sock;
  @@ -446,7 +466,7 @@
           alloc_socket(sock, cont);
           /* XXX figure out the actual socket type here */
           /* *or* just decide that apr_os_sock_put() has to be told the family and type */
  -        set_socket_vars(*sock, AF_INET, SOCK_STREAM);
  +        set_socket_vars(*sock, AF_INET, SOCK_STREAM, APR_PROTO_TCP);
           (*sock)->timeout = -1;
           (*sock)->disconnected = 0;
       }
  
  
  
  1.37      +8 -1      apr/test/server.c
  
  Index: server.c
  ===================================================================
  RCS file: /home/cvs/apr/test/server.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- server.c	15 Jul 2002 07:56:13 -0000	1.36
  +++ server.c	18 Oct 2002 12:04:00 -0000	1.37
  @@ -79,6 +79,7 @@
       apr_sockaddr_t *localsa = NULL, *remotesa;
       apr_status_t stat;
       int family = APR_UNSPEC;
  +    int protocol;
       apr_getopt_t *opt;
       const char *optarg;
       char optchar;
  @@ -113,7 +114,7 @@
       }
   
       APR_TEST_SUCCESS(rv, "Creating new socket", 
  -        apr_socket_create(&sock, family, SOCK_STREAM, context))
  +        apr_socket_create_ex(&sock, family, SOCK_STREAM, APR_PROTO_TCP, context))
   
       APR_TEST_SUCCESS(rv, "Setting option APR_SO_NONBLOCK",
           apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1))
  @@ -153,6 +154,12 @@
       APR_TEST_SUCCESS(rv, "Accepting a connection",
           apr_accept(&sock2, sock, context))
   
  +    apr_socket_protocol_get(sock2, &protocol);
  +    if (protocol != APR_PROTO_TCP) {
  +        fprintf(stderr, "Error: protocol not conveyed from listening socket "
  +                "to connected socket!\n");
  +        exit(1);
  +    }
       apr_socket_addr_get(&remotesa, APR_REMOTE, sock2);
       apr_sockaddr_ip_get(&remote_ipaddr, remotesa);
       apr_sockaddr_port_get(&remote_port, remotesa);
  
  
  

Mime
View raw message