You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@apache.org on 2003/07/08 14:53:12 UTC

cvs commit: apr/test testsockets.c

trawick     2003/07/08 05:53:12

  Modified:    .        CHANGES
               include/arch/os2 apr_arch_networkio.h
               include/arch/unix apr_arch_networkio.h
               include/arch/win32 apr_arch_networkio.h
               network_io/os2 sockets.c
               network_io/unix sockets.c
               network_io/win32 sockets.c
               test     testsockets.c
  Log:
  apr_socket_data_set(): allow the same key to be used for
  multiple sockets in the same pool.
  
  Revision  Changes    Path
  1.421     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.420
  retrieving revision 1.421
  diff -u -r1.420 -r1.421
  --- CHANGES	22 Jun 2003 21:56:38 -0000	1.420
  +++ CHANGES	8 Jul 2003 12:53:07 -0000	1.421
  @@ -1,4 +1,8 @@
   Changes with APR 0.9.4
  +
  +  *) apr_socket_data_set(): allow the same key to be used for
  +     multiple sockets in the same pool.  [Jeff Trawick]
  +
     *) Add new table function apr_table_compress() and replace
        red-black trees with mergesort in apr_table_overlap()
        [Joe Schaefer <jo...@sunstarsys.com>, Brian Pane]
  
  
  
  1.3       +8 -0      apr/include/arch/os2/apr_arch_networkio.h
  
  Index: apr_arch_networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/apr_arch_networkio.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_arch_networkio.h	7 Jan 2003 00:06:28 -0000	1.2
  +++ apr_arch_networkio.h	8 Jul 2003 12:53:10 -0000	1.3
  @@ -63,6 +63,13 @@
   #include <netdb.h>
   #endif
   
  +typedef struct sock_userdata_t sock_userdata_t;
  +struct sock_userdata_t {
  +    sock_userdata_t *next;
  +    const char *key;
  +    void *data;
  +};
  +
   struct apr_socket_t {
       apr_pool_t *cntxt;
       int socketdes;
  @@ -77,6 +84,7 @@
       int remote_addr_unknown;
       apr_int32_t netmask;
       apr_int32_t inherit;
  +    sock_userdata_t *userdata;
   };
   
   /* Error codes returned from sock_errno() */
  
  
  
  1.2       +8 -0      apr/include/arch/unix/apr_arch_networkio.h
  
  Index: apr_arch_networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/unix/apr_arch_networkio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_arch_networkio.h	6 Jan 2003 23:44:26 -0000	1.1
  +++ apr_arch_networkio.h	8 Jul 2003 12:53:10 -0000	1.2
  @@ -122,6 +122,13 @@
   #define POLLNVAL 32
   #endif
   
  +typedef struct sock_userdata_t sock_userdata_t;
  +struct sock_userdata_t {
  +    sock_userdata_t *next;
  +    const char *key;
  +    void *data;
  +};
  +
   struct apr_socket_t {
       apr_pool_t *cntxt;
       int socketdes;
  @@ -138,6 +145,7 @@
       int remote_addr_unknown;
       apr_int32_t netmask;
       apr_int32_t inherit;
  +    sock_userdata_t *userdata;
   };
   
   const char *apr_inet_ntop(int af, const void *src, char *dst, apr_size_t size);
  
  
  
  1.2       +8 -0      apr/include/arch/win32/apr_arch_networkio.h
  
  Index: apr_arch_networkio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/win32/apr_arch_networkio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_arch_networkio.h	6 Jan 2003 23:44:27 -0000	1.1
  +++ apr_arch_networkio.h	8 Jul 2003 12:53:10 -0000	1.2
  @@ -58,6 +58,13 @@
   #include "apr_network_io.h"
   #include "apr_general.h"
   
  +typedef struct sock_userdata_t sock_userdata_t;
  +struct sock_userdata_t {
  +    sock_userdata_t *next;
  +    const char *key;
  +    void *data;
  +};
  +
   struct apr_socket_t {
       apr_pool_t         *cntxt;
       SOCKET              socketdes;
  @@ -73,6 +80,7 @@
       int                 remote_addr_unknown;
       apr_int32_t         netmask;
       apr_int32_t         inherit;
  +    sock_userdata_t    *userdata;
   };
   
   #ifdef _WIN32_WCE
  
  
  
  1.64      +28 -4     apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sockets.c,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- sockets.c	6 Jan 2003 23:44:34 -0000	1.63
  +++ sockets.c	8 Jul 2003 12:53:10 -0000	1.64
  @@ -58,6 +58,7 @@
   #include "apr_general.h"
   #include "apr_portable.h"
   #include "apr_lib.h"
  +#include "apr_strings.h"
   #include <errno.h>
   #include <string.h>
   #include <sys/socket.h>
  @@ -241,17 +242,40 @@
   
   
   APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
  -                                     apr_socket_t *socket)
  +                                     apr_socket_t *sock)
   {
  -    return apr_pool_userdata_get(data, key, socket->cntxt);
  +    sock_userdata_t *cur = sock->userdata;
  +
  +    *data = NULL;
  +
  +    while (cur) {
  +        if (!strcmp(cur->key, key)) {
  +            *data = cur->data;
  +            break;
  +        }
  +        cur = cur->next;
  +    }
  +
  +    return APR_SUCCESS;
   }
   
   
   
  -APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *socket, void *data, const char *key,
  +APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data, const char *key,
                                        apr_status_t (*cleanup) (void *))
   {
  -    return apr_pool_userdata_set(data, key, cleanup, socket->cntxt);
  +    sock_userdata_t *new = apr_palloc(sock->cntxt, sizeof(sock_userdata_t));
  +
  +    new->key = apr_pstrdup(sock->cntxt, key);
  +    new->data = data;
  +    new->next = sock->userdata;
  +    sock->userdata = new;
  +
  +    if (cleanup) {
  +        apr_pool_cleanup_register(sock->cntxt, data, cleanup, cleanup);
  +    }
  +
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock, apr_socket_t *sock)
  
  
  
  1.110     +27 -3     apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.109
  retrieving revision 1.110
  diff -u -r1.109 -r1.110
  --- sockets.c	30 May 2003 12:50:39 -0000	1.109
  +++ sockets.c	8 Jul 2003 12:53:11 -0000	1.110
  @@ -54,6 +54,7 @@
   
   #include "apr_arch_networkio.h"
   #include "apr_network_io.h"
  +#include "apr_strings.h"
   #include "apr_support.h"
   #include "apr_portable.h"
   #include "apr_arch_inherit.h"
  @@ -318,13 +319,36 @@
   
   apr_status_t apr_socket_data_get(void **data, const char *key, apr_socket_t *sock)
   {
  -    return apr_pool_userdata_get(data, key, sock->cntxt);
  +    sock_userdata_t *cur = sock->userdata;
  +
  +    *data = NULL;
  +
  +    while (cur) {
  +        if (!strcmp(cur->key, key)) {
  +            *data = cur->data;
  +            break;
  +        }
  +        cur = cur->next;
  +    }
  +
  +    return APR_SUCCESS;
   }
   
   apr_status_t apr_socket_data_set(apr_socket_t *sock, void *data, const char *key,
  -                              apr_status_t (*cleanup) (void *))
  +                                 apr_status_t (*cleanup) (void *))
   {
  -    return apr_pool_userdata_set(data, key, cleanup, sock->cntxt);
  +    sock_userdata_t *new = apr_palloc(sock->cntxt, sizeof(sock_userdata_t));
  +
  +    new->key = apr_pstrdup(sock->cntxt, key);
  +    new->data = data;
  +    new->next = sock->userdata;
  +    sock->userdata = new;
  +
  +    if (cleanup) {
  +        apr_pool_cleanup_register(sock->cntxt, data, cleanup, cleanup);
  +    }
  +
  +    return APR_SUCCESS;
   }
   
   apr_status_t apr_os_sock_get(apr_os_sock_t *thesock, apr_socket_t *sock)
  
  
  
  1.96      +28 -4     apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- sockets.c	6 Jan 2003 23:44:36 -0000	1.95
  +++ sockets.c	8 Jul 2003 12:53:12 -0000	1.96
  @@ -57,6 +57,7 @@
   #include "apr_general.h"
   #include "apr_lib.h"
   #include "apr_portable.h"
  +#include "apr_strings.h"
   #include <string.h>
   #include "apr_arch_inherit.h"
   #include "apr_arch_misc.h"
  @@ -403,16 +404,39 @@
   }
   
   APR_DECLARE(apr_status_t) apr_socket_data_get(void **data, const char *key,
  -                                             apr_socket_t *socket)
  +                                             apr_socket_t *sock)
   {
  -    return apr_pool_userdata_get(data, key, socket->cntxt);
  +    sock_userdata_t *cur = sock->userdata;
  +
  +    *data = NULL;
  +
  +    while (cur) {
  +        if (!strcmp(cur->key, key)) {
  +            *data = cur->data;
  +            break;
  +        }
  +        cur = cur->next;
  +    }
  +
  +    return APR_SUCCESS;
   }
   
  -APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *socket, void *data,
  +APR_DECLARE(apr_status_t) apr_socket_data_set(apr_socket_t *sock, void *data,
                                                const char *key,
                                                apr_status_t (*cleanup)(void *))
   {
  -    return apr_pool_userdata_set(data, key, cleanup, socket->cntxt);
  +    sock_userdata_t *new = apr_palloc(sock->cntxt, sizeof(sock_userdata_t));
  +
  +    new->key = apr_pstrdup(sock->cntxt, key);
  +    new->data = data;
  +    new->next = sock->userdata;
  +    sock->userdata = new;
  +
  +    if (cleanup) {
  +        apr_pool_cleanup_register(sock->cntxt, data, cleanup, cleanup);
  +    }
  +
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_os_sock_get(apr_os_sock_t *thesock,
  
  
  
  1.9       +28 -0     apr/test/testsockets.c
  
  Index: testsockets.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testsockets.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- testsockets.c	1 Jan 2003 00:01:56 -0000	1.8
  +++ testsockets.c	8 Jul 2003 12:53:12 -0000	1.9
  @@ -168,6 +168,31 @@
       apr_socket_close(sock2);
   }
   
  +static void socket_userdata(CuTest *tc)
  +{
  +    apr_socket_t *sock1, *sock2;
  +    apr_status_t rv;
  +    char *data;
  +    const char *key = "GENERICKEY";
  +
  +    rv = apr_socket_create(&sock1, AF_INET, SOCK_STREAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_socket_create(&sock2, AF_INET, SOCK_STREAM, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_socket_data_set(sock1, "SOCK1", key, NULL);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    rv = apr_socket_data_set(sock2, "SOCK2", key, NULL);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_socket_data_get((void **)&data, key, sock1);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertStrEquals(tc, "SOCK1", data);
  +    rv = apr_socket_data_get((void **)&data, key, sock2);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertStrEquals(tc, "SOCK2", data);
  +}
  +
   CuSuite *testsockets(void)
   {
       CuSuite *suite = CuSuiteNew("Socket Creation");
  @@ -179,6 +204,9 @@
       SUITE_ADD_TEST(suite, udp6_socket);
   
       SUITE_ADD_TEST(suite, sendto_receivefrom);
  +
  +    SUITE_ADD_TEST(suite, socket_userdata);
  +    
       return suite;
   }