]> granicus.if.org Git - apache/commitdiff
Merge r1204104, 1204180:
authorStefan Fritsch <sf@apache.org>
Mon, 21 Nov 2011 23:07:16 +0000 (23:07 +0000)
committerStefan Fritsch <sf@apache.org>
Mon, 21 Nov 2011 23:07:16 +0000 (23:07 +0000)
Remove MPM-private stuff from conn_state_t.

This should make it easier to improve the event MPM in 2.4 without breaking
the API.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1204743 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
include/httpd.h
modules/http/http_core.c
modules/http/http_request.c
server/core.c
server/mpm/event/event.c
server/mpm/event/fdqueue.c
server/mpm/event/fdqueue.h

index 4770d753d5d8a3fa9b7611d8ab9daa5d8d379482..1dd264736832960c43e4a758540d7840fcb4e091 100644 (file)
  *                         and ap_unescape_urlencoded().
  * 20111025.2 (2.3.15-dev) Add ap_lua_ssl_val to mod_lua
  * 20111025.3 (2.4.0-dev)  Add reclvl to ap_expr_eval_ctx_t
+ * 20111122.0 (2.4.0-dev)  Remove parts of conn_state_t that are private to the MPM
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
 
 #ifndef MODULE_MAGIC_NUMBER_MAJOR
-#define MODULE_MAGIC_NUMBER_MAJOR 20111025
+#define MODULE_MAGIC_NUMBER_MAJOR 20111122
 #endif
-#define MODULE_MAGIC_NUMBER_MINOR 3                   /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 0                   /* 0...n */
 
 /**
  * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
index 464f4a12866232a6445cacd25e70faae85308b1c..39d10e1c4c4d90ee40e1d0b80411a0081142fa7d 100644 (file)
@@ -1080,7 +1080,7 @@ struct conn_rec {
     void *sbh;
     /** The bucket allocator to use for all bucket/brigade creations */
     struct apr_bucket_alloc_t *bucket_alloc;
-    /** The current state of this connection */
+    /** The current state of this connection; may be NULL if not used by MPM */
     conn_state_t *cs;
     /** Is there data pending in the input filters? */
     int data_in_input_filters;
@@ -1144,18 +1144,6 @@ typedef enum  {
  * @brief A structure to contain connection state information
  */
 struct conn_state_t {
-    /** APR_RING of expiration timeouts */
-    APR_RING_ENTRY(conn_state_t) timeout_list;
-    /** the expiration time of the next keepalive timeout */
-    apr_time_t expiration_time;
-    /** connection record this struct refers to */
-    conn_rec *c;
-    /** memory pool to allocate from */
-    apr_pool_t *p;
-    /** bucket allocator */
-    apr_bucket_alloc_t *bucket_alloc;
-    /** poll file descriptor information */
-    apr_pollfd_t pfd;
     /** Current state of the connection */
     conn_state_e state;
 };
index 8970ae6dc46c5ca8581eb6e2330c8a868190d0e6..663810a526b38781974fb1a07912d0b1d3f12b23 100644 (file)
@@ -126,6 +126,7 @@ static int ap_process_http_async_connection(conn_rec *c)
     request_rec *r;
     conn_state_t *cs = c->cs;
 
+    AP_DEBUG_ASSERT(cs != NULL);
     AP_DEBUG_ASSERT(cs->state == CONN_STATE_READ_REQUEST_LINE);
 
     while (cs->state == CONN_STATE_READ_REQUEST_LINE) {
@@ -184,7 +185,8 @@ static int ap_process_http_sync_connection(conn_rec *c)
 
         ap_update_child_status(c->sbh, SERVER_BUSY_WRITE, r);
         if (r->status == HTTP_OK) {
-            cs->state = CONN_STATE_HANDLER;
+            if (cs)
+                cs->state = CONN_STATE_HANDLER;
             ap_process_request(r);
             /* After the call to ap_process_request, the
              * request pool will have been deleted.  We set
index 2b357fc5647d1c27c84e4269d43de84e8bdd41a0..9d67a29a9d5446d31cda329a83e68ea99430ac6d 100644 (file)
@@ -260,7 +260,8 @@ AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
      * already by the EOR bucket's cleanup function.
      */
 
-    c->cs->state = CONN_STATE_WRITE_COMPLETION;
+    if (c->cs)
+        c->cs->state = CONN_STATE_WRITE_COMPLETION;
     check_pipeline(c);
     AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, r->status);
     if (ap_extended_status) {
@@ -325,7 +326,8 @@ void ap_process_async_request(request_rec *r)
         if (ap_extended_status) {
             ap_time_process_request(c->sbh, STOP_PREQUEST);
         }
-        c->cs->state = CONN_STATE_SUSPENDED;
+        if (c->cs)
+            c->cs->state = CONN_STATE_SUSPENDED;
 #if APR_HAS_THREADS
         apr_thread_mutex_unlock(r->invoke_mtx);
 #endif
index 751c32219b441115b32838404b7497bc65bd62ab..b96fe7632b587208e965fc84f387268f06d69d4e 100644 (file)
@@ -4525,13 +4525,6 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *server,
     c->id = id;
     c->bucket_alloc = alloc;
 
-    c->cs = (conn_state_t *)apr_pcalloc(ptrans, sizeof(conn_state_t));
-    APR_RING_INIT(&(c->cs->timeout_list), conn_state_t, timeout_list);
-    c->cs->expiration_time = 0;
-    c->cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
-    c->cs->c = c;
-    c->cs->p = ptrans;
-    c->cs->bucket_alloc = alloc;
     c->clogging_input_filters = 0;
 
     return c;
index 3aeb4f62a862d748bcaad6ebfbf60bd8980df1cc..62560a1d7e2e8cc3c298c06ef02d41dd03e7050e 100644 (file)
@@ -179,7 +179,25 @@ static fd_queue_info_t *worker_queue_info;
 static int mpm_state = AP_MPMQ_STARTING;
 
 static apr_thread_mutex_t *timeout_mutex;
-APR_RING_HEAD(timeout_head_t, conn_state_t);
+
+struct event_conn_state_t {
+    /** APR_RING of expiration timeouts */
+    APR_RING_ENTRY(event_conn_state_t) timeout_list;
+    /** the expiration time of the next keepalive timeout */
+    apr_time_t expiration_time;
+    /** connection record this struct refers to */
+    conn_rec *c;
+    /** memory pool to allocate from */
+    apr_pool_t *p;
+    /** bucket allocator */
+    apr_bucket_alloc_t *bucket_alloc;
+    /** poll file descriptor information */
+    apr_pollfd_t pfd;
+    /** public parts of the connection state */
+    conn_state_t pub;
+};
+APR_RING_HEAD(timeout_head_t, event_conn_state_t);
+
 struct timeout_queue {
     struct timeout_head_t head;
     int count;
@@ -201,10 +219,10 @@ static apr_pollfd_t *listener_pollfd;
  * Macros for accessing struct timeout_queue.
  * For TO_QUEUE_APPEND and TO_QUEUE_REMOVE, timeout_mutex must be held.
  */
-#define TO_QUEUE_APPEND(q, el)                                            \
-    do {                                                                  \
-        APR_RING_INSERT_TAIL(&(q).head, el, conn_state_t, timeout_list);  \
-        (q).count++;                                                      \
+#define TO_QUEUE_APPEND(q, el)                                                  \
+    do {                                                                        \
+        APR_RING_INSERT_TAIL(&(q).head, el, event_conn_state_t, timeout_list);  \
+        (q).count++;                                                            \
     } while (0)
 
 #define TO_QUEUE_REMOVE(q, el)             \
@@ -213,10 +231,10 @@ static apr_pollfd_t *listener_pollfd;
         (q).count--;                       \
     } while (0)
 
-#define TO_QUEUE_INIT(q)                                            \
-    do {                                                            \
-            APR_RING_INIT(&(q).head, conn_state_t, timeout_list);   \
-            (q).tag = #q;                                           \
+#define TO_QUEUE_INIT(q)                                                  \
+    do {                                                                  \
+            APR_RING_INIT(&(q).head, event_conn_state_t, timeout_list);   \
+            (q).tag = #q;                                                 \
     } while (0)
 
 #define TO_QUEUE_ELEM_INIT(el) APR_RING_ELEM_INIT(el, timeout_list)
@@ -725,7 +743,7 @@ static void set_signals(void)
  *         1 if connection is lingering
  * may be called by listener or by worker thread
  */
-static int start_lingering_close(conn_state_t *cs)
+static int start_lingering_close(event_conn_state_t *cs)
 {
     apr_status_t rv;
     if (ap_start_lingering_close(cs->c)) {
@@ -748,13 +766,13 @@ static int start_lingering_close(conn_state_t *cs)
             cs->expiration_time =
                 apr_time_now() + apr_time_from_sec(SECONDS_TO_LINGER);
             q = &short_linger_q;
-            cs->state = CONN_STATE_LINGER_SHORT;
+            cs->pub.state = CONN_STATE_LINGER_SHORT;
         }
         else {
             cs->expiration_time =
                 apr_time_now() + apr_time_from_sec(MAX_SECS_TO_LINGER);
             q = &linger_q;
-            cs->state = CONN_STATE_LINGER_NORMAL;
+            cs->pub.state = CONN_STATE_LINGER_NORMAL;
         }
         apr_thread_mutex_lock(timeout_mutex);
         TO_QUEUE_APPEND(*q, cs);
@@ -782,7 +800,7 @@ static int start_lingering_close(conn_state_t *cs)
  * Pre-condition: cs is not in any timeout queue and not in the pollset
  * return: irrelevant (need same prototype as start_lingering_close)
  */
-static int stop_lingering_close(conn_state_t *cs)
+static int stop_lingering_close(event_conn_state_t *cs)
 {
     apr_status_t rv;
     apr_socket_t *csd = ap_get_conn_socket(cs->c);
@@ -804,7 +822,7 @@ static int stop_lingering_close(conn_state_t *cs)
  *         0 if it is still open and waiting for some event
  */
 static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock,
-                          conn_state_t * cs, int my_child_num,
+                          event_conn_state_t * cs, int my_child_num,
                           int my_thread_num)
 {
     conn_rec *c;
@@ -816,7 +834,7 @@ static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock
 
     if (cs == NULL) {           /* This is a new connection */
         listener_poll_type *pt = apr_pcalloc(p, sizeof(*pt));
-        cs = apr_pcalloc(p, sizeof(conn_state_t));
+        cs = apr_pcalloc(p, sizeof(event_conn_state_t));
         cs->bucket_alloc = apr_bucket_alloc_create(p);
         c = ap_run_create_connection(p, ap_server_conf, sock,
                                      conn_id, sbh, cs->bucket_alloc);
@@ -830,7 +848,7 @@ static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock
         apr_pool_cleanup_register(c->pool, NULL, decrement_connection_count, apr_pool_cleanup_null);
         c->current_thread = thd;
         cs->c = c;
-        c->cs = cs;
+        c->cs = &(cs->pub);
         cs->p = p;
         cs->pfd.desc_type = APR_POLL_SOCKET;
         cs->pfd.reqevents = APR_POLLIN;
@@ -862,7 +880,7 @@ static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock
          * When the accept filter is active, sockets are kept in the
          * kernel until a HTTP request is received.
          */
-        cs->state = CONN_STATE_READ_REQUEST_LINE;
+        cs->pub.state = CONN_STATE_READ_REQUEST_LINE;
 
     }
     else {
@@ -877,13 +895,13 @@ static int process_socket(apr_thread_t *thd, apr_pool_t * p, apr_socket_t * sock
          * like the Worker MPM does.
          */
         ap_run_process_connection(c);
-        if (cs->state != CONN_STATE_SUSPENDED) {
-            cs->state = CONN_STATE_LINGER;
+        if (cs->pub.state != CONN_STATE_SUSPENDED) {
+            cs->pub.state = CONN_STATE_LINGER;
         }
     }
 
 read_request:
-    if (cs->state == CONN_STATE_READ_REQUEST_LINE) {
+    if (cs->pub.state == CONN_STATE_READ_REQUEST_LINE) {
         if (!c->aborted) {
             ap_run_process_connection(c);
 
@@ -893,11 +911,11 @@ read_request:
              */
         }
         else {
-            cs->state = CONN_STATE_LINGER;
+            cs->pub.state = CONN_STATE_LINGER;
         }
     }
 
-    if (cs->state == CONN_STATE_WRITE_COMPLETION) {
+    if (cs->pub.state == CONN_STATE_WRITE_COMPLETION) {
         ap_filter_t *output_filter = c->output_filters;
         apr_status_t rv;
         ap_update_child_status_from_conn(sbh, SERVER_BUSY_WRITE, c);
@@ -908,7 +926,7 @@ read_request:
         if (rv != APR_SUCCESS) {
             ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, c,
                           "network write failure in core output filter");
-            cs->state = CONN_STATE_LINGER;
+            cs->pub.state = CONN_STATE_LINGER;
         }
         else if (c->data_in_output_filters) {
             /* Still in WRITE_COMPLETION_STATE:
@@ -925,22 +943,22 @@ read_request:
         }
         else if (c->keepalive != AP_CONN_KEEPALIVE || c->aborted ||
             listener_may_exit) {
-            c->cs->state = CONN_STATE_LINGER;
+            cs->pub.state = CONN_STATE_LINGER;
         }
         else if (c->data_in_input_filters) {
-            cs->state = CONN_STATE_READ_REQUEST_LINE;
+            cs->pub.state = CONN_STATE_READ_REQUEST_LINE;
             goto read_request;
         }
         else {
-            cs->state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
+            cs->pub.state = CONN_STATE_CHECK_REQUEST_LINE_READABLE;
         }
     }
 
-    if (cs->state == CONN_STATE_LINGER) {
+    if (cs->pub.state == CONN_STATE_LINGER) {
         if (!start_lingering_close(cs))
             return 0;
     }
-    else if (cs->state == CONN_STATE_CHECK_REQUEST_LINE_READABLE) {
+    else if (cs->pub.state == CONN_STATE_CHECK_REQUEST_LINE_READABLE) {
         apr_status_t rc;
 
         /* It greatly simplifies the logic to use a single timeout value here
@@ -1069,7 +1087,7 @@ static apr_status_t push2worker(const apr_pollfd_t * pfd,
                                 apr_pollset_t * pollset)
 {
     listener_poll_type *pt = (listener_poll_type *) pfd->client_data;
-    conn_state_t *cs = (conn_state_t *) pt->baton;
+    event_conn_state_t *cs = (event_conn_state_t *) pt->baton;
     apr_status_t rc;
 
     rc = ap_queue_push(worker_queue, cs->pfd.desc.s, cs, cs->p);
@@ -1191,14 +1209,14 @@ static apr_status_t event_register_timed_callback(apr_time_t t,
  * Only to be called in the listener thread;
  * Pre-condition: cs is in one of the linger queues and in the pollset
  */
-static void process_lingering_close(conn_state_t *cs, const apr_pollfd_t *pfd)
+static void process_lingering_close(event_conn_state_t *cs, const apr_pollfd_t *pfd)
 {
     apr_socket_t *csd = ap_get_conn_socket(cs->c);
     char dummybuf[2048];
     apr_size_t nbytes;
     apr_status_t rv;
     struct timeout_queue *q;
-    q = (cs->state == CONN_STATE_LINGER_SHORT) ?  &short_linger_q : &linger_q;
+    q = (cs->pub.state == CONN_STATE_LINGER_SHORT) ?  &short_linger_q : &linger_q;
 
     /* socket is already in non-blocking state */
     do {
@@ -1231,18 +1249,18 @@ static void process_lingering_close(conn_state_t *cs, const apr_pollfd_t *pfd)
  */
 static void process_timeout_queue(struct timeout_queue *q,
                                   apr_time_t timeout_time,
-                                  int (*func)(conn_state_t *))
+                                  int (*func)(event_conn_state_t *))
 {
     int count = 0;
-    conn_state_t *first, *cs, *last;
+    event_conn_state_t *first, *cs, *last;
     apr_status_t rv;
     if (!q->count) {
         return;
     }
-    AP_DEBUG_ASSERT(!APR_RING_EMPTY(&q->head, conn_state_t, timeout_list));
+    AP_DEBUG_ASSERT(!APR_RING_EMPTY(&q->head, event_conn_state_t, timeout_list));
 
     cs = first = APR_RING_FIRST(&q->head);
-    while (cs != APR_RING_SENTINEL(&q->head, conn_state_t, timeout_list)
+    while (cs != APR_RING_SENTINEL(&q->head, event_conn_state_t, timeout_list)
            && cs->expiration_time < timeout_time) {
         last = cs;
         rv = apr_pollset_remove(event_pollset, &cs->pfd);
@@ -1282,7 +1300,7 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy)
     apr_pool_t *ptrans;         /* Pool for per-transaction stuff */
     ap_listen_rec *lr;
     int have_idle_worker = 0;
-    conn_state_t *cs;
+    event_conn_state_t *cs;
     const apr_pollfd_t *out_pfd;
     apr_int32_t num = 0;
     apr_interval_time_t timeout_interval;
@@ -1403,10 +1421,10 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy)
                 /* one of the sockets is readable */
                 struct timeout_queue *remove_from_q = &write_completion_q;
                 int blocking = 1;
-                cs = (conn_state_t *) pt->baton;
-                switch (cs->state) {
+                cs = (event_conn_state_t *) pt->baton;
+                switch (cs->pub.state) {
                 case CONN_STATE_CHECK_REQUEST_LINE_READABLE:
-                    cs->state = CONN_STATE_READ_REQUEST_LINE;
+                    cs->pub.state = CONN_STATE_READ_REQUEST_LINE;
                     remove_from_q = &keepalive_q;
                     /* don't wait for a worker for a keepalive request */
                     blocking = 0;
@@ -1459,7 +1477,7 @@ static void * APR_THREAD_FUNC listener_thread(apr_thread_t * thd, void *dummy)
                     ap_log_error(APLOG_MARK, APLOG_CRIT, rc,
                                  ap_server_conf,
                                  "event_loop: unexpected state %d",
-                                 cs->state);
+                                 cs->pub.state);
                     ap_assert(0);
                 }
             }
@@ -1635,7 +1653,7 @@ static void *APR_THREAD_FUNC worker_thread(apr_thread_t * thd, void *dummy)
     int process_slot = ti->pid;
     int thread_slot = ti->tid;
     apr_socket_t *csd = NULL;
-    conn_state_t *cs;
+    event_conn_state_t *cs;
     apr_pool_t *ptrans;         /* Pool for per-transaction stuff */
     apr_status_t rv;
     int is_idle = 0;
index f7de0bfb263d669a2ddcaf504d9b5e6132fe187a..32911757f0329fbc24c286b54eae278673cd0481 100644 (file)
@@ -364,7 +364,7 @@ apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
  *               to reserve an idle worker thread
  */
 apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
-                           conn_state_t * cs, apr_pool_t * p)
+                           event_conn_state_t * ecs, apr_pool_t * p)
 {
     fd_queue_elem_t *elem;
     apr_status_t rv;
@@ -381,7 +381,7 @@ apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
     if (queue->in >= queue->bounds)
         queue->in -= queue->bounds;
     elem->sd = sd;
-    elem->cs = cs;
+    elem->ecs = ecs;
     elem->p = p;
     queue->nelts++;
 
@@ -422,7 +422,7 @@ apr_status_t ap_queue_push_timer(fd_queue_t * queue, timer_event_t *te)
  * 'sd'.
  */
 apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
-                                    conn_state_t ** cs, apr_pool_t ** p,
+                                    event_conn_state_t ** ecs, apr_pool_t ** p,
                                     timer_event_t ** te_out)
 {
     fd_queue_elem_t *elem;
@@ -465,7 +465,7 @@ apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
             queue->out -= queue->bounds;
         queue->nelts--;
         *sd = elem->sd;
-        *cs = elem->cs;
+        *ecs = elem->ecs;
         *p = elem->p;
 #ifdef AP_DEBUG
         elem->sd = NULL;
index 5877ee74fb6461a83808ad82eff70bb4e4c1273e..955816b7d2aa1e12a69327c069fedda8b8c6217a 100644 (file)
@@ -40,6 +40,7 @@
 #include "ap_mpm.h"
 
 typedef struct fd_queue_info_t fd_queue_info_t;
+typedef struct event_conn_state_t event_conn_state_t;
 
 apr_status_t ap_queue_info_create(fd_queue_info_t ** queue_info,
                                   apr_pool_t * pool, int max_idlers,
@@ -56,7 +57,7 @@ struct fd_queue_elem_t
 {
     apr_socket_t *sd;
     apr_pool_t *p;
-    conn_state_t *cs;
+    event_conn_state_t *ecs;
 };
 typedef struct fd_queue_elem_t fd_queue_elem_t;
 
@@ -91,10 +92,10 @@ void ap_push_pool(fd_queue_info_t * queue_info,
 apr_status_t ap_queue_init(fd_queue_t * queue, int queue_capacity,
                            apr_pool_t * a);
 apr_status_t ap_queue_push(fd_queue_t * queue, apr_socket_t * sd,
-                           conn_state_t * cs, apr_pool_t * p);
+                           event_conn_state_t * ecs, apr_pool_t * p);
 apr_status_t ap_queue_push_timer(fd_queue_t *queue, timer_event_t *te);
 apr_status_t ap_queue_pop_something(fd_queue_t * queue, apr_socket_t ** sd,
-                                    conn_state_t ** cs, apr_pool_t ** p,
+                                    event_conn_state_t ** ecs, apr_pool_t ** p,
                                     timer_event_t ** te);
 apr_status_t ap_queue_interrupt_all(fd_queue_t * queue);
 apr_status_t ap_queue_term(fd_queue_t * queue);