-
Notifications
You must be signed in to change notification settings - Fork 42
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
Bind to a list of Network Interfaces #471
Changes from 18 commits
0a1eed3
0a28f71
65caced
213bd12
283caf0
1d7ecec
0225d80
cf0db5c
3a88295
039d96e
fedc27b
fdeb101
ba4e9ec
aa888ab
625d270
f911659
1eacac3
c48c24d
a0edccb
f6765f5
2a6636a
47ce3ee
469f910
a07346f
b252fd1
e1fcf62
ed135f5
32ea361
3529a2a
aa1a512
eb32171
545b4e9
3f123bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -292,6 +292,17 @@ struct aws_http_connection_manager { | |||||
*/ | ||||||
struct aws_task *cull_task; | ||||||
struct aws_event_loop *cull_event_loop; | ||||||
|
||||||
/* | ||||||
* An aws_array_list<struct aws_string *> of network interface names to distribute the connections using the | ||||||
* round-robin algorithm. We picked round-robin because it is trivial to implement and good enough. We can later | ||||||
* update to a more complex distribution algorithm if required. | ||||||
*/ | ||||||
struct aws_array_list network_interface_names_list; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trivial:
Suggested change
|
||||||
/* | ||||||
* Current index in the network_interface_names list. | ||||||
*/ | ||||||
size_t network_interface_names_list_index; | ||||||
}; | ||||||
|
||||||
struct aws_http_connection_manager_snapshot { | ||||||
|
@@ -703,6 +714,13 @@ static void s_aws_http_connection_manager_finish_destroy(struct aws_http_connect | |||||
aws_http_proxy_config_destroy(manager->proxy_config); | ||||||
} | ||||||
|
||||||
for (size_t i = 0; i < aws_array_list_length(&manager->network_interface_names_list); i++) { | ||||||
struct aws_string *interface_name = NULL; | ||||||
aws_array_list_get_at(&manager->network_interface_names_list, &interface_name, i); | ||||||
aws_string_destroy(interface_name); | ||||||
} | ||||||
aws_array_list_clean_up(&manager->network_interface_names_list); | ||||||
|
||||||
/* | ||||||
* If this task exists then we are actually in the corresponding event loop running the final destruction task. | ||||||
* In that case, we've already cancelled this task and when you cancel, it runs synchronously. So in that | ||||||
|
@@ -896,6 +914,25 @@ struct aws_http_connection_manager *aws_http_connection_manager_new( | |||||
manager->max_closed_streams = options->max_closed_streams; | ||||||
manager->http2_conn_manual_window_management = options->http2_conn_manual_window_management; | ||||||
|
||||||
manager->network_interface_names_list_index = 0; | ||||||
size_t network_interface_names_list_length = options->network_interface_names_list != NULL | ||||||
? aws_array_list_length(options->network_interface_names_list) | ||||||
: 0; | ||||||
/* Ignore the network_interface_names_list if socket_options already contains a network_interface_name. */ | ||||||
if (manager->socket_options.network_interface_name[0] == '\0' && network_interface_names_list_length > 0) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debatable: maybe raise an error if both are set? instead of silently ignoring one of them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, updated. |
||||||
aws_array_list_init_dynamic( | ||||||
&manager->network_interface_names_list, | ||||||
allocator, | ||||||
network_interface_names_list_length, | ||||||
sizeof(struct aws_string *)); | ||||||
for (size_t i = 0; i < network_interface_names_list_length; i++) { | ||||||
struct aws_byte_cursor interface_name; | ||||||
aws_array_list_get_at(options->network_interface_names_list, &interface_name, i); | ||||||
struct aws_string *interface_name_str = aws_string_new_from_cursor(allocator, &interface_name); | ||||||
aws_array_list_push_back(&manager->network_interface_names_list, &interface_name_str); | ||||||
} | ||||||
} | ||||||
|
||||||
/* NOTHING can fail after here */ | ||||||
s_schedule_connection_culling(manager); | ||||||
|
||||||
|
@@ -990,7 +1027,23 @@ static int s_aws_http_connection_manager_new_connection(struct aws_http_connecti | |||||
options.host_name = aws_byte_cursor_from_string(manager->host); | ||||||
options.port = manager->port; | ||||||
options.initial_window_size = manager->initial_window_size; | ||||||
options.socket_options = &manager->socket_options; | ||||||
struct aws_socket_options socket_options = manager->socket_options; | ||||||
if (aws_array_list_length(&manager->network_interface_names_list)) { | ||||||
struct aws_string *interface_name = NULL; | ||||||
aws_array_list_get_at( | ||||||
&manager->network_interface_names_list, &interface_name, manager->network_interface_names_list_index); | ||||||
manager->network_interface_names_list_index = (manager->network_interface_names_list_index + 1) % | ||||||
aws_array_list_length(&manager->network_interface_names_list); | ||||||
#if defined(_MSC_VER) | ||||||
# pragma warning(push) | ||||||
# pragma warning(disable : 4996) /* deprecation */ | ||||||
waahm7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#endif | ||||||
strncpy(socket_options.network_interface_name, aws_string_c_str(interface_name), AWS_NETWORK_INTERFACE_MAX_LEN); | ||||||
graebm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#if defined(_MSC_VER) | ||||||
# pragma warning(pop) | ||||||
#endif | ||||||
} | ||||||
options.socket_options = &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.manual_window_management = manager->enable_read_back_pressure; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have users pass a normal-ass C-array, and separate length.
There's already precedent for this, see a few lines up:
It's simpler for everyone to just use vanilla C arrays. Most uses of this will be in language bindings, and most other languages have their own easier-to-use way to create an array. C++ users can do:
std::vector<aws_byte_cursor> names
and pass it likenames.data(), names.size()
. C users can still useaws_array_list
if they want, and pass a pointer to the first item. Or simply useaws_mem_calloc()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, in S3, the precedence is array list for checksum algorithms list. I debated between char *[16] and aws_array_arraylist, but aws_byte_cursor * seems much nicer. I will update it to that.