Skip to content

Commit 8920d15

Browse files
committed
unix: Non-mutable bufs in send_vectored_with_ancillary_to
1 parent e792288 commit 8920d15

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

library/std/src/sys/unix/ext/net/ancillary.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{sockaddr_un, SocketAddr};
22
use crate::convert::TryFrom;
3-
use crate::io::{self, IoSliceMut};
3+
use crate::io::{self, IoSlice, IoSliceMut};
44
use crate::marker::PhantomData;
55
use crate::mem::{size_of, zeroed};
66
use crate::os::unix::io::RawFd;
@@ -68,7 +68,7 @@ pub(super) fn recv_vectored_with_ancillary_from(
6868
pub(super) fn send_vectored_with_ancillary_to(
6969
socket: &Socket,
7070
path: Option<&Path>,
71-
bufs: &mut [IoSliceMut<'_>],
71+
bufs: &[IoSlice<'_>],
7272
ancillary: &mut SocketAncillary<'_>,
7373
) -> io::Result<usize> {
7474
unsafe {
@@ -78,7 +78,7 @@ pub(super) fn send_vectored_with_ancillary_to(
7878
let mut msg: libc::msghdr = zeroed();
7979
msg.msg_name = &mut msg_name as *mut _ as *mut _;
8080
msg.msg_namelen = msg_namelen;
81-
msg.msg_iov = bufs.as_mut_ptr().cast();
81+
msg.msg_iov = bufs as *const _ as *mut _;
8282
msg.msg_control = ancillary.buffer.as_mut_ptr().cast();
8383
cfg_if::cfg_if! {
8484
if #[cfg(any(target_os = "android", all(target_os = "linux", target_env = "gnu")))] {
@@ -563,7 +563,7 @@ impl<'a> SocketAncillary<'a> {
563563
/// #![feature(unix_socket_ancillary_data)]
564564
/// use std::os::unix::net::{UnixStream, SocketAncillary};
565565
/// use std::os::unix::io::AsRawFd;
566-
/// use std::io::IoSliceMut;
566+
/// use std::io::IoSlice;
567567
///
568568
/// fn main() -> std::io::Result<()> {
569569
/// let sock = UnixStream::connect("/tmp/sock")?;
@@ -573,7 +573,7 @@ impl<'a> SocketAncillary<'a> {
573573
/// ancillary.add_fds(&[sock.as_raw_fd()][..]);
574574
///
575575
/// let mut buf = [1; 8];
576-
/// let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..];
576+
/// let mut bufs = &[IoSlice::new(&mut buf[..])][..];
577577
/// sock.send_vectored_with_ancillary(bufs, &mut ancillary)?;
578578
/// Ok(())
579579
/// }

library/std/src/sys/unix/ext/net/datagram.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use super::{sockaddr_un, SocketAddr};
1919
target_os = "netbsd",
2020
target_os = "openbsd",
2121
))]
22-
use crate::io::IoSliceMut;
22+
use crate::io::{IoSlice, IoSliceMut};
2323
use crate::net::Shutdown;
2424
use crate::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
2525
use crate::path::Path;
@@ -506,17 +506,17 @@ impl UnixDatagram {
506506
/// ```no_run
507507
/// #![feature(unix_socket_ancillary_data)]
508508
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
509-
/// use std::io::IoSliceMut;
509+
/// use std::io::IoSlice;
510510
///
511511
/// fn main() -> std::io::Result<()> {
512512
/// let sock = UnixDatagram::unbound()?;
513513
/// let mut buf1 = [1; 8];
514514
/// let mut buf2 = [2; 16];
515515
/// let mut buf3 = [3; 8];
516-
/// let mut bufs = &mut [
517-
/// IoSliceMut::new(&mut buf1),
518-
/// IoSliceMut::new(&mut buf2),
519-
/// IoSliceMut::new(&mut buf3),
516+
/// let mut bufs = &[
517+
/// IoSlice::new(&mut buf1),
518+
/// IoSlice::new(&mut buf2),
519+
/// IoSlice::new(&mut buf3),
520520
/// ][..];
521521
/// let fds = [0, 1, 2];
522522
/// let mut ancillary_buffer = [0; 128];
@@ -538,7 +538,7 @@ impl UnixDatagram {
538538
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
539539
pub fn send_vectored_with_ancillary_to<P: AsRef<Path>>(
540540
&self,
541-
bufs: &mut [IoSliceMut<'_>],
541+
bufs: &[IoSlice<'_>],
542542
ancillary: &mut SocketAncillary<'_>,
543543
path: P,
544544
) -> io::Result<usize> {
@@ -554,17 +554,17 @@ impl UnixDatagram {
554554
/// ```no_run
555555
/// #![feature(unix_socket_ancillary_data)]
556556
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
557-
/// use std::io::IoSliceMut;
557+
/// use std::io::IoSlice;
558558
///
559559
/// fn main() -> std::io::Result<()> {
560560
/// let sock = UnixDatagram::unbound()?;
561561
/// let mut buf1 = [1; 8];
562562
/// let mut buf2 = [2; 16];
563563
/// let mut buf3 = [3; 8];
564-
/// let mut bufs = &mut [
565-
/// IoSliceMut::new(&mut buf1),
566-
/// IoSliceMut::new(&mut buf2),
567-
/// IoSliceMut::new(&mut buf3),
564+
/// let mut bufs = &[
565+
/// IoSlice::new(&mut buf1),
566+
/// IoSlice::new(&mut buf2),
567+
/// IoSlice::new(&mut buf3),
568568
/// ][..];
569569
/// let fds = [0, 1, 2];
570570
/// let mut ancillary_buffer = [0; 128];
@@ -586,7 +586,7 @@ impl UnixDatagram {
586586
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
587587
pub fn send_vectored_with_ancillary(
588588
&self,
589-
bufs: &mut [IoSliceMut<'_>],
589+
bufs: &[IoSlice<'_>],
590590
ancillary: &mut SocketAncillary<'_>,
591591
) -> io::Result<usize> {
592592
send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary)

library/std/src/sys/unix/ext/net/stream.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,17 @@ impl UnixStream {
530530
/// ```no_run
531531
/// #![feature(unix_socket_ancillary_data)]
532532
/// use std::os::unix::net::{UnixStream, SocketAncillary};
533-
/// use std::io::IoSliceMut;
533+
/// use std::io::IoSlice;
534534
///
535535
/// fn main() -> std::io::Result<()> {
536536
/// let socket = UnixStream::connect("/tmp/sock")?;
537537
/// let mut buf1 = [1; 8];
538538
/// let mut buf2 = [2; 16];
539539
/// let mut buf3 = [3; 8];
540-
/// let mut bufs = &mut [
541-
/// IoSliceMut::new(&mut buf1),
542-
/// IoSliceMut::new(&mut buf2),
543-
/// IoSliceMut::new(&mut buf3),
540+
/// let mut bufs = &[
541+
/// IoSlice::new(&mut buf1),
542+
/// IoSlice::new(&mut buf2),
543+
/// IoSlice::new(&mut buf3),
544544
/// ][..];
545545
/// let fds = [0, 1, 2];
546546
/// let mut ancillary_buffer = [0; 128];
@@ -562,7 +562,7 @@ impl UnixStream {
562562
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
563563
pub fn send_vectored_with_ancillary(
564564
&self,
565-
bufs: &mut [IoSliceMut<'_>],
565+
bufs: &[IoSlice<'_>],
566566
ancillary: &mut SocketAncillary<'_>,
567567
) -> io::Result<usize> {
568568
send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary)

library/std/src/sys/unix/ext/net/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ fn test_send_vectored_fds_unix_stream() {
486486
let (s1, s2) = or_panic!(UnixStream::pair());
487487

488488
let mut buf1 = [1; 8];
489-
let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..];
489+
let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..];
490490

491491
let mut ancillary1_buffer = [0; 128];
492492
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);
@@ -543,7 +543,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {
543543
or_panic!(bsock2.set_passcred(true));
544544

545545
let mut buf1 = [1; 8];
546-
let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..];
546+
let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..];
547547

548548
let mut ancillary1_buffer = [0; 128];
549549
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);
@@ -604,7 +604,7 @@ fn test_send_vectored_with_ancillary_unix_datagram() {
604604
let bsock2 = or_panic!(UnixDatagram::bind(&path2));
605605

606606
let mut buf1 = [1; 8];
607-
let mut bufs_send = &mut [IoSliceMut::new(&mut buf1[..])][..];
607+
let mut bufs_send = &[IoSlice::new(&mut buf1[..])][..];
608608

609609
let mut ancillary1_buffer = [0; 128];
610610
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);

0 commit comments

Comments
 (0)