Skip to content
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

Codechange: allow Connect() to bind to a local address #9127

Closed
wants to merge 1 commit into from

Conversation

TrueBrain
Copy link
Member

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:

  1. add a connect_bind_address variable to NetworkAddress, and pass this from Resolve() into func 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).
  2. use a lambda with a capture to bypass all this and only send the NetworkAddress to ConnectLoopProc 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

This is currently not used, but later commits will make use of
this.

It uses a capture lambda to inject some extra parameters to the callback function, without anything in between knowing about it.

Limitations

  • During testing this works, but I have no clue how many compilers accept this (should be C++17?)
  • My C++ knowledge is limited, so I pieced this together from what LordAro told me last week, but please, look at this carefully :)

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

This is currently not used, but later commits will make use of
this.
@TrueBrain
Copy link
Member Author

Will be part of future PR that uses this.

@TrueBrain TrueBrain closed this Apr 28, 2021
@TrueBrain TrueBrain deleted the network-connect-options branch April 28, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant