apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr/poll/unix poll.c
Date Wed, 31 Jul 2002 01:12:43 GMT
brianp      2002/07/30 18:12:43

  Modified:    poll/unix poll.c
  Log:
  Use storage on the stack instead of apr_palloc in apr_poll()
  when the number of descriptors is small
  
  (Note: The poll API still needs a rewrite in order to be
  usable with large numbers of descriptors.  This change is
  just a short-term hack to work around the memory leak that
  apr_poll() was causing in the httpd.)
  
  Revision  Changes    Path
  1.9       +18 -6     apr/poll/unix/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apr/poll/unix/poll.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- poll.c	16 Jul 2002 20:27:43 -0000	1.8
  +++ poll.c	31 Jul 2002 01:12:43 -0000	1.9
  @@ -106,17 +106,29 @@
       return rv;
   }        
   
  +#define SMALL_POLLSET_LIMIT  8
  +
   APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t num,
                         apr_int32_t *nsds, apr_interval_time_t timeout)
   {
  -    /* obvious optimization, it would be better if this could be allocated
  -     * on the stack.  For a single file/socket, this can be otpimized
  -     * very cleanly.
  -     */
  -    struct pollfd *pollset = apr_palloc(aprset->p,
  -                                        sizeof(struct pollfd) * num);
  +    struct pollfd tmp_pollset[SMALL_POLLSET_LIMIT];
  +    struct pollfd *pollset;
       int i;
   
  +    if (num <= SMALL_POLLSET_LIMIT) {
  +        pollset = tmp_pollset;
  +    }
  +    else {
  +        /* XXX There are two problems with this code: it leaks
  +         * memory, and it requires an O(n)-time loop to copy
  +         * n descriptors from the apr_pollfd_t structs into
  +         * the pollfd structs.  At the moment, it's best suited
  +         * for use with fewer than SMALL_POLLSET_LIMIT
  +         * descriptors.
  +         */
  +        pollset = apr_palloc(aprset->p,
  +                             sizeof(struct pollfd) * num);
  +    }
       for (i = 0; i < num; i++) {
           if (aprset[i].desc_type == APR_POLL_SOCKET) {
               pollset[i].fd = aprset[i].desc.s->socketdes;
  
  
  

Mime
View raw message