You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bn...@apache.org on 2002/01/04 18:25:49 UTC

cvs commit: apr/network_io/win32 sockets.c

bnicholes    02/01/04 09:25:49

  Modified:    network_io/win32 sockets.c
  Log:
  Deferred the memory allocation for the new apr_socket_t until after the accept()
  call so that we don't chew up huge chunks of memory when using non-blocking
  sockets and also avoiding unnecessary memory allocations on error conditions.
  
  Revision  Changes    Path
  1.69      +13 -7     apr/network_io/win32/sockets.c
  
  Index: sockets.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
  retrieving revision 1.68
  retrieving revision 1.69
  diff -u -r1.68 -r1.69
  --- sockets.c	7 Dec 2001 23:29:07 -0000	1.68
  +++ sockets.c	4 Jan 2002 17:25:49 -0000	1.69
  @@ -226,20 +226,26 @@
   APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new, apr_socket_t *sock,
                                        apr_pool_t *p)
   {
  +    SOCKET s;
  +    struct sockaddr sa;
  +    int salen = sizeof(sock->remote_addr->sa);
  +
  +    // Don't allocate the memory until after we call accept. This allows
  +    //  us to work with nonblocking sockets.
  +    s = accept(sock->sock, (struct sockaddr *)&sa, &salen);
  +    if (s == INVALID_SOCKET) {
  +        return apr_get_netos_error();
  +    }
  +
       alloc_socket(new, p);
       set_socket_vars(*new, sock->local_addr->sa.sin.sin_family, SOCK_STREAM);
   
       (*new)->timeout = -1;   
       (*new)->disconnected = 0;
   
  +    (*new)->sock = s;
       (*new)->remote_addr->salen = sizeof((*new)->remote_addr->sa);
  -    (*new)->sock = accept(sock->sock, 
  -                          (struct sockaddr *)&(*new)->remote_addr->sa,
  -                          &(*new)->remote_addr->salen);
  -
  -    if ((*new)->sock == INVALID_SOCKET) {
  -        return apr_get_netos_error();
  -    }
  +    memcpy (&(*new)->remote_addr->sa, &sa, salen);
       *(*new)->local_addr = *sock->local_addr;
   
       /* The above assignment just overwrote the pool entry. Setting the local_addr 
  
  
  

Re: cvs commit: apr/network_io/win32 sockets.c

Posted by Jeff Trawick <tr...@attglobal.net>.
Jeff Trawick <tr...@attglobal.net> writes:

> bnicholes@apache.org writes:
> 
> > bnicholes    02/01/04 09:25:49
> > 
> >   Modified:    network_io/win32 sockets.c
> >   Log:
> >   Deferred the memory allocation for the new apr_socket_t until after the accept()
> >   call so that we don't chew up huge chunks of memory when using non-blocking
> >   sockets and also avoiding unnecessary memory allocations on error conditions.
> 
> I wonder:
> 
> . what sort of non-broken program would suffer with the code the way
>   it used to be?
> 
> . isn't there more total work done now on the normal path?

I meant to clarify that I don't intend this as a complaint.  (But I
would prefer to understand these issues before anybody made a similar
change to other, similar code :) )

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

Re: cvs commit: apr/network_io/win32 sockets.c

Posted by Jeff Trawick <tr...@attglobal.net>.
bnicholes@apache.org writes:

> bnicholes    02/01/04 09:25:49
> 
>   Modified:    network_io/win32 sockets.c
>   Log:
>   Deferred the memory allocation for the new apr_socket_t until after the accept()
>   call so that we don't chew up huge chunks of memory when using non-blocking
>   sockets and also avoiding unnecessary memory allocations on error conditions.

I wonder:

. what sort of non-broken program would suffer with the code the way
  it used to be?

. isn't there more total work done now on the normal path?

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

Re: cvs commit: apr/network_io/win32 sockets.c

Posted by Jeff Trawick <tr...@attglobal.net>.
bnicholes@apache.org writes:

> bnicholes    02/01/04 09:25:49
> 
>   Modified:    network_io/win32 sockets.c
>   Log:
>   Deferred the memory allocation for the new apr_socket_t until after the accept()
>   call so that we don't chew up huge chunks of memory when using non-blocking
>   sockets and also avoiding unnecessary memory allocations on error conditions.

I wonder:

. what sort of non-broken program would suffer with the code the way
  it used to be?

. isn't there more total work done now on the normal path?

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

RE: cvs commit: apr/network_io/win32 sockets.c

Posted by Sander Striker <st...@apache.org>.
> -----Original Message-----
> From: bnicholes@apache.org [mailto:bnicholes@apache.org]
> Sent: 04 January 2002 18:26
> To: apr-cvs@apache.org
> Subject: cvs commit: apr/network_io/win32 sockets.c
> 
> 
> bnicholes    02/01/04 09:25:49
> 
>   Modified:    network_io/win32 sockets.c
>   Log:
>   Deferred the memory allocation for the new apr_socket_t until after the accept()
>   call so that we don't chew up huge chunks of memory when using non-blocking
>   sockets and also avoiding unnecessary memory allocations on error conditions.
>   
>   Revision  Changes    Path
>   1.69      +13 -7     apr/network_io/win32/sockets.c
>   
>   Index: sockets.c
>   ===================================================================
>   RCS file: /home/cvs/apr/network_io/win32/sockets.c,v
>   retrieving revision 1.68
>   retrieving revision 1.69
>   diff -u -r1.68 -r1.69
>   --- sockets.c	7 Dec 2001 23:29:07 -0000	1.68
>   +++ sockets.c	4 Jan 2002 17:25:49 -0000	1.69
>   @@ -226,20 +226,26 @@
>    APR_DECLARE(apr_status_t) apr_accept(apr_socket_t **new, apr_socket_t *sock,
>                                         apr_pool_t *p)
>    {
>   +    SOCKET s;
>   +    struct sockaddr sa;
>   +    int salen = sizeof(sock->remote_addr->sa);
>   +
>   +    // Don't allocate the memory until after we call accept. This allows
>   +    //  us to work with nonblocking sockets.
         ^^

Can we lose the c++ style comments?

Sander 'being a pain in the butt today' Striker