manoj       99/06/28 17:18:04

  Modified:    pthreads/src/include httpd.h
               pthreads/src/main http_accept.c
  Log:
  Change the workings of get_connection in USE_MULTI_ACCEPT mode to search
  the pollfd array rather than the listener linked list. The code is a bit
  easier to follow with this change (our fingers are muddling with fewer
  data structures at once), but the main benefit is for the MPM based on
  this code.
  
  Revision  Changes    Path
  1.18      +0 -1      apache-apr/pthreads/src/include/httpd.h
  
  Index: httpd.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/include/httpd.h,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -d -u -r1.17 -r1.18
  --- httpd.h   1999/06/10 06:25:56     1.17
  +++ httpd.h   1999/06/29 00:18:03     1.18
  @@ -933,7 +933,6 @@
       struct sockaddr_in local_addr;   /* local IP address and port */
       int fd;
       int used;                      /* Only used during restart */
  -    int index;                /* index into the listenfds array */
   /* more stuff here, like which protocol is bound to the port */
   };
   
  
  
  
  1.19      +15 -28    apache-apr/pthreads/src/main/http_accept.c
  
  Index: http_accept.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/pthreads/src/main/http_accept.c,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -d -u -r1.18 -r1.19
  --- http_accept.c     1999/06/10 06:26:07     1.18
  +++ http_accept.c     1999/06/29 00:18:03     1.19
  @@ -300,8 +300,8 @@
    * USE_MULTI_ACCEPT
    * Worker threads do the accept and process the request. 
    */
  -static listen_rec *head_listener;
   static struct pollfd *listenfds;
  +static int last_pollfd = 0; /* 0 = ap_pipe_of_death */
   
   void accept_parent_init(pool *pconf, int listener_count)
   {
  @@ -319,14 +319,12 @@
       SAFE_ACCEPT(intra_mutex_init(pchild, 1));
       SAFE_ACCEPT(accept_mutex_child_init(pchild));
       requests_this_child = ap_max_requests_per_child;
  -    head_listener = ap_listeners;
   
       listenfds = ap_palloc(pchild, sizeof(struct pollfd) * (num_listenfds + 
1));
       listenfds[0].fd = ap_pipe_of_death[0];
       listenfds[0].events = POLLIN;
       listenfds[0].revents = 0;
       for (lr = ap_listeners, i = 1; i <= num_listenfds; lr = lr->next, ++i) {
  -     lr->index = i;
        listenfds[i].fd = lr->fd;
        listenfds[i].events = POLLIN; /* should we add POLLPRI ?*/
        listenfds[i].revents = 0;
  @@ -344,6 +342,7 @@
       int ret;
       listen_rec *lr;
       char pipe_read_char;
  +    int curr_pollfd;
   
       size_t len = sizeof(struct sockaddr);
   
  @@ -404,44 +403,32 @@
   
            /* This conditional is used because the single listen case is the
             * only one where the accept might not be serialized. In that
  -          * case, multiple threads mucking around with the head_listener
  -          * pointer will be harmful */
  +          * case, multiple threads mucking around with the listenfds array
  +          *  and last_pollfd */
               if (num_listenfds == 1) {
                /* only one socket, just pretend we did the other stuff */
                sd = ap_listeners->fd;
               }
               else {
                   /* find a listener */
  -                /* Loop or NULL terminated list? That is the question. Be
  -                 * consistent across all the accept techniques */
  -                lr = head_listener;
  +                curr_pollfd = last_pollfd;
                   do {
  -                    /* XXX: should we check for PR_POLL_ERR ?? */
  -                    if (listenfds[lr->index].revents & POLLIN) {
  -                        /* advance to the next listener for next loop */
  -                        head_listener = lr->next;
  -                        /* hack to handle listenfds being NULL terminated 
list 
  -                         * rather than a loop 
  -                         */
  -                        if (head_listener == NULL) {
  -                            head_listener = ap_listeners;
  -                        }
  -                        goto got_lr;
  +                    curr_pollfd++;
  +                    if (curr_pollfd > num_listenfds) {
  +                        curr_pollfd = 1;
                       }
  -                    lr = lr->next;
  -                    if (lr == NULL) {
  -                     lr = ap_listeners;
  +                    /* XXX: should we check for POLLERR? */
  +                    if (listenfds[curr_pollfd].revents & POLLIN) {
  +                        last_pollfd = curr_pollfd;
  +                        sd = listenfds[curr_pollfd].fd;
  +                        goto got_lr;
                       }
  -                } while (lr != head_listener);
  +                } while (curr_pollfd != last_pollfd);
                   
                   /* if we don't find anything then just start again */
  -                fprintf(stderr,"poll returned but we got nothing!\n");       
  -                head_listener = ap_listeners;        
                   continue;
  -    
  -            got_lr:
  -                sd = lr->fd;
               }
  +        got_lr:
               csd = ap_accept(sd, sa_client, &len);   
               requests_this_child--;
   
  
  
  

Reply via email to