-
Notifications
You must be signed in to change notification settings - Fork 48
Connection manager #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ec05a26
WIP
c90fd32
First draft of connection manager
f08703b
WIP
e0bcdc1
WIP
c3e4726
Simple set of integration tests for connection manager
d563af9
More tests and fixes
0301c63
Logging, invariants, bug fixes
320b63d
Merge branch 'master' into ConnectionManager
02c3400
Formatting
75533f3
Merge branch 'master' into ConnectionManager
bretambrose d3de760
clang tidy/logic
ab5217f
Merge branch 'ConnectionManager' of github.com:awslabs/aws-c-http int…
40aa1fd
more clang tidy
20aa022
tidy
006d11a
Function pointer messiness
2451c6f
WIP
cb447e6
CR Feedback + snapshot logging
104ec04
Merge branch 'master' into ConnectionManager
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #ifndef AWS_HTTP_CONNECTION_MANAGER_H | ||
| #define AWS_HTTP_CONNECTION_MANAGER_H | ||
|
|
||
| /* | ||
| * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| #include <aws/http/http.h> | ||
|
|
||
| #include <aws/common/byte_buf.h> | ||
|
|
||
| struct aws_client_bootstrap; | ||
| struct aws_http_connection; | ||
| struct aws_http_connection_manager; | ||
| struct aws_http_connection_manager_mocks; | ||
| struct aws_socket_options; | ||
| struct aws_tls_connection_options; | ||
|
|
||
| typedef void(aws_http_connection_manager_on_connection_setup_fn)( | ||
| struct aws_http_connection *connection, | ||
| int error_code, | ||
| void *user_data); | ||
|
|
||
| /* | ||
| * Connection manager configuration struct. | ||
| * | ||
| * Contains all of the configuration needed to create an http connection as well as | ||
| * the maximum number of connections to ever have in existence. | ||
| */ | ||
| struct aws_http_connection_manager_options { | ||
| /* | ||
| * http connection configuration | ||
| */ | ||
| struct aws_client_bootstrap *bootstrap; | ||
| size_t initial_window_size; | ||
| struct aws_socket_options *socket_options; | ||
| struct aws_tls_connection_options *tls_connection_options; | ||
| struct aws_byte_cursor host; | ||
| uint16_t port; | ||
|
|
||
| /* | ||
| * Maximum number of connections this manager is allowed to contain | ||
| */ | ||
| size_t max_connections; | ||
| }; | ||
|
|
||
| AWS_EXTERN_C_BEGIN | ||
|
|
||
| /* | ||
| * Connection managers are ref counted. Adds one external ref to the manager. | ||
| */ | ||
| AWS_HTTP_API | ||
| void aws_http_connection_manager_acquire(struct aws_http_connection_manager *manager); | ||
|
|
||
| /* | ||
| * Connection managers are ref counted. Removes one external ref from the manager. | ||
| * | ||
| * When the ref count goes to zero, the connection manager begins its shut down | ||
| * process. All pending connection acquisitions are failed (with callbacks | ||
| * invoked) and any (erroneous) subsequent attempts to acquire a connection | ||
| * fail immediately. The connection manager destroys itself once all pending | ||
| * asynchronous activities have resolved. | ||
| */ | ||
| AWS_HTTP_API | ||
| void aws_http_connection_manager_release(struct aws_http_connection_manager *manager); | ||
|
|
||
| /* | ||
| * Creates a new connection manager with the supplied configuration options. | ||
| * | ||
| * The returned connection manager begins with a ref count of 1. | ||
| */ | ||
| AWS_HTTP_API | ||
| struct aws_http_connection_manager *aws_http_connection_manager_new( | ||
| struct aws_allocator *allocator, | ||
| struct aws_http_connection_manager_options *options); | ||
|
|
||
| /* | ||
| * Requests a connection from the manager. The requester is notified of | ||
| * an acquired connection (or failure to acquire) via the supplied callback. | ||
| * | ||
| * Once a connection has been successfully acquired from the manager it | ||
| * must be released back (via aws_http_connection_manager_release_connection) | ||
| * at some point. Failure to do so will cause a resource leak. | ||
| */ | ||
| AWS_HTTP_API | ||
| void aws_http_connection_manager_acquire_connection( | ||
| struct aws_http_connection_manager *manager, | ||
| aws_http_connection_manager_on_connection_setup_fn *callback, | ||
| void *user_data); | ||
|
|
||
| /* | ||
| * Returns a connection back to the manager. All acquired connections must | ||
| * eventually be released back to the manager in order to avoid a resource leak. | ||
| */ | ||
| AWS_HTTP_API | ||
| int aws_http_connection_manager_release_connection( | ||
| struct aws_http_connection_manager *manager, | ||
| struct aws_http_connection *connection); | ||
|
|
||
| AWS_EXTERN_C_END | ||
|
|
||
| #endif /* AWS_HTTP_CONNECTION_MANAGER_H */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
include/aws/http/private/connection_manager_function_table.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #ifndef AWS_HTTP_CONNECTION_MANAGER_FUNCTION_TABLE_H | ||
| #define AWS_HTTP_CONNECTION_MANAGER_FUNCTION_TABLE_H | ||
|
|
||
| /* | ||
| * Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| #include <aws/http/http.h> | ||
|
|
||
| #include <aws/http/connection.h> | ||
|
|
||
| typedef int(aws_http_connection_manager_create_connection_fn)(const struct aws_http_client_connection_options *options); | ||
| typedef void(aws_http_connection_manager_close_connection_fn)(struct aws_http_connection *connection); | ||
| typedef void(aws_http_connection_manager_release_connection_fn)(struct aws_http_connection *connection); | ||
| typedef bool(aws_http_connection_manager_is_connection_open_fn)(const struct aws_http_connection *connection); | ||
|
|
||
| struct aws_http_connection_manager_function_table { | ||
| /* | ||
| * Downstream http functions | ||
| */ | ||
| aws_http_connection_manager_create_connection_fn *create_connection; | ||
| aws_http_connection_manager_close_connection_fn *close_connection; | ||
| aws_http_connection_manager_release_connection_fn *release_connection; | ||
| aws_http_connection_manager_is_connection_open_fn *is_connection_open; | ||
| }; | ||
|
|
||
| AWS_HTTP_API | ||
| bool aws_http_connection_manager_function_table_is_valid( | ||
| const struct aws_http_connection_manager_function_table *table); | ||
|
|
||
| AWS_HTTP_API | ||
| void aws_http_connection_manager_set_function_table( | ||
| struct aws_http_connection_manager *manager, | ||
| const struct aws_http_connection_manager_function_table *function_table); | ||
|
|
||
| AWS_HTTP_API | ||
| extern const struct aws_http_connection_manager_function_table | ||
| *g_aws_http_connection_manager_default_function_table_ptr; | ||
|
|
||
| #endif /* AWS_HTTP_CONNECTION_MANAGER_FUNCTION_TABLE_H */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.