Skip to content

Commit 4be9631

Browse files
committed
changes from ACP feedback
1 parent f7d3a1a commit 4be9631

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

library/std/src/os/unix/net/datagram.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use libc::MSG_NOSIGNAL;
1616
use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary};
1717
use super::{sockaddr_un, SocketAddr};
1818
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
19-
use crate::ffi::{CStr, CString};
19+
use crate::ffi::CString;
2020
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
2121
use crate::io::{IoSlice, IoSliceMut};
2222
use crate::net::Shutdown;
@@ -848,19 +848,19 @@ impl UnixDatagram {
848848
not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")),
849849
doc = "```ignore"
850850
)]
851-
/// #![feature(unix_set_todevice)]
851+
/// #![feature(unix_set_device)]
852852
/// use std::os::unix::net::UnixDatagram;
853853
///
854854
/// fn main() -> std::io::Result<()> {
855855
/// let socket = UnixDatagram::unbound()?;
856-
/// socket.set_todevice(c"eth0")?;
856+
/// socket.set_device("eth0")?;
857857
/// Ok(())
858858
/// }
859859
/// ```
860860
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
861-
#[unstable(feature = "unix_set_todevice", issue = "129182")]
862-
pub fn set_todevice(&self, ifrname: &CStr) -> io::Result<()> {
863-
self.0.set_todevice(ifrname)
861+
#[unstable(feature = "unix_set_device", issue = "129182")]
862+
pub fn set_device(&self, ifrname: &str) -> io::Result<()> {
863+
self.0.set_device(ifrname)
864864
}
865865

866866
/// Get the interface this socket is bound to
@@ -873,21 +873,21 @@ impl UnixDatagram {
873873
not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")),
874874
doc = "```ignore"
875875
)]
876-
/// #![feature(unix_set_todevice)]
876+
/// #![feature(unix_set_device)]
877877
/// use std::os::unix::net::UnixDatagram;
878878
///
879879
/// fn main() -> std::io::Result<()> {
880880
/// let socket = UnixDatagram::unbound()?;
881-
/// socket.set_todevice(c"eth0")?;
882-
/// let name = socket.todevice()?;
881+
/// socket.set_device("eth0")?;
882+
/// let name = socket.device()?;
883883
/// assert_eq!(Ok("eth0"), name.to_str());
884884
/// Ok(())
885885
/// }
886886
/// ```
887887
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
888-
#[unstable(feature = "unix_set_todevice", issue = "129182")]
889-
pub fn todevice(&self) -> io::Result<CString> {
890-
self.0.todevice()
888+
#[unstable(feature = "unix_set_device", issue = "129182")]
889+
pub fn device(&self) -> io::Result<CString> {
890+
self.0.device()
891891
}
892892
/// Returns the value of the `SO_ERROR` option.
893893
///

library/std/src/os/unix/net/stream.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use super::{peer_cred, UCred};
1313
use super::{recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to, SocketAncillary};
1414
use super::{sockaddr_un, SocketAddr};
1515
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
16-
use crate::ffi::{CStr, CString};
16+
use crate::ffi::CString;
1717
use crate::fmt;
1818
use crate::io::{self, IoSlice, IoSliceMut};
1919
use crate::net::Shutdown;
@@ -417,19 +417,19 @@ impl UnixStream {
417417
not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")),
418418
doc = "```ignore"
419419
)]
420-
/// #![feature(unix_set_todevice)]
420+
/// #![feature(unix_set_device)]
421421
/// use std::os::unix::net::UnixStream;
422422
///
423423
/// fn main() -> std::io::Result<()> {
424424
/// let socket = UnixStream::connect("/tmp/sock")?;
425-
/// socket.set_todevice(c"eth0")?;
425+
/// socket.set_device("eth0")?;
426426
/// Ok(())
427427
/// }
428428
/// ```
429429
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
430-
#[unstable(feature = "unix_set_todevice", issue = "129182")]
431-
pub fn set_todevice(&self, ifrname: &CStr) -> io::Result<()> {
432-
self.0.set_todevice(ifrname)
430+
#[unstable(feature = "unix_set_device", issue = "129182")]
431+
pub fn set_device(&self, ifrname: &str) -> io::Result<()> {
432+
self.0.set_device(ifrname)
433433
}
434434

435435
/// Get the interface this socket is bound to
@@ -442,21 +442,21 @@ impl UnixStream {
442442
not(any(target_os = "linux", target_os = "haiku", target_os = "vxworks")),
443443
doc = "```ignore"
444444
)]
445-
/// #![feature(unix_set_todevice)]
445+
/// #![feature(unix_set_device)]
446446
/// use std::os::unix::net::UnixStream;
447447
///
448448
/// fn main() -> std::io::Result<()> {
449449
/// let socket = UnixStream::connect("/tmp/sock")?;
450-
/// socket.set_todevice(c"eth0")?;
451-
/// let name = socket.todevice()?;
450+
/// socket.set_device("eth0")?;
451+
/// let name = socket.device()?;
452452
/// assert_eq!(Ok("eth0"), name.to_str());
453453
/// Ok(())
454454
/// }
455455
/// ```
456456
#[cfg(any(doc, target_os = "linux", target_os = "haiku", target_os = "vxworks",))]
457-
#[unstable(feature = "unix_set_todevice", issue = "129182")]
458-
pub fn todevice(&self) -> io::Result<CString> {
459-
self.0.todevice()
457+
#[unstable(feature = "unix_set_device", issue = "129182")]
458+
pub fn device(&self) -> io::Result<CString> {
459+
self.0.device()
460460
}
461461

462462
/// Returns the value of the `SO_ERROR` option.

library/std/src/sys/pal/unix/net.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ impl Socket {
564564
}
565565

566566
#[cfg(any(target_os = "linux", target_os = "haiku", target_os = "vxworks"))]
567-
pub fn todevice(&self) -> io::Result<crate::ffi::CString> {
567+
pub fn device(&self) -> io::Result<crate::ffi::CString> {
568568
let buf: [libc::c_char; libc::IFNAMSIZ] =
569569
getsockopt(self, libc::SOL_SOCKET, libc::SO_BINDTODEVICE)?;
570570
let s: &[u8] = unsafe { core::slice::from_raw_parts(buf.as_ptr() as *const u8, buf.len()) };
@@ -573,8 +573,8 @@ impl Socket {
573573
}
574574

575575
#[cfg(any(target_os = "linux", target_os = "haiku", target_os = "vxworks"))]
576-
pub fn set_todevice(&self, ifrname: &CStr) -> io::Result<()> {
577-
let istr = ifrname.to_bytes();
576+
pub fn set_device(&self, ifrname: &str) -> io::Result<()> {
577+
let istr = ifrname.as_bytes();
578578

579579
if istr.len() >= libc::IFNAMSIZ {
580580
return Err(io::Error::from_raw_os_error(libc::ENAMETOOLONG));

0 commit comments

Comments
 (0)