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

cvs commit: apr/poll/unix poll.c pollacc.c

brianp      2002/08/06 17:06:12

  Modified:    poll/unix poll.c pollacc.c
  Log:
  Changed apr_poll_socket_remove() and apr_poll() to avoid
  putting invalid descriptors on the pollset after removing
  from the middle of the array
  Reported by: Rob Saccoccio <ro...@fastcgi.com>
  
  Revision  Changes    Path
  1.28      +9 -1      apr/poll/unix/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apr/poll/unix/poll.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- poll.c	6 Aug 2002 03:37:54 -0000	1.27
  +++ poll.c	7 Aug 2002 00:06:12 -0000	1.28
  @@ -151,6 +151,10 @@
           else if (aprset[i].desc_type == APR_POLL_FILE) {
               pollset[i].fd = aprset[i].desc.f->filedes;
           }
  +        else if (aprset[i].desc_type == APR_NO_DESC) {
  +            num = i + 1;
  +            break;
  +        }
           pollset[i].events = get_event(aprset[i].reqevents);
       }
   
  @@ -221,7 +225,7 @@
   #endif
               fd = aprset[i].desc.s->socketdes;
           }
  -        else {
  +        else if (aprset[i].desc_type == APR_POLL_FILE) {
   #if !APR_FILES_AS_SOCKETS
               return APR_EBADF;
   #else
  @@ -236,6 +240,10 @@
               fd = aprset[i].desc.f->filedes;
   
   #endif /* APR_FILES_AS_SOCKETS */
  +        }
  +        else if (aprset[i].desc_type == APR_NO_DESC) {
  +            num = i + 1;
  +            break;
           }
           if (aprset[i].reqevents & APR_POLLIN) {
               FD_SET(fd, &readset);
  
  
  
  1.3       +19 -2     apr/poll/unix/pollacc.c
  
  Index: pollacc.c
  ===================================================================
  RCS file: /home/cvs/apr/poll/unix/pollacc.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- pollacc.c	16 Jul 2002 05:25:44 -0000	1.2
  +++ pollacc.c	7 Aug 2002 00:06:12 -0000	1.3
  @@ -134,11 +134,28 @@
   
   APR_DECLARE(apr_status_t) apr_poll_socket_remove(apr_pollfd_t *aprset, apr_socket_t *sock)
   {
  -    apr_pollfd_t *curr = find_poll_sock(aprset, sock);
  -    if (curr == NULL) {
  +    apr_pollfd_t *match = NULL;
  +    apr_pollfd_t *curr;
  +
  +    for (curr = aprset; (curr->desc_type != APR_POLL_LASTDESC) &&
  +             (curr->desc_type != APR_NO_DESC); curr++) {
  +        if (curr->desc.s == sock) {
  +            match = curr;
  +        }
  +    }
  +    if (match == NULL) {
           return APR_NOTFOUND;
       }
   
  +    /* Remove this entry by swapping the last entry into its place.
  +     * This ensures that the non-APR_NO_DESC entries are all at the
  +     * start of the array, so that apr_poll() doesn't have to worry
  +     * about invalid entries in the middle of the pollset.
  +     */
  +    curr--;
  +    if (curr != match) {
  +        *match = *curr;
  +    }
       curr->desc_type = APR_NO_DESC;
   
       return APR_SUCCESS;