Skip to content

Commit 9e4e739

Browse files
committed
unix: Non-mutable bufs in send_vectored_with_ancillary_to
Change the arguments of `send_vectored_with_ancillary` and `send_vectored_with_ancillary_to` to take an non-mutable bufs.
1 parent 8e863eb commit 9e4e739

File tree

4 files changed

+48
-45
lines changed

4 files changed

+48
-45
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_ptr() 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")))] {
@@ -567,7 +567,7 @@ impl<'a> SocketAncillary<'a> {
567567
/// #![feature(unix_socket_ancillary_data)]
568568
/// use std::os::unix::net::{UnixStream, SocketAncillary};
569569
/// use std::os::unix::io::AsRawFd;
570-
/// use std::io::IoSliceMut;
570+
/// use std::io::IoSlice;
571571
///
572572
/// fn main() -> std::io::Result<()> {
573573
/// let sock = UnixStream::connect("/tmp/sock")?;
@@ -577,7 +577,7 @@ impl<'a> SocketAncillary<'a> {
577577
/// ancillary.add_fds(&[sock.as_raw_fd()][..]);
578578
///
579579
/// let mut buf = [1; 8];
580-
/// let mut bufs = &mut [IoSliceMut::new(&mut buf[..])][..];
580+
/// let mut bufs = &mut [IoSlice::new(&mut buf[..])][..];
581581
/// sock.send_vectored_with_ancillary(bufs, &mut ancillary)?;
582582
/// Ok(())
583583
/// }

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

+23-21
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,23 +506,24 @@ 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()?;
513-
/// let mut buf1 = [1; 8];
514-
/// let mut buf2 = [2; 16];
515-
/// 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),
513+
/// let buf1 = [1; 8];
514+
/// let buf2 = [2; 16];
515+
/// let buf3 = [3; 8];
516+
/// let bufs = &[
517+
/// IoSlice::new(&buf1),
518+
/// IoSlice::new(&buf2),
519+
/// IoSlice::new(&buf3),
520520
/// ][..];
521521
/// let fds = [0, 1, 2];
522522
/// let mut ancillary_buffer = [0; 128];
523523
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
524524
/// ancillary.add_fds(&fds[..]);
525-
/// sock.send_vectored_with_ancillary_to(bufs, &mut ancillary, "/some/sock").expect("send_vectored_with_ancillary_to function failed");
525+
/// sock.send_vectored_with_ancillary_to(bufs, &mut ancillary, "/some/sock")
526+
/// .expect("send_vectored_with_ancillary_to function failed");
526527
/// Ok(())
527528
/// }
528529
/// ```
@@ -538,7 +539,7 @@ impl UnixDatagram {
538539
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
539540
pub fn send_vectored_with_ancillary_to<P: AsRef<Path>>(
540541
&self,
541-
bufs: &mut [IoSliceMut<'_>],
542+
bufs: &[IoSlice<'_>],
542543
ancillary: &mut SocketAncillary<'_>,
543544
path: P,
544545
) -> io::Result<usize> {
@@ -554,23 +555,24 @@ impl UnixDatagram {
554555
/// ```no_run
555556
/// #![feature(unix_socket_ancillary_data)]
556557
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
557-
/// use std::io::IoSliceMut;
558+
/// use std::io::IoSlice;
558559
///
559560
/// fn main() -> std::io::Result<()> {
560561
/// let sock = UnixDatagram::unbound()?;
561-
/// let mut buf1 = [1; 8];
562-
/// let mut buf2 = [2; 16];
563-
/// 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),
562+
/// let buf1 = [1; 8];
563+
/// let buf2 = [2; 16];
564+
/// let buf3 = [3; 8];
565+
/// let bufs = &[
566+
/// IoSlice::new(&buf1),
567+
/// IoSlice::new(&buf2),
568+
/// IoSlice::new(&buf3),
568569
/// ][..];
569570
/// let fds = [0, 1, 2];
570571
/// let mut ancillary_buffer = [0; 128];
571572
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
572573
/// ancillary.add_fds(&fds[..]);
573-
/// sock.send_vectored_with_ancillary(bufs, &mut ancillary).expect("send_vectored_with_ancillary function failed");
574+
/// sock.send_vectored_with_ancillary(bufs, &mut ancillary)
575+
/// .expect("send_vectored_with_ancillary function failed");
574576
/// Ok(())
575577
/// }
576578
/// ```
@@ -586,7 +588,7 @@ impl UnixDatagram {
586588
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
587589
pub fn send_vectored_with_ancillary(
588590
&self,
589-
bufs: &mut [IoSliceMut<'_>],
591+
bufs: &[IoSlice<'_>],
590592
ancillary: &mut SocketAncillary<'_>,
591593
) -> io::Result<usize> {
592594
send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary)

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -530,23 +530,24 @@ 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")?;
537-
/// let mut buf1 = [1; 8];
538-
/// let mut buf2 = [2; 16];
539-
/// 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),
537+
/// let buf1 = [1; 8];
538+
/// let buf2 = [2; 16];
539+
/// let buf3 = [3; 8];
540+
/// let bufs = &[
541+
/// IoSlice::new(&buf1),
542+
/// IoSlice::new(&buf2),
543+
/// IoSlice::new(&buf3),
544544
/// ][..];
545545
/// let fds = [0, 1, 2];
546546
/// let mut ancillary_buffer = [0; 128];
547547
/// let mut ancillary = SocketAncillary::new(&mut ancillary_buffer[..]);
548548
/// ancillary.add_fds(&fds[..]);
549-
/// socket.send_vectored_with_ancillary(bufs, &mut ancillary).expect("send_vectored_with_ancillary function failed");
549+
/// socket.send_vectored_with_ancillary(bufs, &mut ancillary)
550+
/// .expect("send_vectored_with_ancillary function failed");
550551
/// Ok(())
551552
/// }
552553
/// ```
@@ -562,7 +563,7 @@ impl UnixStream {
562563
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
563564
pub fn send_vectored_with_ancillary(
564565
&self,
565-
bufs: &mut [IoSliceMut<'_>],
566+
bufs: &[IoSlice<'_>],
566567
ancillary: &mut SocketAncillary<'_>,
567568
) -> io::Result<usize> {
568569
send_vectored_with_ancillary_to(&self.0, None, bufs, ancillary)

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -485,14 +485,14 @@ fn test_unix_datagram_peek_from() {
485485
fn test_send_vectored_fds_unix_stream() {
486486
let (s1, s2) = or_panic!(UnixStream::pair());
487487

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

491491
let mut ancillary1_buffer = [0; 128];
492492
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);
493493
assert!(ancillary1.add_fds(&[s1.as_raw_fd()][..]));
494494

495-
let usize = or_panic!(s1.send_vectored_with_ancillary(&mut bufs_send, &mut ancillary1));
495+
let usize = or_panic!(s1.send_vectored_with_ancillary(&bufs_send, &mut ancillary1));
496496
assert_eq!(usize, 8);
497497

498498
let mut buf2 = [0; 8];
@@ -542,8 +542,8 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {
542542

543543
or_panic!(bsock2.set_passcred(true));
544544

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

548548
let mut ancillary1_buffer = [0; 128];
549549
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);
@@ -554,7 +554,7 @@ fn test_send_vectored_with_ancillary_to_unix_datagram() {
554554
assert!(ancillary1.add_creds(&[cred1.clone()][..]));
555555

556556
let usize =
557-
or_panic!(bsock1.send_vectored_with_ancillary_to(&mut bufs_send, &mut ancillary1, &path2));
557+
or_panic!(bsock1.send_vectored_with_ancillary_to(&bufs_send, &mut ancillary1, &path2));
558558
assert_eq!(usize, 8);
559559

560560
let mut buf2 = [0; 8];
@@ -603,15 +603,15 @@ fn test_send_vectored_with_ancillary_unix_datagram() {
603603
let bsock1 = or_panic!(UnixDatagram::bind(&path1));
604604
let bsock2 = or_panic!(UnixDatagram::bind(&path2));
605605

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

609609
let mut ancillary1_buffer = [0; 128];
610610
let mut ancillary1 = SocketAncillary::new(&mut ancillary1_buffer[..]);
611611
assert!(ancillary1.add_fds(&[bsock1.as_raw_fd()][..]));
612612

613613
or_panic!(bsock1.connect(&path2));
614-
let usize = or_panic!(bsock1.send_vectored_with_ancillary(&mut bufs_send, &mut ancillary1));
614+
let usize = or_panic!(bsock1.send_vectored_with_ancillary(&bufs_send, &mut ancillary1));
615615
assert_eq!(usize, 8);
616616

617617
let mut buf2 = [0; 8];

0 commit comments

Comments
 (0)