From 8920d1514f6bd7f1182f163e717fd76badb084a3 Mon Sep 17 00:00:00 2001 From: Lukas Lihotzki Date: Sun, 6 Dec 2020 16:16:21 +0100 Subject: [PATCH] unix: Non-mutable bufs in send_vectored_with_ancillary_to --- library/std/src/sys/unix/ext/net/ancillary.rs | 10 +++---- library/std/src/sys/unix/ext/net/datagram.rs | 26 +++++++++---------- library/std/src/sys/unix/ext/net/stream.rs | 12 ++++----- library/std/src/sys/unix/ext/net/tests.rs | 6 ++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/library/std/src/sys/unix/ext/net/ancillary.rs b/library/std/src/sys/unix/ext/net/ancillary.rs index 2c91ba70dd0b5..ec1acdcddcb5a 100644 --- a/library/std/src/sys/unix/ext/net/ancillary.rs +++ b/library/std/src/sys/unix/ext/net/ancillary.rs @@ -1,6 +1,6 @@ use super::{sockaddr_un, SocketAddr}; use crate::convert::TryFrom; -use crate::io::{self, IoSliceMut}; +use crate::io::{self, IoSlice, IoSliceMut}; use crate::marker::PhantomData; use crate::mem::{size_of, zeroed}; use crate::os::unix::io::RawFd; @@ -68,7 +68,7 @@ pub(super) fn recv_vectored_with_ancillary_from( pub(super) fn send_vectored_with_ancillary_to( socket: &Socket, path: Option<&Path>, - bufs: &mut [IoSliceMut<'_>], + bufs: &[IoSlice<'_>], ancillary: &mut SocketAncillary<'_>, ) -> io::Result { unsafe { @@ -78,7 +78,7 @@ pub(super) fn send_vectored_with_ancillary_to( let mut msg: libc::msghdr = zeroed(); msg.msg_name = &mut msg_name as *mut _ as *mut _; msg.msg_namelen = msg_namelen; - msg.msg_iov = bufs.as_mut_ptr().cast(); + msg.msg_iov = bufs as *const _ as *mut _; msg.msg_control = ancillary.buffer.as_mut_ptr().cast(); cfg_if::cfg_if! { if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] { @@ -563,7 +563,7 @@ impl<'a> SocketAncillary<'a> { /// #![feature(unix_socket_ancillary_data)] /// use std::os::unix::net::{UnixStream, SocketAncillary}; /// use std::os::unix::io::AsRawFd; - /// use std::io::IoSliceMut; + /// use std::io::IoSlice; /// /// fn main() -> std::io::Result<()> { /// let sock = UnixStream::connect("/tmp/sock")?; @@ -573,7 +573,7 @@ impl<'a> SocketAncillary<'a> { /// ancillary.add_fds(&[sock.as_raw_fd()][..]); /// /// let mut buf = [1; 8]; - /// let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..]; + /// let mut bufs = &[IoSlice::new(&mut buf[..])][..]; /// sock.send_vectored_with_ancillary(bufs, &mut ancillary)?; /// Ok(()) /// } diff --git a/library/std/src/sys/unix/ext/net/datagram.rs b/library/std/src/sys/unix/ext/net/datagram.rs index 0f532c47c8f92..74de1138fd1e7 100644 --- a/library/std/src/sys/unix/ext/net/datagram.rs +++ b/library/std/src/sys/unix/ext/net/datagram.rs @@ -19,7 +19,7 @@ use super::{sockaddr_un, SocketAddr}; target_os = "netbsd", target_os = "openbsd", ))] -use crate::io::IoSliceMut; +use crate::io::{IoSlice, IoSliceMut}; use crate::net::Shutdown; use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use crate::path::Path; @@ -506,17 +506,17 @@ impl UnixDatagram { /// ```no_run /// #![feature(unix_socket_ancillary_data)] /// use std::os::unix::net::{UnixDatagram, SocketAncillary}; - /// use std::io::IoSliceMut; + /// use std::io::IoSlice; /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// let mut buf1 = [1; 8]; /// let mut buf2 = [2; 16]; /// let mut buf3 = [3; 8]; - /// let mut bufs = &mut [ - /// IoSliceMut::new(&mut buf1), - /// IoSliceMut::new(&mut buf2), - /// IoSliceMut::new(&mut buf3), + /// let mut bufs = &[ + /// IoSlice::new(&mut buf1), + /// IoSlice::new(&mut buf2), + /// IoSlice::new(&mut buf3), /// ][..]; /// let fds = [0, 1, 2]; /// let mut ancillary_buffer = [0; 128]; @@ -538,7 +538,7 @@ impl UnixDatagram { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn send_vectored_with_ancillary_to>( &self, - bufs: &mut [IoSliceMut<'_>], + bufs: &[IoSlice<'_>], ancillary: &mut SocketAncillary<'_>, path: P, ) -> io::Result { @@ -554,17 +554,17 @@ impl UnixDatagram { /// ```no_run /// #![feature(unix_socket_ancillary_data)] /// use std::os::unix::net::{UnixDatagram, SocketAncillary}; - /// use std::io::IoSliceMut; + /// use std::io::IoSlice; /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// let mut buf1 = [1; 8]; /// let mut buf2 = [2; 16]; /// let mut buf3 = [3; 8]; - /// let mut bufs = &mut [ - /// IoSliceMut::new(&mut buf1), - /// IoSliceMut::new(&mut buf2), - /// IoSliceMut::new(&mut buf3), + /// let mut bufs = &[ + /// IoSlice::new(&mut buf1), + /// IoSlice::new(&mut buf2), + /// IoSlice::new(&mut buf3), /// ][..]; /// let fds = [0, 1, 2]; /// let mut ancillary_buffer = [0; 128]; @@ -586,7 +586,7 @@ impl UnixDatagram { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn send_vectored_with_ancillary( &self, - bufs: &mut [IoSliceMut<'_>], + bufs: &[IoSlice<'_>], ancillary: &mut SocketAncillary<'_>, ) -> io::Result { send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary) diff --git a/library/std/src/sys/unix/ext/net/stream.rs b/library/std/src/sys/unix/ext/net/stream.rs index 9fe6b85837e33..bb45e435e9583 100644 --- a/library/std/src/sys/unix/ext/net/stream.rs +++ b/library/std/src/sys/unix/ext/net/stream.rs @@ -530,17 +530,17 @@ impl UnixStream { /// ```no_run /// #![feature(unix_socket_ancillary_data)] /// use std::os::unix::net::{UnixStream, SocketAncillary}; - /// use std::io::IoSliceMut; + /// use std::io::IoSlice; /// /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let mut buf1 = [1; 8]; /// let mut buf2 = [2; 16]; /// let mut buf3 = [3; 8]; - /// let mut bufs = &mut [ - /// IoSliceMut::new(&mut buf1), - /// IoSliceMut::new(&mut buf2), - /// IoSliceMut::new(&mut buf3), + /// let mut bufs = &[ + /// IoSlice::new(&mut buf1), + /// IoSlice::new(&mut buf2), + /// IoSlice::new(&mut buf3), /// ][..]; /// let fds = [0, 1, 2]; /// let mut ancillary_buffer = [0; 128]; @@ -562,7 +562,7 @@ impl UnixStream { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn send_vectored_with_ancillary( &self, - bufs: &mut [IoSliceMut<'_>], + bufs: &[IoSlice<'_>], ancillary: &mut SocketAncillary<'_>, ) -> io::Result { send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary) diff --git a/library/std/src/sys/unix/ext/net/tests.rs b/library/std/src/sys/unix/ext/net/tests.rs index 97a016904b4a4..b2044b6367bb2 100644 --- a/library/std/src/sys/unix/ext/net/tests.rs +++ b/library/std/src/sys/unix/ext/net/tests.rs @@ -486,7 +486,7 @@ fn test_send_vectored_fds_unix_stream() { let (s1, s2) = or_panic!(UnixStream::pair()); let mut buf1 = [1; 8]; - let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..]; + let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..]; let mut ancillary1_buffer = [0; 128]; let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]); @@ -543,7 +543,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() { or_panic!(bsock2.set_passcred(true)); let mut buf1 = [1; 8]; - let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..]; + let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..]; let mut ancillary1_buffer = [0; 128]; let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]); @@ -604,7 +604,7 @@ fn test_send_vectored_with_ancillary_unix_datagram() { let bsock2 = or_panic!(UnixDatagram::bind(&path2)); let mut buf1 = [1; 8]; - let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..]; + let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..]; let mut ancillary1_buffer = [0; 128]; let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);