]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Follow up to r1879449: yet better MPM poll callback API.
authorYann Ylavic <ylavic@apache.org>
Thu, 2 Jul 2020 15:49:53 +0000 (15:49 +0000)
committerYann Ylavic <ylavic@apache.org>
Thu, 2 Jul 2020 15:49:53 +0000 (15:49 +0000)
Let pass a const pfds to the MPM, for it to make a copy on the given pool
as needed.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879451 13f79535-47bb-0310-9956-ffa450edef68

include/ap_mmn.h
include/ap_mpm.h
include/mpm_common.h
modules/proxy/mod_proxy_http.c
modules/proxy/mod_proxy_wstunnel.c
server/mpm/event/event.c
server/mpm_common.c

index 68905ad85bf12278937722008249fc17e8da9f06..7e232a920696b732510da60391bb80dd6e6721a2 100644 (file)
  *                         mpm_unregister_poll_callback hook.
  * 20200702.0 (2.5.1-dev)  Add pool arg to mpm_register_poll_callback and
  *                         mpm_register_poll_callback_timeout hooks
- *                         
  */
 
 #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */
index a5e2ce106283270a22ab4dbe6a94785dffad069e..6698d0e7c6069ecef0c7c55a14472ac2efa4a01f 100644 (file)
@@ -224,7 +224,7 @@ AP_DECLARE(apr_status_t) ap_mpm_register_timed_callback(
  */
 
 AP_DECLARE(apr_status_t) ap_mpm_register_poll_callback(
-        apr_pool_t *p, apr_array_header_t *pfds,
+        apr_pool_t *p, const apr_array_header_t *pfds,
         ap_mpm_callback_fn_t *cbfn, void *baton);
 
 /**
@@ -247,7 +247,7 @@ AP_DECLARE(apr_status_t) ap_mpm_register_poll_callback(
  */
 
 AP_DECLARE(apr_status_t) ap_mpm_register_poll_callback_timeout(
-        apr_pool_t *p, apr_array_header_t *pfds,
+        apr_pool_t *p, const apr_array_header_t *pfds,
         ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn,
         void *baton, apr_time_t timeout);
 
index a0966a58ba2994f3041e0d491ae837ce460fb73c..a8e7b03749df3188ecc57705d6f72d7a62e4fe1f 100644 (file)
@@ -427,7 +427,7 @@ AP_DECLARE_HOOK(apr_status_t, mpm_register_timed_callback,
  * @ingroup hooks
  */
 AP_DECLARE_HOOK(apr_status_t, mpm_register_poll_callback,
-                (apr_pool_t *p, apr_array_header_t *pds,
+                (apr_pool_t *p, const apr_array_header_t *pds,
                  ap_mpm_callback_fn_t *cbfn, void *baton))
 
 /* register the specified callback, with timeout 
@@ -435,9 +435,8 @@ AP_DECLARE_HOOK(apr_status_t, mpm_register_poll_callback,
  *
  */
 AP_DECLARE_HOOK(apr_status_t, mpm_register_poll_callback_timeout,
-                (apr_pool_t *p, apr_array_header_t *pds,
-                ap_mpm_callback_fn_t *cbfn,
-                ap_mpm_callback_fn_t *tofn,
+                (apr_pool_t *p, const apr_array_header_t *pds,
+                ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn,
                 void *baton, apr_time_t timeout))
 
 /** Resume the suspended connection 
index 3572650a0f7488a756498c26f64be97a9674a2fd..76caf2c06ae580526b0eaacf1016b72dff66f383 100644 (file)
@@ -256,7 +256,6 @@ typedef struct {
     proxy_tunnel_rec *tunnel;
 
     apr_pool_t *async_pool;
-    apr_array_header_t *pfds;
     apr_interval_time_t idle_timeout;
 
     unsigned int can_go_async           :1,
@@ -319,26 +318,6 @@ static void proxy_http_async_cb(void *baton)
         /* Pump both ends until they'd block and then start over again */
         status = ap_proxy_tunnel_run(req->tunnel);
         if (status == HTTP_GATEWAY_TIME_OUT) {
-            if (!req->async_pool) {
-                /* Create the MPM's (req->)pfds off of our tunnel's, and
-                 * the subpool used by the MPM to alloc its own temporary
-                 * data, which we want to clear on the next round (above)
-                 * to avoid leaks.
-                 */
-                req->pfds = apr_array_copy(req->p, req->tunnel->pfds);
-                APR_ARRAY_IDX(req->pfds, 0, apr_pollfd_t).client_data = NULL;
-                APR_ARRAY_IDX(req->pfds, 1, apr_pollfd_t).client_data = NULL;
-                apr_pool_create(&req->async_pool, req->p);
-            }
-            else {
-                /* Update only reqevents of the MPM's pfds with our tunnel's,
-                 * the rest didn't change.
-                 */
-                APR_ARRAY_IDX(req->pfds, 0, apr_pollfd_t).reqevents =
-                    APR_ARRAY_IDX(req->tunnel->pfds, 0, apr_pollfd_t).reqevents;
-                APR_ARRAY_IDX(req->pfds, 1, apr_pollfd_t).reqevents =
-                    APR_ARRAY_IDX(req->tunnel->pfds, 1, apr_pollfd_t).reqevents;
-            }
             status = SUSPENDED;
         }
         break;
@@ -356,7 +335,16 @@ static void proxy_http_async_cb(void *baton)
                       "proxy %s: suspended, going async",
                       req->proto);
 
-        ap_mpm_register_poll_callback_timeout(req->async_pool, req->pfds,
+        if (!req->async_pool) {
+            /* Create the subpool used by the MPM to alloc its own
+             * temporary data, which we want to clear on the next
+             * round (above) to avoid leaks.
+             */
+            apr_pool_create(&req->async_pool, req->p);
+        }
+
+        ap_mpm_register_poll_callback_timeout(req->async_pool,
+                                              req->tunnel->pfds,
                                               proxy_http_async_cb, 
                                               proxy_http_async_cancel_cb, 
                                               req, req->idle_timeout);
index c98b99ea6bd07a7224c09404ff2305b5be73ca23..0c082fe6d886b9e39532e854256d40ef19f91c40 100644 (file)
@@ -29,7 +29,6 @@ typedef struct ws_baton_t {
     request_rec *r;
     proxy_conn_rec *backend;
     proxy_tunnel_rec *tunnel;
-    apr_array_header_t *pfds;
     apr_pool_t *async_pool;
     const char *scheme;
 } ws_baton_t;
@@ -96,15 +95,8 @@ static void proxy_wstunnel_callback(void *b)
         ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, baton->r,
                       "proxy_wstunnel_callback suspend");
 
-        /* Update only reqevents of the MPM's pfds with our tunnel's,
-         * the rest didn't change.
-         */
-        APR_ARRAY_IDX(baton->pfds, 0, apr_pollfd_t).reqevents =
-            APR_ARRAY_IDX(baton->tunnel->pfds, 0, apr_pollfd_t).reqevents;
-        APR_ARRAY_IDX(baton->pfds, 1, apr_pollfd_t).reqevents =
-            APR_ARRAY_IDX(baton->tunnel->pfds, 1, apr_pollfd_t).reqevents;
-
-        ap_mpm_register_poll_callback_timeout(baton->async_pool, baton->pfds,
+        ap_mpm_register_poll_callback_timeout(baton->async_pool,
+                                              baton->tunnel->pfds,
                                               proxy_wstunnel_callback, 
                                               proxy_wstunnel_cancel_callback, 
                                               baton, dconf->idle_timeout);
@@ -275,18 +267,15 @@ static int proxy_wstunnel_request(apr_pool_t *p, request_rec *r,
         tunnel->timeout = dconf->async_delay;
         status = proxy_wstunnel_pump(baton, 1);
         if (status == SUSPENDED) {
-            /* Create the MPM's (baton->)pfds off of our tunnel's, and
-             * the subpool used by the MPM to alloc its own temporary
-             * data, which we want to clear on the next round (above)
-             * to avoid leaks.
+            /* Create the subpool used by the MPM to alloc its own
+             * temporary data, which we want to clear on the next
+             * round (above) to avoid leaks.
              */
-            baton->pfds = apr_array_copy(baton->r->pool, baton->tunnel->pfds);
-            APR_ARRAY_IDX(baton->pfds, 0, apr_pollfd_t).client_data = NULL;
-            APR_ARRAY_IDX(baton->pfds, 1, apr_pollfd_t).client_data = NULL;
             apr_pool_create(&baton->async_pool, baton->r->pool);
 
             rv = ap_mpm_register_poll_callback_timeout(
-                         baton->async_pool, baton->pfds,
+                         baton->async_pool,
+                         baton->tunnel->pfds,
                          proxy_wstunnel_callback, 
                          proxy_wstunnel_cancel_callback, 
                          baton, 
index 3de751f36d116fe2be2ccb0fcd9f0ce30957368d..69384652b804b4f8eb95be3c5c5819ed2d555e28 100644 (file)
@@ -1605,11 +1605,11 @@ static apr_status_t event_cleanup_poll_callback(void *data)
 }
 
 static apr_status_t event_register_poll_callback_ex(apr_pool_t *p,
-                                                    apr_array_header_t *pfds,
-                                                    ap_mpm_callback_fn_t *cbfn,
-                                                    ap_mpm_callback_fn_t *tofn,
-                                                    void *baton,
-                                                    apr_time_t timeout)
+                                                const apr_array_header_t *pfds,
+                                                ap_mpm_callback_fn_t *cbfn,
+                                                ap_mpm_callback_fn_t *tofn,
+                                                void *baton,
+                                                apr_time_t timeout)
 {
     socket_callback_baton_t *scb = apr_pcalloc(p, sizeof(*scb));
     listener_poll_type *pt = apr_palloc(p, sizeof(*pt));
@@ -1621,12 +1621,12 @@ static apr_status_t event_register_poll_callback_ex(apr_pool_t *p,
 
     scb->cbfunc = cbfn;
     scb->user_baton = baton;
-    scb->pfds = pfds;
+    scb->pfds = apr_array_copy(p, pfds);
 
-    apr_pool_pre_cleanup_register(p, pfds, event_cleanup_poll_callback);
+    apr_pool_pre_cleanup_register(p, scb->pfds, event_cleanup_poll_callback);
 
-    for (i = 0; i < pfds->nelts; i++) {
-        apr_pollfd_t *pfd = (apr_pollfd_t *)pfds->elts + i;
+    for (i = 0; i < scb->pfds->nelts; i++) {
+        apr_pollfd_t *pfd = (apr_pollfd_t *)scb->pfds->elts + i;
         if (pfd->reqevents) {
             if (pfd->reqevents & APR_POLLIN) {
                 pfd->reqevents |= APR_POLLHUP;
@@ -1641,10 +1641,10 @@ static apr_status_t event_register_poll_callback_ex(apr_pool_t *p,
 
     if (timeout > 0) { 
         /* XXX:  This cancel timer event can fire before the pollset is updated */
-        scb->cancel_event = event_get_timer_event(timeout, tofn, baton, 1, pfds);
+        scb->cancel_event = event_get_timer_event(timeout, tofn, baton, 1, scb->pfds);
     }
-    for (i = 0; i < pfds->nelts; i++) {
-        apr_pollfd_t *pfd = (apr_pollfd_t *)pfds->elts + i;
+    for (i = 0; i < scb->pfds->nelts; i++) {
+        apr_pollfd_t *pfd = (apr_pollfd_t *)scb->pfds->elts + i;
         if (pfd->client_data) {
             rc = apr_pollset_add(event_pollset, pfd);
             if (rc != APR_SUCCESS) {
@@ -1656,7 +1656,7 @@ static apr_status_t event_register_poll_callback_ex(apr_pool_t *p,
 }
 
 static apr_status_t event_register_poll_callback(apr_pool_t *p,
-                                                 apr_array_header_t *pfds,
+                                                 const apr_array_header_t *pfds,
                                                  ap_mpm_callback_fn_t *cbfn,
                                                  void *baton)
 {
index 09a7e06e4a18903369ffa038df28730cb8b7b7fc..d5a27faa0413c04723260f67d43877f7e5a1dd26 100644 (file)
@@ -110,11 +110,11 @@ AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_resume_suspended,
                             (conn_rec *c),
                             (c), APR_ENOTIMPL)
 AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_register_poll_callback,
-                            (apr_pool_t *p, apr_array_header_t *pds,
+                            (apr_pool_t *p, const apr_array_header_t *pds,
                              ap_mpm_callback_fn_t *cbfn, void *baton),
                             (p, pds, cbfn, baton), APR_ENOTIMPL)
 AP_IMPLEMENT_HOOK_RUN_FIRST(apr_status_t, mpm_register_poll_callback_timeout,
-                            (apr_pool_t *p, apr_array_header_t *pds,
+                            (apr_pool_t *p, const apr_array_header_t *pds,
                              ap_mpm_callback_fn_t *cbfn,
                              ap_mpm_callback_fn_t *tofn,
                              void *baton, apr_time_t timeout),
@@ -572,15 +572,16 @@ AP_DECLARE(apr_status_t) ap_mpm_register_timed_callback(apr_time_t t,
 }
 
 AP_DECLARE(apr_status_t) ap_mpm_register_poll_callback(
-        apr_pool_t *p, apr_array_header_t *pfds,
+        apr_pool_t *p, const apr_array_header_t *pfds,
         ap_mpm_callback_fn_t *cbfn, void *baton)
 {
     return ap_run_mpm_register_poll_callback(p, pfds, cbfn, baton);
 }
 
 AP_DECLARE(apr_status_t) ap_mpm_register_poll_callback_timeout(
-        apr_pool_t *p, apr_array_header_t *pfds, ap_mpm_callback_fn_t *cbfn,
-        ap_mpm_callback_fn_t *tofn, void *baton, apr_time_t timeout)
+        apr_pool_t *p, const apr_array_header_t *pfds,
+        ap_mpm_callback_fn_t *cbfn, ap_mpm_callback_fn_t *tofn,
+        void *baton, apr_time_t timeout)
 {
     return ap_run_mpm_register_poll_callback_timeout(p, pfds, cbfn, tofn,
                                                      baton, timeout);