httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ic...@apache.org
Subject svn commit: r1734434 - in /httpd/httpd/trunk/modules/http2: h2_io.c h2_io.h
Date Thu, 10 Mar 2016 17:06:58 GMT
Author: icing
Date: Thu Mar 10 17:06:57 2016
New Revision: 1734434

URL: http://svn.apache.org/viewvc?rev=1734434&view=rev
Log:
mod_http2: some more code cleanup

Modified:
    httpd/httpd/trunk/modules/http2/h2_io.c
    httpd/httpd/trunk/modules/http2/h2_io.h

Modified: httpd/httpd/trunk/modules/http2/h2_io.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_io.c?rev=1734434&r1=1734433&r2=1734434&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_io.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_io.c Thu Mar 10 17:06:57 2016
@@ -49,10 +49,28 @@ static void check_bbin(h2_io *io)
 {
     if (!io->bbin) {
         io->bbin = apr_brigade_create(io->pool, io->bucket_alloc);
-        io->tmp = apr_brigade_create(io->pool, io->bucket_alloc);
     }
 }
 
+static void check_bbout(h2_io *io)
+{
+    if (!io->bbout) {
+        io->bbout = apr_brigade_create(io->pool, io->bucket_alloc);
+    }
+}
+
+static void check_bbtmp(h2_io *io)
+{
+    if (!io->bbtmp) {
+        io->bbtmp = apr_brigade_create(io->pool, io->bucket_alloc);
+    }
+}
+
+static void append_eos(h2_io *io, apr_bucket_brigade *bb)
+{
+    APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(io->bucket_alloc));
+}
+
 void h2_io_redo(h2_io *io)
 {
     io->worker_started = 0;
@@ -64,8 +82,8 @@ void h2_io_redo(h2_io *io)
     if (io->bbout) {
         apr_brigade_cleanup(io->bbout);
     }
-    if (io->tmp) {
-        apr_brigade_cleanup(io->tmp);
+    if (io->bbtmp) {
+        apr_brigade_cleanup(io->bbtmp);
     }
     io->started_at = io->done_at = 0;
 }
@@ -196,8 +214,8 @@ static int add_trailer(void *ctx, const
     return (status == APR_SUCCESS);
 }
 
-static apr_status_t append_eos(h2_io *io, apr_bucket_brigade *bb, 
-                               apr_table_t *trailers)
+static apr_status_t in_append_eos(h2_io *io, apr_bucket_brigade *bb, 
+                                  apr_table_t *trailers)
 {
     apr_status_t status = APR_SUCCESS;
     apr_table_t *t = io->request->trailers;
@@ -219,7 +237,7 @@ static apr_status_t append_eos(h2_io *io
             status = apr_brigade_puts(bb, NULL, NULL, "0\r\n\r\n");
         }
     }
-    APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_eos_create(io->bucket_alloc));
+    append_eos(io, bb);
     return status;
 }
 
@@ -236,7 +254,7 @@ apr_status_t h2_io_in_read(h2_io *io, ap
     if (!io->bbin || APR_BRIGADE_EMPTY(io->bbin)) {
         if (io->eos_in) {
             if (!io->eos_in_written) {
-                status = append_eos(io, bb, trailers);
+                status = in_append_eos(io, bb, trailers);
                 io->eos_in_written = 1;
                 return status;
             }
@@ -247,26 +265,27 @@ apr_status_t h2_io_in_read(h2_io *io, ap
     
     if (io->request->chunked) {
         /* the reader expects HTTP/1.1 chunked encoding */
-        status = h2_util_move(io->tmp, io->bbin, maxlen, NULL, "h2_io_in_read_chunk");
+        check_bbtmp(io);
+        status = h2_util_move(io->bbtmp, io->bbin, maxlen, NULL, "h2_io_in_read_chunk");
         if (status == APR_SUCCESS) {
             apr_off_t tmp_len = 0;
             
-            apr_brigade_length(io->tmp, 1, &tmp_len);
+            apr_brigade_length(io->bbtmp, 1, &tmp_len);
             if (tmp_len > 0) {
                 io->input_consumed += tmp_len;
                 status = apr_brigade_printf(bb, NULL, NULL, "%lx\r\n", 
                                             (unsigned long)tmp_len);
                 if (status == APR_SUCCESS) {
-                    status = h2_util_move(bb, io->tmp, -1, NULL, "h2_io_in_read_tmp1");
+                    status = h2_util_move(bb, io->bbtmp, -1, NULL, "h2_io_in_read_tmp1");
                     if (status == APR_SUCCESS) {
                         status = apr_brigade_puts(bb, NULL, NULL, "\r\n");
                     }
                 }
             }
             else {
-                status = h2_util_move(bb, io->tmp, -1, NULL, "h2_io_in_read_tmp2");
+                status = h2_util_move(bb, io->bbtmp, -1, NULL, "h2_io_in_read_tmp2");
             }
-            apr_brigade_cleanup(io->tmp);
+            apr_brigade_cleanup(io->bbtmp);
         }
     }
     else {
@@ -283,7 +302,7 @@ apr_status_t h2_io_in_read(h2_io *io, ap
     if (status == APR_SUCCESS && (!io->bbin || APR_BRIGADE_EMPTY(io->bbin)))
{
         if (io->eos_in) {
             if (!io->eos_in_written) {
-                status = append_eos(io, bb, trailers);
+                status = in_append_eos(io, bb, trailers);
                 io->eos_in_written = 1;
             }
         }
@@ -324,27 +343,36 @@ apr_status_t h2_io_in_close(h2_io *io)
     return APR_SUCCESS;
 }
 
-apr_status_t h2_io_out_readx(h2_io *io,  
-                             h2_io_data_cb *cb, void *ctx, 
-                             apr_off_t *plen, int *peos)
+static int is_out_readable(h2_io *io, apr_off_t *plen, int *peos, 
+                           apr_status_t *ps)
 {
-    apr_status_t status;
-    
     if (io->rst_error) {
-        return APR_ECONNABORTED;
+        *ps = APR_ECONNABORTED;
+        return 0;
     }
-    
     if (io->eos_out_read) {
         *plen = 0;
         *peos = 1;
-        return APR_SUCCESS;
+        *ps = APR_SUCCESS;
+        return 0;
     }
     else if (!io->bbout) {
         *plen = 0;
         *peos = 0;
-        return APR_EAGAIN;
+        *ps = APR_EAGAIN;
+        return 0;
+    }
+    return 1;
+}
+
+apr_status_t h2_io_out_readx(h2_io *io,  
+                             h2_io_data_cb *cb, void *ctx, 
+                             apr_off_t *plen, int *peos)
+{
+    apr_status_t status;
+    if (!is_out_readable(io, plen, peos, &status)) {
+        return status;
     }
-    
     if (cb == NULL) {
         /* just checking length available */
         status = h2_util_bb_avail(io->bbout, plen, peos);
@@ -356,7 +384,6 @@ apr_status_t h2_io_out_readx(h2_io *io,
             io->output_consumed += *plen;
         }
     }
-    
     return status;
 }
 
@@ -364,22 +391,9 @@ apr_status_t h2_io_out_read_to(h2_io *io
                                apr_off_t *plen, int *peos)
 {
     apr_status_t status;
-    
-    if (io->rst_error) {
-        return APR_ECONNABORTED;
-    }
-    
-    if (io->eos_out_read) {
-        *plen = 0;
-        *peos = 1;
-        return APR_SUCCESS;
-    }
-    else if (!io->bbout) {
-        *plen = 0;
-        *peos = 0;
-        return APR_EAGAIN;
+    if (!is_out_readable(io, plen, peos, &status)) {
+        return status;
     }
-
     io->eos_out_read = *peos = h2_util_has_eos(io->bbout, *plen);
     status = h2_util_move(bb, io->bbout, *plen, NULL, "h2_io_read_to");
     io->output_consumed += *plen;
@@ -424,9 +438,6 @@ apr_status_t h2_io_out_write(h2_io *io,
     }
 
     process_trailers(io, trailers);
-    if (!io->bbout) {
-        io->bbout = apr_brigade_create(io->pool, io->bucket_alloc);
-    }
     
     /* Let's move the buckets from the request processing in here, so
      * that the main thread can read them when it has time/capacity.
@@ -438,6 +449,7 @@ apr_status_t h2_io_out_write(h2_io *io,
      * many open files already buffered. Otherwise we will run out of
      * file handles.
      */
+    check_bbout(io);
     start_allowed = *pfile_buckets_allowed;
     status = h2_util_move(io->bbout, bb, maxlen, pfile_buckets_allowed, 
                           "h2_io_out_write");
@@ -456,14 +468,11 @@ apr_status_t h2_io_out_close(h2_io *io,
     }
     if (!io->eos_out_read) { /* EOS has not been read yet */
         process_trailers(io, trailers);
-        if (!io->bbout) {
-            io->bbout = apr_brigade_create(io->pool, io->bucket_alloc);
-        }
         if (!io->eos_out) {
+            check_bbout(io);
             io->eos_out = 1;
             if (!h2_util_has_eos(io->bbout, -1)) {
-                APR_BRIGADE_INSERT_TAIL(io->bbout, 
-                                        apr_bucket_eos_create(io->bucket_alloc));
+                append_eos(io, io->bbout);
             }
         }
     }

Modified: httpd/httpd/trunk/modules/http2/h2_io.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_io.h?rev=1734434&r1=1734433&r2=1734434&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_io.h (original)
+++ httpd/httpd/trunk/modules/http2/h2_io.h Thu Mar 10 17:06:57 2016
@@ -46,7 +46,7 @@ struct h2_io {
 
     apr_bucket_brigade *bbin;        /* input data for stream */
     apr_bucket_brigade *bbout;       /* output data from stream */
-    apr_bucket_brigade *tmp;         /* temporary data for chunking */
+    apr_bucket_brigade *bbtmp;       /* temporary data for chunking */
 
     unsigned int orphaned       : 1; /* h2_stream is gone for this io */    
     unsigned int worker_started : 1; /* h2_worker started processing for this io */



Mime
View raw message