-
Notifications
You must be signed in to change notification settings - Fork 28
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
Simplify handling of sockaddr information lookup #38
Conversation
With a custom deleter, we must take care to also delete the pointer managed by the unique_ptr.
Rather than gethostbyname and then manually constructing a struct sockaddr_in, make the lookup IPv6-agnostic by using getaddrinfo directly.
Rather than heap-allocating the endpoint parameters, as well as the addrinfo, stack allocate the endpoint parameters and use a unique_ptr managed heap allocation for addrinfo. This is safe because endpoint and listener creation copies the addrinfo data upon initialisation.
Now that this just returns an addrinfo struct, the previous name was misleading.
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 @wence- , this looks great! I left a few suggestions on style, and one typo fix (which is not even modified in this PR but I catched and suggested it anyway).
Thanks, done! |
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 Lawrence!
I just squashed the remaining few places where param structs were separated from initialisation. |
/merge |
Migrate away from using
gethostbyname
(deprecated) togetaddrinfo
. As a consequence, we can refactor some memory management and handle allocation lifetime with aunique_ptr
.Although this doesn't introduce a class for managing sockaddr objects, it does make the lifetime management transparent enough that this closes #8.