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 d339240
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions wayland-backend/src/rs/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::os::unix::net::UnixStream;
use std::slice;

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

use crate::protocol::{ArgumentType, Message};
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 d339240

Please sign in to comment.