Skip to content

Commit

Permalink
Use send instead of sendmsg to send with no fds
Browse files Browse the repository at this point in the history
This should fix the failing FreeBSD CI test, and behave correctly. This
is perhaps better, though I think either *should* work
(bytecodealliance/rustix#914).

The other `sendmsg`/`recvmsg` calls use `rustix::cmsg_space!`, and
should work without issue.
  • Loading branch information
ids1024 committed Nov 1, 2023
1 parent edd0f60 commit d73fe9a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions wayland-backend/src/rs/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::os::unix::net::UnixStream;
use std::slice;

use rustix::net::{
recvmsg, sendmsg, RecvAncillaryBuffer, RecvAncillaryMessage, RecvFlags, SendAncillaryBuffer,
recvmsg, send, sendmsg, RecvAncillaryBuffer, RecvAncillaryMessage, RecvFlags, SendAncillaryBuffer,
SendAncillaryMessage, SendFlags,
};

Expand Down Expand Up @@ -39,18 +39,17 @@ impl Socket {
/// end may lose some data.
pub fn send_msg(&self, bytes: &[u8], fds: &[RawFd]) -> IoResult<usize> {
let flags = SendFlags::DONTWAIT | SendFlags::NOSIGNAL;
let iov = [IoSlice::new(bytes)];

if !fds.is_empty() {
let iov = [IoSlice::new(bytes)];
let mut cmsg_space = vec![0; rustix::cmsg_space!(ScmRights(fds.len()))];
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut cmsg_space);
let fds =
unsafe { slice::from_raw_parts(fds.as_ptr() as *const BorrowedFd, fds.len()) };
cmsg_buffer.push(SendAncillaryMessage::ScmRights(fds));
Ok(sendmsg(self, &iov, &mut cmsg_buffer, flags)?)
} else {
let mut cmsg_buffer = SendAncillaryBuffer::new(&mut []);
Ok(sendmsg(self, &iov, &mut cmsg_buffer, flags)?)
Ok(send(self, bytes, flags)?)
}
}

Expand Down

0 comments on commit d73fe9a

Please sign in to comment.