MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_unix_msg_with_combo

Function test_unix_msg_with_combo

tests/net/unix_alloc.rs:693–903  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

691#[cfg(not(target_os = "freebsd"))] // TODO: Investigate why these tests fail on FreeBSD.
692#[test]
693fn test_unix_msg_with_combo() {
694 crate::init();
695
696 use rustix::fd::AsFd as _;
697 use rustix::io::{IoSlice, IoSliceMut};
698 use rustix::net::{
699 recvmsg, sendmsg, RecvAncillaryBuffer, RecvAncillaryMessage, RecvFlags, ReturnFlags,
700 SendAncillaryBuffer, SendAncillaryMessage, SendFlags,
701 };
702 use rustix::pipe::pipe;
703 use std::string::ToString as _;
704
705 let tmpdir = tempfile::tempdir().unwrap();
706 let path = tmpdir.path().join("scp_4804");
707
708 let server = {
709 let path = path.clone();
710
711 let connection_socket = socket(AddressFamily::UNIX, SocketType::SEQPACKET, None).unwrap();
712
713 let name = SocketAddrUnix::new(&path).unwrap();
714 bind(&connection_socket, &name).unwrap();
715 listen(&connection_socket, 1).unwrap();
716
717 move || {
718 let mut pipe_end = None;
719 let mut another_pipe_end = None;
720 let mut yet_another_pipe_end = None;
721
722 let mut buffer = vec![0; BUFFER_SIZE];
723 let mut cmsg_space =
724 Vec::with_capacity(rustix::cmsg_space!(ScmRights(1), ScmRights(2)));
725
726 'exit: loop {
727 let data_socket = accept(&connection_socket).unwrap();
728 let mut sum = 0;
729 loop {
730 let mut cmsg_buffer = RecvAncillaryBuffer::new(cmsg_space.spare_capacity_mut());
731 let result = recvmsg(
732 &data_socket,
733 &mut [IoSliceMut::new(&mut buffer)],
734 &mut cmsg_buffer,
735 RecvFlags::empty(),
736 )
737 .unwrap();
738 let nread = result.bytes;
739
740 assert_eq!(result.flags, ReturnFlags::empty());
741
742 // Read out the pipe if we got it.
743 for cmsg in cmsg_buffer.drain() {
744 match cmsg {
745 RecvAncillaryMessage::ScmRights(rights) => {
746 for right in rights {
747 if pipe_end.is_none() {
748 pipe_end = Some(right);
749 } else if another_pipe_end.is_none() {
750 another_pipe_end = Some(right);

Callers

nothing calls this directly

Calls 15

cloneMethod · 0.80
drainMethod · 0.80
initFunction · 0.70
serverFunction · 0.70
clientFunction · 0.70
socketFunction · 0.50
bindFunction · 0.50
listenFunction · 0.50
acceptFunction · 0.50
recvmsgFunction · 0.50
sendmsgFunction · 0.50
unlinkatFunction · 0.50

Tested by

no test coverage detected