Skip to content

Commit

Permalink
backend/rs: Retry send/recv on EINTR
Browse files Browse the repository at this point in the history
This could be considered a breaking API change, but probably no callers
are actually handling it. And it seems libwayland does this, so making
the rs backend consistent here can be considered a bug fix.
  • Loading branch information
ids1024 committed Jan 22, 2024
1 parent 31bab14 commit fd39fd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions wayland-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#### Bugfixes
- backend/sys: Fix error/segfault if object argument is no longer alive
- backend/rs: Retry send/recv on `EINTR`
* Matches the behavior of libwayland

## 0.3.2 -- 2023-09-25

Expand Down
7 changes: 4 additions & 3 deletions wayland-backend/src/rs/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, OwnedFd, RawFd};
use std::os::unix::net::UnixStream;
use std::slice;

use rustix::io::retry_on_intr;
use rustix::net::{
recvmsg, send, sendmsg, RecvAncillaryBuffer, RecvAncillaryMessage, RecvFlags,
SendAncillaryBuffer, SendAncillaryMessage, SendFlags,
Expand Down Expand Up @@ -51,9 +52,9 @@ impl Socket {
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)?)
Ok(retry_on_intr(|| sendmsg(self, &iov, &mut cmsg_buffer, flags))?)
} else {
Ok(send(self, bytes, flags)?)
Ok(retry_on_intr(|| send(self, bytes, flags))?)
}
}

Expand All @@ -77,7 +78,7 @@ impl Socket {
let mut cmsg_space = vec![0; rustix::cmsg_space!(ScmRights(MAX_FDS_OUT))];
let mut cmsg_buffer = RecvAncillaryBuffer::new(&mut cmsg_space);
let mut iov = [IoSliceMut::new(buffer)];
let msg = recvmsg(&self.stream, &mut iov[..], &mut cmsg_buffer, flags)?;
let msg = retry_on_intr(|| recvmsg(&self.stream, &mut iov[..], &mut cmsg_buffer, flags))?;

let received_fds = cmsg_buffer
.drain()
Expand Down

0 comments on commit fd39fd4

Please sign in to comment.