From 0ae48563e50f814c8b64cfd868e3cbfa54a07f66 Mon Sep 17 00:00:00 2001 From: "Jonathan M. Henson" Date: Fri, 6 Mar 2020 12:53:58 -0800 Subject: [PATCH] Exposed options for toggling read back pressure behavior, updated to match aws-c-io api changes. --- include/aws/http/connection.h | 5 ++++ include/aws/http/connection_manager.h | 5 ++++ include/aws/http/server.h | 5 ++++ source/connection.c | 36 +++++++++++++-------------- source/connection_manager.c | 13 +++++++--- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/include/aws/http/connection.h b/include/aws/http/connection.h index d59eb29df..dc8dfb5f3 100644 --- a/include/aws/http/connection.h +++ b/include/aws/http/connection.h @@ -208,6 +208,11 @@ struct aws_http_client_connection_options { * See `aws_http_on_client_connection_shutdown_fn`. */ aws_http_on_client_connection_shutdown_fn *on_shutdown; + + /** + * If set to true, read back pressure mechanism will be enabled. + */ + bool enable_read_back_pressure; }; /** diff --git a/include/aws/http/connection_manager.h b/include/aws/http/connection_manager.h index 8c12d5640..acd7d99b1 100644 --- a/include/aws/http/connection_manager.h +++ b/include/aws/http/connection_manager.h @@ -64,6 +64,11 @@ struct aws_http_connection_manager_options { */ void *shutdown_complete_user_data; aws_http_connection_manager_shutdown_complete_fn *shutdown_complete_callback; + + /** + * If set to true, the read back pressure mechanism will be enabled. + */ + bool enable_read_back_pressure; }; AWS_EXTERN_C_BEGIN diff --git a/include/aws/http/server.h b/include/aws/http/server.h index fa7029336..ef9eadfcd 100644 --- a/include/aws/http/server.h +++ b/include/aws/http/server.h @@ -103,6 +103,11 @@ struct aws_http_server_options { * Optional. */ aws_http_server_on_destroy_fn *on_destroy_complete; + + /** + * If set to true, read back pressure mechanism will be enabled. + */ + bool enable_read_back_pressure; }; /** diff --git a/source/connection.c b/source/connection.c index 343c5085b..c8b3b485a 100644 --- a/source/connection.c +++ b/source/connection.c @@ -487,26 +487,23 @@ struct aws_http_server *aws_http_server_new(const struct aws_http_server_options s_server_lock_synced_data(server); if (options->tls_options) { server->is_using_tls = true; - - server->socket = aws_server_bootstrap_new_tls_socket_listener( - options->bootstrap, - options->endpoint, - options->socket_options, - options->tls_options, - s_server_bootstrap_on_accept_channel_setup, - s_server_bootstrap_on_accept_channel_shutdown, - s_server_bootstrap_on_server_listener_destroy, - server); - } else { - server->socket = aws_server_bootstrap_new_socket_listener( - options->bootstrap, - options->endpoint, - options->socket_options, - s_server_bootstrap_on_accept_channel_setup, - s_server_bootstrap_on_accept_channel_shutdown, - s_server_bootstrap_on_server_listener_destroy, - server); } + + struct aws_server_socket_channel_bootstrap_options bootstrap_options = { + .enable_read_back_pressure = options->enable_read_back_pressure, + .tls_options = options->tls_options, + .bootstrap = options->bootstrap, + .socket_options = options->socket_options, + .incoming_callback = s_server_bootstrap_on_accept_channel_setup, + .shutdown_callback = s_server_bootstrap_on_accept_channel_shutdown, + .destroy_callback = s_server_bootstrap_on_server_listener_destroy, + .host_name = options->endpoint->address, + .port = options->endpoint->port, + .user_data = server, + }; + + server->socket = aws_server_bootstrap_new_socket_listener(&bootstrap_options); + s_server_unlock_synced_data(server); if (!server->socket) { @@ -769,6 +766,7 @@ int aws_http_client_connect_internal( .tls_options = options->tls_options, .setup_callback = s_client_bootstrap_on_channel_setup, .shutdown_callback = s_client_bootstrap_on_channel_shutdown, + .enable_read_back_pressure = options->enable_read_back_pressure, .user_data = http_bootstrap, }; diff --git a/source/connection_manager.c b/source/connection_manager.c index 2ec5b4e93..cce7f11d9 100644 --- a/source/connection_manager.c +++ b/source/connection_manager.c @@ -207,6 +207,11 @@ struct aws_http_connection_manager { * a hybrid atomic/lock solution felt excessively complicated and delicate. */ size_t external_ref_count; + + /* + * if set to true, read back pressure mechanism will be enabled. + */ + bool enable_read_back_pressure; }; struct aws_http_connection_manager_snapshot { @@ -560,12 +565,11 @@ struct aws_http_connection_manager *aws_http_connection_manager_new( } struct aws_http_connection_manager *manager = - aws_mem_acquire(allocator, sizeof(struct aws_http_connection_manager)); + aws_mem_calloc(allocator, 1, sizeof(struct aws_http_connection_manager)); if (manager == NULL) { return NULL; } - AWS_ZERO_STRUCT(*manager); manager->allocator = allocator; if (aws_mutex_init(&manager->lock)) { @@ -612,6 +616,7 @@ struct aws_http_connection_manager *aws_http_connection_manager_new( manager->external_ref_count = 1; manager->shutdown_complete_callback = options->shutdown_complete_callback; manager->shutdown_complete_user_data = options->shutdown_complete_user_data; + manager->enable_read_back_pressure = options->enable_read_back_pressure; AWS_LOGF_INFO(AWS_LS_HTTP_CONNECTION_MANAGER, "id=%p: Successfully created", (void *)manager); @@ -686,6 +691,7 @@ static int s_aws_http_connection_manager_new_connection(struct aws_http_connecti options.socket_options = &manager->socket_options; options.on_setup = s_aws_http_connection_manager_on_connection_setup; options.on_shutdown = s_aws_http_connection_manager_on_connection_shutdown; + options.enable_read_back_pressure = manager->enable_read_back_pressure; if (aws_http_connection_monitoring_options_is_valid(&manager->monitoring_options)) { options.monitoring_options = &manager->monitoring_options; @@ -844,13 +850,12 @@ void aws_http_connection_manager_acquire_connection( AWS_LOGF_DEBUG(AWS_LS_HTTP_CONNECTION_MANAGER, "id=%p: Acquire connection", (void *)manager); struct aws_http_connection_acquisition *request = - aws_mem_acquire(manager->allocator, sizeof(struct aws_http_connection_acquisition)); + aws_mem_calloc(manager->allocator, 1, sizeof(struct aws_http_connection_acquisition)); if (request == NULL) { callback(NULL, aws_last_error(), user_data); return; } - AWS_ZERO_STRUCT(*request); request->callback = callback; request->user_data = user_data;