-
Notifications
You must be signed in to change notification settings - Fork 75
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
tcp: connect: Add source_address and bind_device options #154
tcp: connect: Add source_address and bind_device options #154
Conversation
c9e4b29
to
7fc14e0
Compare
fac3e82
to
07fbb1d
Compare
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 for this hard-to-implement feature, I left a couple of comments
src/adapters/tcp.rs
Outdated
/// Bind the TCP connection to a specific interface, identified by its name. On other systems | ||
/// this opion will be ignored. |
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.
/// Bind the TCP connection to a specific interface, identified by its name. On other systems | |
/// this opion will be ignored. | |
/// Bind the TCP connection to a specific interface, identified by its name. | |
/// This option works in Unix, on other systems, it will be ignored. |
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.
oh yes, I changed that sentence multiple times. At some point I must have dropped the Unix part accidentally .
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.
No worries! usually happens 😆
#[cfg(unix)] | ||
Err(e) if e.raw_os_error() != Some(libc::EINPROGRESS) => return Err(e), | ||
#[cfg(windows)] | ||
Err(e) if e.kind() != io::ErrorKind::WouldBlock => return Err(e), |
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.
Ask from the unknowledge, could a WouldBlock
be obtained on Unix at this point (it seems like it's totally fine returning that for a socket implementation at this point)? In this case, an error will be returned when we shouldn't
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.
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.
Then it should be ok 👍🏻
07fbb1d
to
9f783b6
Compare
This option allows to specify the source address and port for outgoing TCP connections. Signed-off-by: Konrad Gräfe <[email protected]>
Add option to bind an outgoing TCP connection to a specific device, identified by its name. Signed-off-by: Konrad Gräfe <[email protected]>
9f783b6
to
41a9ef8
Compare
Thanks again for another awesome contribution! 🚀 |
This change allows binding an outgoing TCP connection to a specific network interface. My use-case for that is that I need to support situations where two interfaces are configured for link-local addressing. In that case the system has two different routes into the link-local subnet.
On Windows the interface is determined by the IP address passed to
bind()
. On Linux this is not sufficient as the routing table takes precedence. Therefore we must explicitly bind the socket to the interface.Depends on #153