You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@locus.apache.org on 2000/11/16 03:17:30 UTC

cvs commit: apache-2.0/src/lib/apr/network_io/os2 sockets.c sockopt.c

trawick     00/11/15 18:17:29

  Modified:    src/lib/apr/include/arch/os2 networkio.h
               src/lib/apr/network_io/os2 sockets.c sockopt.c
  Log:
  port initial set of David Reid's IPv6 support to OS/2
  (not compiled, not tested)
  
  Revision  Changes    Path
  1.15      +2 -3      apache-2.0/src/lib/apr/include/arch/os2/networkio.h
  
  Index: networkio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/arch/os2/networkio.h,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- networkio.h	2000/11/14 06:40:04	1.14
  +++ networkio.h	2000/11/16 02:17:29	1.15
  @@ -66,9 +66,8 @@
   struct apr_socket_t {
       apr_pool_t *cntxt;
       int socketdes;
  -    struct sockaddr_in *local_addr;
  -    struct sockaddr_in *remote_addr;
  -    int addr_len;
  +    apr_sockaddr_t *local_addr;
  +    apr_sockaddr_t *remote_addr;
       apr_interval_time_t timeout;
       int nonblock;
       int local_port_unknown;
  
  
  
  1.29      +60 -30    apache-2.0/src/lib/apr/network_io/os2/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockets.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- sockets.c	2000/11/14 14:08:38	1.28
  +++ sockets.c	2000/11/16 02:17:29	1.29
  @@ -83,33 +83,63 @@
       }
   }
   
  +static void set_socket_vars(apr_socket_t *sock, int family)
  +{
  +    sock->local_addr->sa.sin.sin_family = family;
  +    sock->remote_addr->sa.sin.sin_family = family;
  +
  +    if (family == AF_INET) {
  +        sock->local_addr->sa_len = sizeof(struct sockaddr_in);
  +        sock->local_addr->addr_str_len = 16;
  +        sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin.sin_addr);
  +        sock->local_addr->ipaddr_len = sizeof(struct in_addr);
  +
  +        sock->remote_addr->sa_len = sizeof(struct sockaddr_in);
  +        sock->remote_addr->addr_str_len = 16;
  +        sock->remote_addr->ipaddr_ptr = &(sock->remote_addr->sa.sin.sin_addr);
  +        sock->remote_addr->ipaddr_len = sizeof(struct in_addr);
  +    }
  +#if APR_HAVE_IPV6
  +    else if (family == AF_INET6) {
  +        sock->local_addr->sa_len = sizeof(struct sockaddr_in6);
  +        sock->local_addr->addr_str_len = 46;
  +        sock->local_addr->ipaddr_ptr = &(sock->local_addr->sa.sin6.sin6_addr);
  +        sock->local_addr->ipaddr_len = sizeof(struct in6_addr);
  +
  +        sock->remote_addr->sa_len = sizeof(struct sockaddr_in6);
  +        sock->remote_addr->addr_str_len = 46;
  +        sock->remote_addr->ipaddr_ptr = &(sock->remote_addr->sa.sin6.sin6_addr);
  +        sock->remote_addr->ipaddr_len = sizeof(struct in6_addr);
  +    }
  +#endif
  +}                                                                                                  
  +static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
  +{
  +    *new = (apr_socket_t *)apr_pcalloc(p, sizeof(apr_socket_t));
  +    (*new)->cntxt = p;
  +    (*new)->local_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                       sizeof(apr_sockaddr_t));
  +    (*new)->remote_addr = (apr_sockaddr_t *)apr_pcalloc((*new)->cntxt,
  +                                                        sizeof(apr_sockaddr_t));
  +}
  +
   apr_status_t apr_create_tcp_socket(apr_socket_t **new, apr_pool_t *cont)
   {
  -    (*new) = (apr_socket_t *)apr_palloc(cont, sizeof(apr_socket_t));
  +    alloc_socket(new, cont);
   
       if ((*new) == NULL) {
           return APR_ENOMEM;
       }
  -    (*new)->cntxt = cont; 
  -    (*new)->local_addr = (struct sockaddr_in *)apr_palloc((*new)->cntxt,
  -                         sizeof(struct sockaddr_in));
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_palloc((*new)->cntxt,
  -                         sizeof(struct sockaddr_in));
  -
       if ((*new)->local_addr == NULL || (*new)->remote_addr == NULL) {
           return APR_ENOMEM;
       }
    
       (*new)->socketdes = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  -
  -    (*new)->local_addr->sin_family = AF_INET;
  -    (*new)->remote_addr->sin_family = AF_INET;
  -
  -    (*new)->addr_len = sizeof(*(*new)->local_addr);
  -    
       if ((*new)->socketdes < 0) {
           return APR_OS2_STATUS(sock_errno());
       }
  +    set_socket_vars(*new, AF_INET);
  +
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
       apr_register_cleanup((*new)->cntxt, (void *)(*new), 
  @@ -138,7 +168,9 @@
   
   apr_status_t apr_bind(apr_socket_t *sock)
   {
  -    if (bind(sock->socketdes, (struct sockaddr *)sock->local_addr, sock->addr_len) == -1)
  +    if (bind(sock->socketdes, 
  +             (struct sockaddr *)sock->local_addr->sa, 
  +             sock->local_addr->sa_len) == -1)
           return APR_OS2_STATUS(sock_errno());
       else
           return APR_SUCCESS;
  @@ -154,19 +186,15 @@
   
   apr_status_t apr_accept(apr_socket_t **new, apr_socket_t *sock, apr_pool_t *connection_context)
   {
  -    (*new) = (apr_socket_t *)apr_palloc(connection_context, 
  -                            sizeof(apr_socket_t));
  +    alloc_socket(new, connection_context);
  +    set_socket_vars(*new, sock->local_addr->sa.sin.sin_family);
   
  -    (*new)->cntxt = connection_context;
  -    (*new)->remote_addr = (struct sockaddr_in *)apr_palloc((*new)->cntxt,
  -                          sizeof(struct sockaddr_in));
  -    (*new)->local_addr = sock->local_addr;
  -    (*new)->addr_len = sizeof(struct sockaddr_in);
       (*new)->timeout = -1;
       (*new)->nonblock = FALSE;
   
  -    (*new)->socketdes = accept(sock->socketdes, (struct sockaddr *)(*new)->remote_addr,
  -                        &(*new)->addr_len);
  +    (*new)->socketdes = accept(sock->socketdes, 
  +                               (struct sockaddr *)&(*new)->remote_addr->sa,
  +                               &(*new)->remote_addr->sa_len);
   
       if ((*new)->socketdes < 0) {
           return APR_OS2_STATUS(sock_errno());
  @@ -194,17 +222,19 @@
               return h_errno;
           }
       
  -        memcpy((char *)&sock->remote_addr->sin_addr, hp->h_addr_list[0], hp->h_length);
  -        sock->addr_len = sizeof(*sock->remote_addr);
  +        memcpy((char *)&sock->remote_addr->sa.sin.sin_addr, hp->h_addr_list[0], 
  +               hp->h_length);
       }
   
  -    if ((connect(sock->socketdes, (struct sockaddr *)sock->remote_addr, sock->addr_len) < 0) &&
  +    if ((connect(sock->socketdes, (struct sockaddr *)&sock->remote_addr->sa.sin, 
  +                 sock->remote_addr->sa_len) < 0) &&
           (sock_errno() != SOCEINPROGRESS)) {
           return APR_OS2_STATUS(sock_errno());
       }
       else {
  -        int namelen = sizeof(*sock->local_addr);
  -        getsockname(sock->socketdes, (struct sockaddr *)sock->local_addr, &namelen);
  +        int namelen = sizeof(sock->local_addr->sa.sin);
  +        getsockname(sock->socketdes, (struct sockaddr *)&sock->local_addr->sa.sin, 
  +                    &namelen);
           return APR_SUCCESS;
       }
   }
  @@ -239,8 +269,8 @@
           return APR_ENOPOOL;
       }
       if ((*sock) == NULL) {
  -        (*sock) = (apr_socket_t *)apr_palloc(cont, sizeof(apr_socket_t));
  -        (*sock)->cntxt = cont;
  +        alloc_socket(sock, cont);
  +        set_socket_vars(*sock, AF_INET);
       }
       (*sock)->socketdes = *thesock;
       return APR_SUCCESS;
  
  
  
  1.19      +2 -2      apache-2.0/src/lib/apr/network_io/os2/sockopt.c
  
  Index: sockopt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/os2/sockopt.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- sockopt.c	2000/11/14 14:31:40	1.18
  +++ sockopt.c	2000/11/16 02:17:29	1.19
  @@ -154,9 +154,9 @@
       apr_in_addr_t sa_ptr;
   
       if (which == APR_LOCAL)
  -        sa_ptr = sock->local_addr->sin_addr;
  +        sa_ptr = sock->local_addr->sa.sin.sin_addr;
       else if (which == APR_REMOTE)
  -        sa_ptr = sock->remote_addr->sin_addr;
  +        sa_ptr = sock->remote_addr->sa.sin.sin_addr;
       else
           return APR_EINVAL;
   
  
  
  

Re: cvs commit: apache-2.0/src/lib/apr/network_io/os2 sockets.csockopt.c

Posted by David Reid <dr...@jetnet.co.uk>.
I've started doing that with sa_common.c...

The biggest area seems to be the returning of error codes between unix/win32
so maybe we can do something about that and then have a common set of
files...

david

----- Original Message -----
From: <rb...@covalent.net>
To: <ne...@apache.org>
Sent: Thursday, November 16, 2000 4:57 AM
Subject: Re: cvs commit: apache-2.0/src/lib/apr/network_io/os2
sockets.csockopt.c


>
> > Heck, most of sockets.c is the same, but there are sprinkles of
> > platform detail here and there.  This could be shared to a much
> > greater extent but folks would have to be willing to put up with a bit
> > of conditional compilation and some macros (like getting the
> > OS-specific error code) to make it work.
> >
> > Right now it can be a pain to work in that package because there is
> > enough sharing that changing apr_socket_t much affects all four
> > platforms but not enough sharing to minimize the risks of breaking one
> > of the platforms when you play with it.
>
> The general rule for combining code in APR has been that if more than half
> the file is common, then the file should be common.  I would prefer to
> start by really comparing how much of the code is common and how much is
> going to require code like:
>
> #if UNIX
> ...
> #elif BEOS
> ...
> #elif OS2
> ...
> #endif
>
> The other option is to start to combine functions one function at a time,
> and just leave the non-common code in the separate files.
>
> Ryan
>
>
____________________________________________________________________________
___
> Ryan Bloom                        rbb@apache.org
> 406 29th St.
> San Francisco, CA 94131
> --------------------------------------------------------------------------
-----
>
>


Re: cvs commit: apache-2.0/src/lib/apr/network_io/os2 sockets.c sockopt.c

Posted by rb...@covalent.net.
> Heck, most of sockets.c is the same, but there are sprinkles of
> platform detail here and there.  This could be shared to a much
> greater extent but folks would have to be willing to put up with a bit
> of conditional compilation and some macros (like getting the
> OS-specific error code) to make it work.
> 
> Right now it can be a pain to work in that package because there is
> enough sharing that changing apr_socket_t much affects all four
> platforms but not enough sharing to minimize the risks of breaking one
> of the platforms when you play with it.

The general rule for combining code in APR has been that if more than half
the file is common, then the file should be common.  I would prefer to
start by really comparing how much of the code is common and how much is
going to require code like:

#if UNIX
...
#elif BEOS
...
#elif OS2
...
#endif

The other option is to start to combine functions one function at a time,
and just leave the non-common code in the separate files.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: cvs commit: apache-2.0/src/lib/apr/network_io/os2 sockets.c sockopt.c

Posted by Jeff Trawick <tr...@bellsouth.net>.
Greg Stein <gs...@lyra.org> writes:

> >   +static void set_socket_vars(apr_socket_t *sock, int family)
> >...
> >   +static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
> >...
> 
> Can some of this be shared? It looks exactly like the unix version.

That is possibly useful, but I think the similaries between a lot more
code in the network package warrant looking at the broader picture to
see how to combine code more.

Heck, most of sockets.c is the same, but there are sprinkles of
platform detail here and there.  This could be shared to a much
greater extent but folks would have to be willing to put up with a bit
of conditional compilation and some macros (like getting the
OS-specific error code) to make it work.

Right now it can be a pain to work in that package because there is
enough sharing that changing apr_socket_t much affects all four
platforms but not enough sharing to minimize the risks of breaking one
of the platforms when you play with it.

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Re: cvs commit: apache-2.0/src/lib/apr/network_io/os2 sockets.c sockopt.c

Posted by Greg Stein <gs...@lyra.org>.
On Thu, Nov 16, 2000 at 02:17:30AM -0000, trawick@locus.apache.org wrote:
> trawick     00/11/15 18:17:29
> 
>   Modified:    src/lib/apr/include/arch/os2 networkio.h
>                src/lib/apr/network_io/os2 sockets.c sockopt.c
>   Log:
>   port initial set of David Reid's IPv6 support to OS/2
>   (not compiled, not tested)
>...
>   +static void set_socket_vars(apr_socket_t *sock, int family)
>...
>   +static void alloc_socket(apr_socket_t **new, apr_pool_t *p)
>...

Can some of this be shared? It looks exactly like the unix version.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/