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...@locus.apache.org on 2000/12/04 17:09:35 UTC

cvs commit: apr/network_io/win32 sockets.c

trawick     00/12/04 08:09:34

  Modified:    .        CHANGES aprlib.def
               include  apr_portable.h
               network_io/os2 sockets.c
               network_io/unix sockets.c
               network_io/win32 sockets.c
  Log:
  Add apr_make_os_sock() for constructing a fully-capable APR
  socket.
  
  The BeOS sockets.c doesn't look up-to-date and I think David
  is(has) switching(switched) to using the Unix sockets.c.  Thus,
  I have not messed with it.
  
  Revision  Changes    Path
  1.14      +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CHANGES	2000/12/02 07:08:00	1.13
  +++ CHANGES	2000/12/04 16:09:20	1.14
  @@ -1,4 +1,7 @@
   Changes with APR a9
  +  *) Add apr_make_os_sock() for constructing a fully-capable APR
  +     socket.  [Jeff Trawick]
  +
     *) Make APR's shared memory routines always allocate enough memory
        for the requested segment, the MM internal types, and the APR
        internal types.
  
  
  
  1.47      +1 -0      apr/aprlib.def
  
  Index: aprlib.def
  ===================================================================
  RCS file: /home/cvs/apr/aprlib.def,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- aprlib.def	2000/12/01 18:48:45	1.46
  +++ aprlib.def	2000/12/04 16:09:22	1.47
  @@ -75,6 +75,7 @@
   	apr_set_socketdata
   	apr_get_polldata
   	apr_set_polldata
  +	apr_make_os_sock
   	apr_put_os_sock
   	apr_get_os_sock
   	apr_remove_poll_socket
  
  
  
  1.41      +28 -0     apr/include/apr_portable.h
  
  Index: apr_portable.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_portable.h,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- apr_portable.h	2000/11/26 03:00:03	1.40
  +++ apr_portable.h	2000/12/04 16:09:24	1.41
  @@ -185,6 +185,20 @@
   #endif
   
   /**
  + * everything APR needs to know about an active socket to construct
  + * an APR socket from it; currently, this is platform-independent
  + */
  +struct apr_os_sock_info_t {
  +    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. */
  +};
  +
  +typedef struct apr_os_sock_info_t apr_os_sock_info_t;
  +
  +/**
    * convert the file from apr type to os specific type.
    * @param thefile The os specific file we are converting to
    * @param file The apr file to convert.
  @@ -273,6 +287,20 @@
    */
   apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, 
                                apr_pool_t *cont);
  +
  +/**
  + * Create a socket from an existing descriptor and local and remote
  + * socket addresses.
  + * @param apr_sock The new socket that has been set up
  + * @param os_sock_info The os representation of the socket handle and
  + *        other characteristics of the socket
  + * @param cont The pool to use
  + * @tip If you only know the descriptor/handle or if it isn't really
  + *      a true socket, use apr_put_os_sock() instead.
  + */
  +apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, 
  +                              apr_os_sock_info_t *os_sock_info, 
  +                              apr_pool_t *cont);
   
   /**
    * Convert the lock from os specific type to apr type
  
  
  
  1.36      +26 -0     apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/os2/sockets.c,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- sockets.c	2000/11/21 21:33:06	1.35
  +++ sockets.c	2000/12/04 16:09:26	1.36
  @@ -263,7 +263,33 @@
       return APR_SUCCESS;
   }
   
  +apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, 
  +                              apr_os_sock_info_t *os_sock_info, 
  +                              apr_pool_t *cont)
  +{
  +    alloc_socket(apr_sock, cont);
  +    set_socket_vars(*apr_sock, os_sock_info->family);
  +    (*apr_sock)->timeout = -1;
  +    (*apr_sock)->socketdes = *os_sock_info->os_sock;
  +    if (os_sock_info->local) {
  +        memcpy(&(*apr_sock)->local_addr->sa.sin, 
  +               os_sock_info->local, 
  +               (*apr_sock)->local_addr->salen);
  +    }
  +    else {
  +        (*apr_sock)->local_port_unknown = (*apr_sock)->local_interface_unknown = 1;
  +    }
  +    if (os_sock_info->remote) {
  +        memcpy(&(*apr_sock)->remote_addr->sa.sin, 
  +               os_sock_info->remote,
  +               (*apr_sock)->remote_addr->salen);
  +    }
  +        
  +    apr_register_cleanup((*apr_sock)->cntxt, (void *)(*apr_sock), 
  +                        socket_cleanup, apr_null_cleanup);
   
  +    return APR_SUCCESS;
  +}
   
   apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, apr_pool_t *cont)
   {
  
  
  
  1.66      +31 -0     apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/sockets.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- sockets.c	2000/11/21 21:33:07	1.65
  +++ sockets.c	2000/12/04 16:09:29	1.66
  @@ -282,6 +282,37 @@
       return APR_SUCCESS;
   }
   
  +apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, 
  +                              apr_os_sock_info_t *os_sock_info, 
  +                              apr_pool_t *cont)
  +{
  +    alloc_socket(apr_sock, cont);
  +    set_socket_vars(*apr_sock, os_sock_info->family);
  +    (*apr_sock)->timeout = -1;
  +    (*apr_sock)->socketdes = *os_sock_info->os_sock;
  +    if (os_sock_info->local) {
  +        memcpy(&(*apr_sock)->local_addr->sa.sin, 
  +               os_sock_info->local, 
  +               (*apr_sock)->local_addr->salen);
  +    }
  +    else {
  +        (*apr_sock)->local_port_unknown = (*apr_sock)->local_interface_unknown = 1;
  +    }
  +    if (os_sock_info->remote) {
  +#ifndef HAVE_POLL
  +        (*apr_sock)->connected = 1;
  +#endif
  +        memcpy(&(*apr_sock)->remote_addr->sa.sin, 
  +               os_sock_info->remote,
  +               (*apr_sock)->remote_addr->salen);
  +    }
  +        
  +    apr_register_cleanup((*apr_sock)->cntxt, (void *)(*apr_sock), 
  +                        socket_cleanup, apr_null_cleanup);
  +
  +    return APR_SUCCESS;
  +}
  +
   apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, 
                              apr_pool_t *cont)
   {
  
  
  
  1.46      +29 -0     apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- sockets.c	2000/11/21 21:33:08	1.45
  +++ sockets.c	2000/12/04 16:09:32	1.46
  @@ -305,6 +305,35 @@
       return APR_SUCCESS;
   }
   
  +apr_status_t apr_make_os_sock(apr_socket_t **apr_sock, 
  +                              apr_os_sock_info_t *os_sock_info, 
  +                              apr_pool_t *cont)
  +{
  +    alloc_socket(apr_sock, cont);
  +    set_socket_vars(*apr_sock, os_sock_info->family);
  +    (*apr_sock)->timeout = -1;
  +    (*apr_sock)->disconnected = 0;
  +    (*apr_sock)->sock = *os_sock_info->os_sock;
  +    if (os_sock_info->local) {
  +        memcpy(&(*apr_sock)->local_addr->sa.sin, 
  +               os_sock_info->local, 
  +               (*apr_sock)->local_addr->salen);
  +    }
  +    else {
  +        (*apr_sock)->local_port_unknown = (*apr_sock)->local_interface_unknown = 1;
  +    }
  +    if (os_sock_info->remote) {
  +        memcpy(&(*apr_sock)->remote_addr->sa.sin, 
  +               os_sock_info->remote,
  +               (*apr_sock)->remote_addr->salen);
  +    }
  +        
  +    apr_register_cleanup((*apr_sock)->cntxt, (void *)(*apr_sock), 
  +                        socket_cleanup, apr_null_cleanup);
  +
  +    return APR_SUCCESS;
  +}
  +
   apr_status_t apr_put_os_sock(apr_socket_t **sock, apr_os_sock_t *thesock, 
                              apr_pool_t *cont)
   {