You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gm...@apache.org on 2021/03/17 19:43:04 UTC

[qpid-dispatch] branch master updated: DISPATCH-2005: Combined two loops into one in handle_incoming_http to yield a minor performance improvement

This is an automated email from the ASF dual-hosted git repository.

gmurthy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-dispatch.git


The following commit(s) were added to refs/heads/master by this push:
     new 2042f66  DISPATCH-2005: Combined two loops into one in handle_incoming_http to yield a minor performance improvement
2042f66 is described below

commit 2042f6605a0d32929684a7b43e3748b8039d5497
Author: Ganesh Murthy <gm...@apache.org>
AuthorDate: Wed Mar 17 15:42:35 2021 -0400

    DISPATCH-2005: Combined two loops into one in handle_incoming_http to yield a minor performance improvement
---
 src/adaptors/http2/http2_adaptor.c | 80 +++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 44 deletions(-)

diff --git a/src/adaptors/http2/http2_adaptor.c b/src/adaptors/http2/http2_adaptor.c
index 788b613..f7f4258 100644
--- a/src/adaptors/http2/http2_adaptor.c
+++ b/src/adaptors/http2/http2_adaptor.c
@@ -1963,15 +1963,16 @@ static int handle_incoming_http(qdr_http2_connection_t *conn)
 
     }
 
-    qd_http2_buffer_list_t buffers;
-    DEQ_INIT(buffers);
     pn_raw_buffer_t raw_buffers[READ_BUFFERS];
     size_t n;
     int count = 0;
+    int rv = 0;
 
     if (!conn->pn_raw_conn)
         return 0;
 
+    bool close_conn = false;
+
     while ( (n = pn_raw_connection_take_read_buffers(conn->pn_raw_conn, raw_buffers, READ_BUFFERS)) ) {
         for (size_t i = 0; i < n && raw_buffers[i].bytes; ++i) {
             qd_http2_buffer_t *buf = (qd_http2_buffer_t*) raw_buffers[i].context;
@@ -1979,61 +1980,52 @@ static int handle_incoming_http(qdr_http2_connection_t *conn)
             uint32_t raw_buff_size = raw_buffers[i].size;
             qd_http2_buffer_insert(buf, raw_buff_size);
             count += raw_buff_size;
-            DEQ_INSERT_TAIL(buffers, buf);
-        }
-    }
 
-    //
-    // Read each buffer in the buffer chain and call nghttp2_session_mem_recv with buffer content
-    //
-    qd_http2_buffer_t *buf = DEQ_HEAD(buffers);
-    qd_http2_buffer_t *curr_buf = 0;
+            if (raw_buff_size > 0 && !close_conn) {
+                qd_log(http2_adaptor->log_source, QD_LOG_DEBUG, "[C%"PRIu64"] handle_incoming_http - Calling nghttp2_session_mem_recv qd_http2_buffer of size %"PRIu32" ", conn->conn_id, raw_buff_size);
+                rv = nghttp2_session_mem_recv(conn->session_data->session, qd_http2_buffer_base(buf), qd_http2_buffer_size(buf));
+                if (rv < 0) {
+                    qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] Error in nghttp2_session_mem_recv rv=%i", conn->conn_id, rv);
+                    if (rv == NGHTTP2_ERR_FLOODED) {
+                        // Flooding was detected in this HTTP/2 session, and it must be closed. This is most likely caused by misbehavior of peer.
+                        // If the client magic is bad, we need to close the connection.
+                        qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP NGHTTP2_ERR_FLOODED", conn->conn_id);
+                        nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Protocol Error", 14);
+                    }
+                    else if (rv == NGHTTP2_ERR_CALLBACK_FAILURE) {
+                        qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP NGHTTP2_ERR_CALLBACK_FAILURE", conn->conn_id);
+                        nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Internal Error", 14);
+                    }
+                    else if (rv == NGHTTP2_ERR_BAD_CLIENT_MAGIC) {
+                        qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP2 Protocol error, NGHTTP2_ERR_BAD_CLIENT_MAGIC, closing connection", conn->conn_id);
+                        nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Bad Client Magic", 16);
+                    }
+                    else {
+                        nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Protocol Error", 14);
+                    }
+                    nghttp2_session_send(conn->session_data->session);
 
-    int rv = 0;
-    while (buf) {
-        size_t http2_buffer_size = qd_http2_buffer_size(buf);
-        if (http2_buffer_size > 0) {
-            qd_log(http2_adaptor->log_source, QD_LOG_DEBUG, "[C%"PRIu64"] handle_incoming_http - Calling nghttp2_session_mem_recv qd_http2_buffer of size %"PRIu32" ", conn->conn_id, http2_buffer_size);
-            rv = nghttp2_session_mem_recv(conn->session_data->session, qd_http2_buffer_base(buf), qd_http2_buffer_size(buf));
-            if (rv < 0) {
-                qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] Error in nghttp2_session_mem_recv rv=%i", conn->conn_id, rv);
-                if (rv == NGHTTP2_ERR_FLOODED) {
-                    // Flooding was detected in this HTTP/2 session, and it must be closed. This is most likely caused by misbehavior of peer.
-                    // If the client magic is bad, we need to close the connection.
-                    qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP NGHTTP2_ERR_FLOODED", conn->conn_id);
-                    nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Protocol Error", 14);
-                }
-                else if (rv == NGHTTP2_ERR_CALLBACK_FAILURE) {
-                    qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP NGHTTP2_ERR_CALLBACK_FAILURE", conn->conn_id);
-                    nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Internal Error", 14);
-                }
-                else if (rv == NGHTTP2_ERR_BAD_CLIENT_MAGIC) {
-                    qd_log(http2_adaptor->protocol_log_source, QD_LOG_ERROR, "[C%"PRIu64"] HTTP2 Protocol error, NGHTTP2_ERR_BAD_CLIENT_MAGIC, closing connection", conn->conn_id);
-                    nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Bad Client Magic", 16);
-                }
-                else {
-                    nghttp2_submit_goaway(conn->session_data->session, 0, 0, NGHTTP2_PROTOCOL_ERROR, (uint8_t *)"Protocol Error", 14);
+                    //
+                    // An error was received from nghttp2, the connection needs to be closed.
+                    //
+                    close_conn = true;
                 }
-                nghttp2_session_send(conn->session_data->session);
-                pn_raw_connection_close(conn->pn_raw_conn);
-                break;
             }
+            free_qd_http2_buffer_t(buf);
         }
-        curr_buf = buf;
-        DEQ_REMOVE_HEAD(buffers);
-        buf = DEQ_HEAD(buffers);
-        free_qd_http2_buffer_t(curr_buf);
     }
 
-    if (rv > 0)
+    if (close_conn) {
+        pn_raw_connection_close(conn->pn_raw_conn);
+    }
+    else {
         grant_read_buffers(conn);
-
+    }
     nghttp2_session_send(conn-> session_data->session);
 
     return count;
 }
 
-
 qdr_http2_connection_t *qdr_http_connection_ingress_accept(qdr_http2_connection_t* ingress_http_conn)
 {
     ingress_http_conn->remote_address = get_address_string(ingress_http_conn->pn_raw_conn);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org