-
Notifications
You must be signed in to change notification settings - Fork 70
Adding Support for Host Listeners #320
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
Conversation
cece967 to
bf8f174
Compare
b328e3e to
2316c79
Compare
11b90ed to
82a2faa
Compare
5c171a3 to
01a1628
Compare
| aws_host_listener_shutdown_fn *shutdown_callback; | ||
| void *user_data; | ||
|
|
||
| /* Synchronous data, requires host resolver lock to read/modify*/ |
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.
Let's put this in its own struct like we usually do, synced_data most likely
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.
The rest of the host resolver doesn't use that paradigm so I was worried it might be confusing to mix that in. Might be okay though!
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.
We should move toward it over time. For this one, I'd rather break consistency and use the right pattern.
source/host_resolver.c
Outdated
| AWS_ASSERT(new_address_list); | ||
| AWS_ASSERT(listener_list); | ||
|
|
||
| struct aws_linked_list_node *listener_node = aws_linked_list_begin(listener_list); |
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.
How do we not need to lock around modifying the listener list?
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.
Because this listener list is owned by the resolver thread, and only the resolver thread ever modifies it.
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.
Ok, can you make that clearer in the comments?
source/host_resolver.c
Outdated
| bool owned_by_resolver_thread; | ||
| bool pending_destroy; |
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.
Let's put these at the end of the structure, and bit pack them
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.
Will do!
| * struct aws_host_address *host_address = NULL; | ||
| * aws_array_list_get_at_ptr(new_address_list, (void **)&host_address, address_index); |
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.
trivial: It's very nice! But to keep the consistent, we may not need this tip?
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.
I've found getting a value out of an array list can be somewhat confusing. (I usually crash once!) So I liked calling that out here, but maybe it's overkill.
source/host_resolver.c
Outdated
| struct aws_host_listener *aws_host_resolver_add_host_listener( | ||
| struct aws_host_resolver *resolver, | ||
| const struct aws_host_listener_options *options) { | ||
| AWS_ASSERT(resolver); |
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.
trivial: AWS_PRECONDITION? Actually, I am not quite clear about the difference between this two macros..
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.
I was trying to keep this consistent with the existing aws_host_resolver functions. :)
source/host_resolver.c
Outdated
| } | ||
|
|
||
| int aws_host_resolver_remove_host_listener(struct aws_host_resolver *resolver, struct aws_host_listener *listener) { | ||
| AWS_ASSERT(resolver); |
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.
ditto
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.
Same as above!
source/host_resolver.c
Outdated
| /* Synchronous data, requires host resolver lock to read/modify*/ | ||
| bool owned_by_resolver_thread; | ||
| bool pending_destroy; | ||
| struct aws_linked_list_node node; |
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.
Is node also synchronous data? And, why don't we use the structure synced_data.
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.
It is, I was trying to keep this consistent with the way the rest of the host_resolver code is written, ie, no synced_data struct. But I'm going to do the synced_data approach.
| /* Structure for holding all listeners for a particular host name. */ | ||
| struct host_listener_entry { | ||
| struct default_host_resolver *resolver; | ||
| struct aws_linked_list listeners; |
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.
maybe comment about what's inside the linked_list? Is that struct host_listener?
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.
Will do!
source/host_resolver.c
Outdated
| * Any time the listener list in the listener entry becomes empty, we remove the entry from the table. This | ||
| * includes when a resolver thread moves all of the available listeners to its local list. | ||
| */ | ||
| /* host_name (string) -> host_listener_entry */ |
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.
Trivial: I feel it might be better to point it out that it stores the pointer of host_listener_entry. But, yeah, basically, it will be only pointers stored in the table. So, ignore this if the other way is more consistent.
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.
I think it's okay but adding the asterisk won't hurt. :)
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.
yeah, because there was a bug in aws-c-mqtt that we stored pointer in array or table, but we forgot it...
source/host_resolver.c
Outdated
|
|
||
| /* Notify all listeners with resolve address callbacks, and also clean up any that are waiting to be cleaned up. */ | ||
| /* Assumes no lock is held. */ | ||
| static void s_resolver_thread_update_listeners( |
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.
maybe it will be more clear to comment that the listener_list is a local list, so it doesn't need to be protected by a lock?
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.
Will do!
049c34d to
db49aea
Compare
fb736e1 to
781fdbc
Compare
6bb6c49 to
a774d4b
Compare
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.