-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
std::net: adding new option todevice. #129172
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ use super::{peer_cred, UCred}; | |
| #[cfg(any(doc, target_os = "android", target_os = "linux"))] | ||
| use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary}; | ||
| use super::{sockaddr_un, SocketAddr}; | ||
| #[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))] | ||
| use crate::ffi::CString; | ||
| use crate::fmt; | ||
| use crate::io::{self, IoSlice, IoSliceMut}; | ||
| use crate::net::Shutdown; | ||
|
|
@@ -405,6 +407,58 @@ impl UnixStream { | |
| self.0.set_mark(mark) | ||
| } | ||
|
|
||
| /// Bind the socket to an interface | ||
| /// | ||
| #[cfg_attr( | ||
| any(target_os = "linux", target_os = "haiku", target_os = "vxworks"), | ||
| doc = "```no_run" | ||
| )] | ||
| #[cfg_attr( | ||
| not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")), | ||
| doc = "```ignore" | ||
| )] | ||
| /// #![feature(unix_set_device)] | ||
| /// use std::os::unix::net::UnixStream; | ||
| /// | ||
| /// fn main() -> std::io::Result<()> { | ||
| /// let socket = UnixStream::connect("/tmp/sock")?; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this using The examples should be things expected to work.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wait, it looks like these are being added to UNIX sockets? Shouldn't these be for TCP/UDP, not UNIX? |
||
| /// socket.set_device("eth0")?; | ||
| /// Ok(()) | ||
| /// } | ||
| /// ``` | ||
| #[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))] | ||
| #[unstable(feature = "unix_set_device", issue = "129182")] | ||
| pub fn set_device(&self, ifrname: &str) -> io::Result<()> { | ||
| self.0.set_device(ifrname) | ||
| } | ||
|
|
||
| /// Get the interface this socket is bound to | ||
| /// | ||
| #[cfg_attr( | ||
| any(target_os = "linux", target_os = "haiku", target_os = "vxworks"), | ||
| doc = "```no_run" | ||
| )] | ||
| #[cfg_attr( | ||
| not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")), | ||
| doc = "```ignore" | ||
| )] | ||
| /// #![feature(unix_set_device)] | ||
| /// use std::os::unix::net::UnixStream; | ||
| /// | ||
| /// fn main() -> std::io::Result<()> { | ||
| /// let socket = UnixStream::connect("/tmp/sock")?; | ||
| /// socket.set_device("eth0")?; | ||
| /// let name = socket.device()?; | ||
| /// assert_eq!(Ok("eth0"), name.to_str()); | ||
| /// Ok(()) | ||
| /// } | ||
| /// ``` | ||
| #[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))] | ||
| #[unstable(feature = "unix_set_device", issue = "129182")] | ||
| pub fn device(&self) -> io::Result<CString> { | ||
| self.0.device() | ||
| } | ||
|
|
||
| /// Returns the value of the `SO_ERROR` option. | ||
| /// | ||
| /// # Examples | ||
|
|
||
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.
Something seems odd here.
The assertion fails.