]> granicus.if.org Git - apache/commitdiff
h2_repsonse across pool lifetimes implementation changed, no longer using calloc
authorStefan Eissing <icing@apache.org>
Mon, 24 Aug 2015 12:48:59 +0000 (12:48 +0000)
committerStefan Eissing <icing@apache.org>
Mon, 24 Aug 2015 12:48:59 +0000 (12:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1697370 13f79535-47bb-0310-9956-ffa450edef68

modules/http2/h2_conn.c
modules/http2/h2_h2.c
modules/http2/h2_io.c
modules/http2/h2_mplx.c
modules/http2/h2_response.c
modules/http2/h2_response.h
modules/http2/h2_session.c
modules/http2/h2_version.h

index 5430943860ac511fc96d6228a41dfad5d5cd15f6..f5a5819f8f75668d2d5f1e75cc868ee6f75cbfcf 100644 (file)
@@ -329,6 +329,28 @@ apr_status_t h2_session_process(h2_session *session)
 
 static void fix_event_conn(conn_rec *c, conn_rec *master);
 
+/*
+ * We would like to create the connection more lightweight like
+ * slave connections in 2.5-DEV. But we get 500 responses on long
+ * cgi tests in modules/h2.t as the script parsing seems to see an
+ * EOF from the cgi before anything is sent. 
+ *
+conn_rec *h2_conn_create(conn_rec *master, apr_pool_t *pool)
+{
+    conn_rec *c = (conn_rec *) apr_palloc(pool, sizeof(conn_rec));
+    
+    memcpy(c, master, sizeof(conn_rec));
+    c->id = (master->id & (long)pool);
+    c->slaves = NULL;
+    c->master = master;
+    c->input_filters = NULL;
+    c->output_filters = NULL;
+    c->pool = pool;
+    
+    return c;
+}
+*/
+
 conn_rec *h2_conn_create(conn_rec *master, apr_pool_t *pool)
 {
     apr_socket_t *socket;
index 6cb0f475e375decf570598dbc220202dbc3271eb..98b6ce77b9685b4cfeb8787c52ad39a92d71f3ae 100644 (file)
@@ -111,7 +111,6 @@ void h2_h2_register_hooks(void)
     ap_hook_process_connection(h2_h2_remove_timeout, 
                                mod_reqtimeout, NULL, APR_HOOK_LAST);
     
-    ap_hook_post_read_request(h2_h2_post_read_req, NULL, NULL, APR_HOOK_MIDDLE);
     /* With "H2SerializeHeaders On", we install the filter in this hook
      * that parses the response. This needs to happen before any other post
      * read function terminates the request with an error. Otherwise we will
index 9ce2e954d0cd60225ed280fbfb7a5f4963aad00c..09fe5055a0cae0bfa39349f2de48ea7e9fbcb203 100644 (file)
@@ -40,9 +40,6 @@ h2_io *h2_io_create(int id, apr_pool_t *pool, apr_bucket_alloc_t *bucket_alloc)
 
 static void h2_io_cleanup(h2_io *io)
 {
-    if (io->response) {
-        h2_response_cleanup(io->response);
-    }
 }
 
 void h2_io_destroy(h2_io *io)
index db460bd5281af12ba40af898dfdf5ceb527c3a7d..49656abbca016eabbd3dc478f52269c8725e825d 100644 (file)
@@ -555,10 +555,10 @@ static apr_status_t out_open(h2_mplx *m, int stream_id, h2_response *response,
         if (f) {
             ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, f->c,
                           "h2_mplx(%ld-%d): open response: %s",
-                          m->id, stream_id, response->headers->status);
+                          m->id, stream_id, response->status);
         }
         
-        h2_response_copy(io->response, response);
+        io->response = h2_response_copy(io->pool, response);
         h2_io_set_add(m->ready_ios, io);
         if (bb) {
             status = out_write(m, io, f, bb, iowait);
@@ -636,7 +636,7 @@ apr_status_t h2_mplx_out_close(h2_mplx *m, int stream_id)
         if (!m->aborted) {
             h2_io *io = h2_io_set_get(m->stream_ios, stream_id);
             if (io) {
-                if (!io->response->headers) {
+                if (!io->response->ngheader) {
                     /* In case a close comes before a response was created,
                      * insert an error one so that our streams can properly
                      * reset.
index 00c0e945384b48979cf66f93affea2f8423e2e0a..b464472c56152a16a77ada0f478ccc1af10c2450 100644 (file)
@@ -28,8 +28,9 @@
 #include "h2_util.h"
 #include "h2_response.h"
 
-static void convert_header(h2_response *response, apr_table_t *headers,
-                           const char *http_status, request_rec *r);
+static h2_ngheader *make_ngheader(apr_pool_t *pool, const char *status,
+                                  apr_table_t *header);
+
 static int ignore_header(const char *name) 
 {
     return (H2_HD_MATCH_LIT_CS("connection", name)
@@ -52,6 +53,7 @@ h2_response *h2_response_create(int stream_id,
     }
     
     response->stream_id = stream_id;
+    response->status = http_status;
     response->content_length = -1;
     
     if (hlines) {
@@ -93,9 +95,9 @@ h2_response *h2_response_create(int stream_id,
     else {
         header = apr_table_make(pool, 0);        
     }
-    
-    convert_header(response, header, http_status, NULL);
-    return response->headers? response : NULL;
+
+    response->rheader = header;
+    return response;
 }
 
 h2_response *h2_response_rcreate(int stream_id, request_rec *r,
@@ -107,34 +109,27 @@ h2_response *h2_response_rcreate(int stream_id, request_rec *r,
     }
     
     response->stream_id = stream_id;
+    response->status = apr_psprintf(pool, "%d", r->status);
     response->content_length = -1;
-    convert_header(response, header, apr_psprintf(pool, "%d", r->status), r);
+    response->rheader = header;
     
-    return response->headers? response : NULL;
-}
-
-void h2_response_cleanup(h2_response *response)
-{
-    if (response->headers) {
-        if (--response->headers->refs == 0) {
-            free(response->headers);
-        }
-        response->headers = NULL;
-    }
+    return response;
 }
 
 void h2_response_destroy(h2_response *response)
 {
-    h2_response_cleanup(response);
 }
 
-void h2_response_copy(h2_response *to, h2_response *from)
+h2_response *h2_response_copy(apr_pool_t *pool, h2_response *from)
 {
-    h2_response_cleanup(to);
-    *to = *from;
-    if (from->headers) {
-        ++from->headers->refs;
+    h2_response *to = apr_pcalloc(pool, sizeof(h2_response));
+    to->stream_id = from->stream_id;
+    to->status = apr_pstrdup(pool, from->status);
+    to->content_length = from->content_length;
+    if (from->rheader) {
+        to->ngheader = make_ngheader(pool, to->status, from->rheader);
     }
+    return to;
 }
 
 typedef struct {
@@ -143,12 +138,10 @@ typedef struct {
     size_t nvstrlen;
     size_t offset;
     char *strbuf;
-    h2_response *response;
-    int debug;
-    request_rec *r;
+    apr_pool_t *pool;
 } nvctx_t;
 
-static int count_headers(void *ctx, const char *key, const char *value)
+static int count_header(void *ctx, const char *key, const char *value)
 {
     if (!ignore_header(key)) {
         nvctx_t *nvctx = (nvctx_t*)ctx;
@@ -199,42 +192,33 @@ static int add_header(void *ctx, const char *key, const char *value)
 {
     if (!ignore_header(key)) {
         nvctx_t *nvctx = (nvctx_t*)ctx;
-        if (nvctx->debug) {
-            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_EINVAL, 
-                          nvctx->r, "h2_response(%d) header -> %s: %s",
-                          nvctx->response->stream_id, key, value);
-        }
-        NV_ADD_CS_CS(ctx, key, value);
+        NV_ADD_CS_CS(nvctx, key, value);
     }
     return 1;
 }
 
-static void convert_header(h2_response *response, apr_table_t *headers,
-                           const char *status, request_rec *r)
+static h2_ngheader *make_ngheader(apr_pool_t *pool, const char *status,
+                                  apr_table_t *header)
 {
     size_t n;
-    h2_headers *h;
-    nvctx_t ctx = { NULL, 1, strlen(status) + 1, 0, NULL, 
-        response, r? APLOGrdebug(r) : 0, r };
+    h2_ngheader *h;
+    nvctx_t ctx = { NULL, 1, strlen(status) + 1, 0, NULL, pool };
     
-    apr_table_do(count_headers, &ctx, headers, NULL);
+    apr_table_do(count_header, &ctx, header, NULL);
     
-    n =  (sizeof(h2_headers)
+    n =  (sizeof(h2_ngheader)
                  + (ctx.nvlen * sizeof(nghttp2_nv)) + ctx.nvstrlen); 
-    /* XXX: Why calloc, Why not on the pool of the request? */
-    h = calloc(1, n);
+    h = apr_pcalloc(pool, n);
     if (h) {
         ctx.nv = (nghttp2_nv*)(h + 1);
         ctx.strbuf = (char*)&ctx.nv[ctx.nvlen];
         
         NV_ADD_LIT_CS(&ctx, ":status", status);
-        apr_table_do(add_header, &ctx, headers, NULL);
+        apr_table_do(add_header, &ctx, header, NULL);
         
         h->nv = ctx.nv;
         h->nvlen = ctx.nvlen;
-        h->status = (const char *)ctx.nv[0].value;
-        h->refs = 1;
-        response->headers = h;
     }
+    return h;
 }
 
index d6174f5b688369257e38b540f152536eeb8cb7ed..456d2226ed28a9c4748484d54992a13560a5bcb1 100644 (file)
 /* h2_response is just the data belonging the the head of a HTTP response,
  * suitable prepared to be fed to nghttp2 for response submit. 
  */
-typedef struct h2_headers {
+typedef struct h2_ngheader {
     nghttp2_nv *nv;
     apr_size_t nvlen;
-    const char *status;
-    volatile int refs;
-} h2_headers;
+} h2_ngheader;
 
 typedef struct h2_response {
     int stream_id;
+    const char *status;
     apr_off_t content_length;
-    h2_headers *headers;
+    apr_table_t *rheader;
+    h2_ngheader *ngheader;
 } h2_response;
 
 h2_response *h2_response_create(int stream_id,
@@ -40,9 +40,8 @@ h2_response *h2_response_create(int stream_id,
 h2_response *h2_response_rcreate(int stream_id, request_rec *r,
                                  apr_table_t *header, apr_pool_t *pool);
 
-void h2_response_cleanup(h2_response *response);
 void h2_response_destroy(h2_response *response);
 
-void h2_response_copy(h2_response *to, h2_response *from);
+h2_response *h2_response_copy(apr_pool_t *pool, h2_response *from);
 
 #endif /* defined(__mod_h2__h2_response__) */
index 73faa65dc4026a9cf2e28c5d4ae21f78ebc61277..0ce33d095b176f5c1adcca3f571d033311c409a0 100644 (file)
@@ -1081,11 +1081,11 @@ static int submit_response(h2_session *session, h2_response *response)
     
     ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, session->c,
                   "h2_stream(%ld-%d): submitting response %s",
-                  session->id, response->stream_id, response->headers->status);
+                  session->id, response->stream_id, response->status);
     
     rv = nghttp2_submit_response(session->ngh2, response->stream_id,
-                                     response->headers->nv, 
-                                     response->headers->nvlen, &provider);
+                                 response->ngheader->nv, 
+                                 response->ngheader->nvlen, &provider);
     
     if (rv != 0) {
         ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, session->c,
@@ -1096,7 +1096,7 @@ static int submit_response(h2_session *session, h2_response *response)
         ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c,
                       "h2_stream(%ld-%d): submitted response %s, rv=%d",
                       session->id, response->stream_id, 
-                      response->headers->status, rv);
+                      response->status, rv);
     }
     return rv;
 }
@@ -1113,7 +1113,7 @@ apr_status_t h2_session_handle_response(h2_session *session, h2_stream *stream)
     AP_DEBUG_ASSERT(stream);
     AP_DEBUG_ASSERT(stream->response);
     
-    if (stream->response->headers) {
+    if (stream->response->ngheader) {
         rv = submit_response(session, stream->response);
     }
     else {
index ec761f895ef736e004b95f19b9b8462f47d02137..b253bef68ad2cc7e5ca8f1ca4482677e79a683c8 100644 (file)
@@ -20,7 +20,7 @@
  * @macro
  * Version number of the h2 module as c string
  */
-#define MOD_H2_VERSION "0.9.1"
+#define MOD_H2_VERSION "0.9.2"
 
 /**
  * @macro
@@ -28,7 +28,7 @@
  * release. This is a 24 bit number with 8 bits for major number, 8 bits
  * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
  */
-#define MOD_H2_VERSION_NUM 0x010000
+#define MOD_H2_VERSION_NUM 0x000902
 
 
 #endif /* mod_h2_h2_version_h */