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...@apache.org on 2003/12/13 16:46:09 UTC

cvs commit: httpd-2.0/server/mpm/experimental/leader leader.c

trawick     2003/12/13 07:46:09

  Modified:    server/mpm/experimental/leader leader.c
  Log:
  update leader MPM to build and appear to work with the current APR
  pollset API
  
  Revision  Changes    Path
  1.34      +43 -25    httpd-2.0/server/mpm/experimental/leader/leader.c
  
  Index: leader.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/mpm/experimental/leader/leader.c,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- leader.c	24 Nov 2003 01:34:04 -0000	1.33
  +++ leader.c	13 Dec 2003 15:46:09 -0000	1.34
  @@ -703,11 +703,12 @@
       apr_allocator_t *allocator;
       apr_pool_t *ptrans;                /* Pool for per-transaction stuff */
       apr_bucket_alloc_t *bucket_alloc;
  -    int n;
  -    apr_pollfd_t *pollset;
  +    int numdesc;
  +    apr_pollset_t *pollset;
       apr_status_t rv;
  -    ap_listen_rec *lr, *last_lr = ap_listeners;
  +    ap_listen_rec *lr;
       int is_listener;
  +    int last_poll_idx = 0;
   
       ap_update_child_status_from_indexes(process_slot, thread_slot, SERVER_STARTING, NULL);
   
  @@ -720,10 +721,19 @@
       apr_allocator_owner_set(allocator, ptrans);
       bucket_alloc = apr_bucket_alloc_create_ex(allocator);
   
  -    apr_poll_setup(&pollset, num_listensocks, tpool);
  -    for(lr = ap_listeners ; lr != NULL ; lr = lr->next)
  -        apr_poll_socket_add(pollset, lr->sd, APR_POLLIN);
  -
  +    apr_pollset_create(&pollset, num_listensocks, tpool, 0);
  +    for (lr = ap_listeners ; lr != NULL ; lr = lr->next) {
  +        apr_pollfd_t pfd = { 0 };
  +
  +        pfd.desc_type = APR_POLL_SOCKET;
  +        pfd.desc.s = lr->sd;
  +        pfd.reqevents = APR_POLLIN;
  +        pfd.client_data = lr;
  +
  +        /* ### check the status */
  +        (void) apr_pollset_add(pollset, &pfd);
  +    }
  +    
       /* TODO: Switch to a system where threads reuse the results from earlier
          poll calls - manoj */
       is_listener = 0;
  @@ -778,37 +788,45 @@
           else {
               while (!workers_may_exit) {
                   apr_status_t ret;
  -                apr_int16_t event;
  +                const apr_pollfd_t *pdesc;
   
  -                ret = apr_poll(pollset, num_listensocks, &n, -1);
  +                ret = apr_pollset_poll(pollset, -1, &numdesc, &pdesc);
                   if (ret != APR_SUCCESS) {
                       if (APR_STATUS_IS_EINTR(ret)) {
                           continue;
                       }
   
  -                    /* apr_poll() will only return errors in catastrophic
  +                    /* apr_pollset_poll() will only return errors in catastrophic
                        * circumstances. Let's try exiting gracefully, for now. */
                       ap_log_error(APLOG_MARK, APLOG_ERR, ret, (const server_rec *)
  -                                 ap_server_conf, "apr_poll: (listen)");
  +                                 ap_server_conf, "apr_pollset_poll: (listen)");
                       signal_threads(ST_GRACEFUL);
                   }
   
                   if (workers_may_exit) break;
   
  -                /* find a listener */
  -                lr = last_lr;
  -                do {
  -                    lr = lr->next;
  -                    if (lr == NULL) {
  -                        lr = ap_listeners;
  -                    }
  -                    /* XXX: Should we check for POLLERR? */
  -                    apr_poll_revents_get(&event, lr->sd, pollset);
  -                    if (event & APR_POLLIN) {
  -                        last_lr = lr;
  -                        goto got_fd;
  -                    }
  -                } while (lr != last_lr);
  +                /* We can always use pdesc[0], but sockets at position N
  +                 * could end up completely starved of attention in a very
  +                 * busy server. Therefore, we round-robin across the
  +                 * returned set of descriptors. While it is possible that
  +                 * the returned set of descriptors might flip around and
  +                 * continue to starve some sockets, we happen to know the
  +                 * internal pollset implementation retains ordering
  +                 * stability of the sockets. Thus, the round-robin should
  +                 * ensure that a socket will eventually be serviced.
  +                 */
  +                if (last_poll_idx >= numdesc)
  +                    last_poll_idx = 0;
  +
  +                /* Grab a listener record from the client_data of the poll
  +                 * descriptor, and advance our saved index to round-robin
  +                 * the next fetch.
  +                 *
  +                 * ### hmm... this descriptor might have POLLERR rather
  +                 * ### than POLLIN
  +                 */
  +                lr = pdesc[last_poll_idx++].client_data;
  +                goto got_fd;
               }
           }
       got_fd: