Codechange: allow Connect() to bind to a local address #9127
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.
Motivation / Problem
For STUN I need a method that a
connect()
can be bound to a local address (to reuse a local address, as that is what STUN does). I was looking for a clean way to implement this.I see two methods of doing this:
connect_bind_address
variable toNetworkAddress
, and passthis
fromResolve()
intofunc
so it can read this address again. This is a lot of poking holes, and adds a variable specific for one flow (out of the three that exist).NetworkAddress
toConnectLoopProc
directly.In this PR I present the second option, mostly as my C++ knowledge is not sufficient to know if there are any downsides to this approach.
Description
It uses a capture lambda to inject some extra parameters to the callback function, without anything in between knowing about it.
Limitations
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.