]> granicus.if.org Git - apache/commitdiff
* Let mod_proxy_wstunnel and mod_proxy_connect use ap_proxy_transfer_between_connections
authorRuediger Pluem <rpluem@apache.org>
Thu, 4 Feb 2016 13:57:14 +0000 (13:57 +0000)
committerRuediger Pluem <rpluem@apache.org>
Thu, 4 Feb 2016 13:57:14 +0000 (13:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1728481 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy_connect.c
modules/proxy/mod_proxy_wstunnel.c

index 225419045d5d227997eb652f3f3e3338f7fde1dd..b0289ea811a85a6fd564ac2506d60f4711a8f560 100644 (file)
@@ -143,55 +143,6 @@ static int proxy_connect_canon(request_rec *r, char *url)
     return OK;
 }
 
-/* read available data (in blocks of CONN_BLKSZ) from c_i and copy to c_o */
-static int proxy_connect_transfer(request_rec *r, conn_rec *c_i, conn_rec *c_o,
-                                  apr_bucket_brigade *bb_i,
-                                  apr_bucket_brigade *bb_o, char *name)
-{
-    int rv;
-#ifdef DEBUGGING
-    apr_off_t len;
-#endif
-
-    do {
-        apr_brigade_cleanup(bb_i);
-        rv = ap_get_brigade(c_i->input_filters, bb_i, AP_MODE_READBYTES,
-                            APR_NONBLOCK_READ, CONN_BLKSZ);
-        if (rv == APR_SUCCESS) {
-            if (c_o->aborted)
-                return APR_EPIPE;
-            if (APR_BRIGADE_EMPTY(bb_i))
-                break;
-#ifdef DEBUGGING
-            len = -1;
-            apr_brigade_length(bb_i, 0, &len);
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01016)
-                          "read %" APR_OFF_T_FMT
-                          " bytes from %s", len, name);
-#endif
-            ap_proxy_buckets_lifetime_transform(r, bb_i, bb_o);
-            rv = ap_pass_brigade(c_o->output_filters, bb_o);
-            if (rv == APR_SUCCESS) {
-                ap_fflush(c_o->output_filters, bb_o);
-            }
-            else {
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(01017)
-                              "error on %s - ap_pass_brigade",
-                              name);
-            }
-        } else if (!APR_STATUS_IS_EAGAIN(rv)) {
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(01018)
-                          "error on %s - ap_get_brigade",
-                          name);
-        }
-    } while (rv == APR_SUCCESS);
-
-    if (APR_STATUS_IS_EAGAIN(rv)) {
-        rv = APR_SUCCESS;
-    }
-    return rv;
-}
-
 /* CONNECT handler */
 static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
                                  proxy_server_conf *conf,
@@ -445,9 +396,12 @@ static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
                     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01025)
                                   "sock was readable");
 #endif
-                    done |= proxy_connect_transfer(r, backconn, c, bb_back,
-                                                   bb_front, "sock")
-                                                   != APR_SUCCESS;
+                    done |= ap_proxy_transfer_between_connections(r, backconn,
+                                                                  c, bb_back,
+                                                                  bb_front,
+                                                                  "sock", NULL,
+                                                                  CONN_BLKSZ, 1)
+                                                                 != APR_SUCCESS;
                 }
                 else if (pollevent & APR_POLLERR) {
                     ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(01026)
@@ -463,9 +417,14 @@ static int proxy_connect_handler(request_rec *r, proxy_worker *worker,
                     ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01027)
                                   "client was readable");
 #endif
-                    done |= proxy_connect_transfer(r, c, backconn, bb_front,
-                                                   bb_back, "client")
-                                                   != APR_SUCCESS;
+                    done |= ap_proxy_transfer_between_connections(r, c,
+                                                                  backconn,
+                                                                  bb_front,
+                                                                  bb_back,
+                                                                  "client",
+                                                                  NULL,
+                                                                  CONN_BLKSZ, 1)
+                                                                 != APR_SUCCESS;
                 }
                 else if (pollevent & APR_POLLERR) {
                     ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02827)
index 475038e03121d228146c2e5539a8b4b191cd8ac4..a2fd50563a9d580696688315d44878515f74547b 100644 (file)
@@ -37,11 +37,6 @@ typedef struct ws_baton_t {
     char *scheme;               /* required to release the proxy connection */
 } ws_baton_t;
 
-static apr_status_t proxy_wstunnel_transfer(request_rec *r,
-                                            conn_rec *c_i, conn_rec *c_o,
-                                            apr_bucket_brigade *bb_i,
-                                            apr_bucket_brigade *bb_o,
-                                            const char *name, int *sent);
 static void proxy_wstunnel_callback(void *b);
 
 static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_async) {
@@ -92,9 +87,12 @@ static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_as
                 if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
                     ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02446)
                             "sock was readable");
-                    done |= proxy_wstunnel_transfer(r, backconn, c, bb_i, bb_o,
-                                                    "sock", NULL)
-                                                    != APR_SUCCESS;
+                    done |= ap_proxy_transfer_between_connections(r, backconn,
+                                                                  c, bb_i, bb_o,
+                                                                  "sock", NULL,
+                                                                  AP_IOBUFSIZE,
+                                                                  0)
+                                                                 != APR_SUCCESS;
                 }
                 else if (pollevent & APR_POLLERR) {
                     ap_log_rerror(APLOG_MARK, APLOG_NOTICE, 0, r, APLOGNO(02447)
@@ -113,9 +111,13 @@ static int proxy_wstunnel_pump(ws_baton_t *baton, apr_time_t timeout, int try_as
                 if (pollevent & (APR_POLLIN | APR_POLLHUP)) {
                     ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02448)
                             "client was readable");
-                    done |= proxy_wstunnel_transfer(r, c, backconn, bb_o, bb_i,
-                                                    "client", &replied)
-                                                    != APR_SUCCESS;
+                    done |= ap_proxy_transfer_between_connections(r, c, backconn,
+                                                                  bb_o, bb_i,
+                                                                  "client",
+                                                                  &replied,
+                                                                  AP_IOBUFSIZE,
+                                                                  0)
+                                                                 != APR_SUCCESS;
                 }
                 else if (pollevent & APR_POLLERR) {
                     ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(02607)
@@ -272,65 +274,6 @@ static int proxy_wstunnel_canon(request_rec *r, char *url)
     return OK;
 }
 
-
-static apr_status_t proxy_wstunnel_transfer(request_rec *r,
-                                            conn_rec *c_i, conn_rec *c_o,
-                                            apr_bucket_brigade *bb_i,
-                                            apr_bucket_brigade *bb_o,
-                                            const char *name, int *sent)
-{
-    apr_status_t rv;
-#ifdef DEBUGGING
-    apr_off_t len;
-#endif
-
-    do {
-        apr_brigade_cleanup(bb_i);
-        rv = ap_get_brigade(c_i->input_filters, bb_i, AP_MODE_READBYTES,
-                            APR_NONBLOCK_READ, AP_IOBUFSIZE);
-        if (rv == APR_SUCCESS) {
-            if (c_o->aborted) {
-                return APR_EPIPE;
-            }
-            if (APR_BRIGADE_EMPTY(bb_i)) {
-                break;
-            }
-#ifdef DEBUGGING
-            len = -1;
-            apr_brigade_length(bb_i, 0, &len);
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02440)
-                          "read %" APR_OFF_T_FMT
-                          " bytes from %s", len, name);
-#endif
-            if (sent) {
-                *sent = 1;
-            }
-            ap_proxy_buckets_lifetime_transform(r, bb_i, bb_o);
-            rv = ap_pass_brigade(c_o->output_filters, bb_o);
-            if (rv == APR_SUCCESS) {
-                ap_fflush(c_o->output_filters, bb_o);
-            }
-            else {
-                ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r, APLOGNO(02441)
-                              "error on %s - ap_pass_brigade",
-                              name);
-            }
-        } else if (!APR_STATUS_IS_EAGAIN(rv) && !APR_STATUS_IS_EOF(rv)) {
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, rv, r, APLOGNO(02442)
-                          "error on %s - ap_get_brigade",
-                          name);
-        }
-    } while (rv == APR_SUCCESS);
-
-    ap_log_rerror(APLOG_MARK, APLOG_TRACE2, rv, r, "wstunnel_transfer complete");
-
-    if (APR_STATUS_IS_EAGAIN(rv)) {
-        rv = APR_SUCCESS;
-    }
-
-    return rv;
-}
-
 /*
  * process the request and write the response.
  */