io: use io_uring for all io
There should no longer be any - read - write - connect - sendmsg - recvmsg - accept calls in the codebase. Previously we were using a mix of io_uring and these calls which had some negative effects: Since we were using the old system calls, we had to set the file descriptors to non-blocking. But our io_uring code did not handle EAGAIN. This lead to programs sometimes being killed when the wayland IO was actually blocking. Now all file descriptors are set to blocking, but io_uring makes it non-blocking from our perspective. The one exception are evdev files because they are read via libinput and libinput uses the old system calls.
This commit is contained in:
parent
2db0ee8995
commit
9812a02f87
55 changed files with 900 additions and 672 deletions
|
|
@ -17,12 +17,22 @@ use {
|
|||
};
|
||||
|
||||
impl IoUring {
|
||||
pub async fn sendmsg(
|
||||
pub async fn sendmsg_one(
|
||||
&self,
|
||||
fd: &Rc<OwnedFd>,
|
||||
buf: Buf,
|
||||
fds: Vec<Rc<OwnedFd>>,
|
||||
timeout: Option<Time>,
|
||||
) -> Result<usize, IoUringError> {
|
||||
self.sendmsg(fd, &mut [buf], fds, timeout).await
|
||||
}
|
||||
|
||||
pub async fn sendmsg(
|
||||
&self,
|
||||
fd: &Rc<OwnedFd>,
|
||||
bufs: &mut [Buf],
|
||||
fds: Vec<Rc<OwnedFd>>,
|
||||
timeout: Option<Time>,
|
||||
) -> Result<usize, IoUringError> {
|
||||
self.ring.check_destroyed()?;
|
||||
let id = self.ring.id();
|
||||
|
|
@ -52,13 +62,17 @@ impl IoUring {
|
|||
}
|
||||
st.id = id.id;
|
||||
st.fd = fd.raw();
|
||||
st.iovec.iov_base = buf.as_ptr() as _;
|
||||
st.iovec.iov_len = buf.len() as _;
|
||||
st.msghdr.msg_iov = &st.iovec as *const _ as _;
|
||||
st.msghdr.msg_iovlen = 1;
|
||||
st.bufs.clear();
|
||||
st.bufs.extend(bufs.iter_mut().map(|b| b.clone()));
|
||||
st.iovecs.clear();
|
||||
st.iovecs.extend(bufs.iter().map(|b| c::iovec {
|
||||
iov_base: b.as_ptr() as _,
|
||||
iov_len: b.len(),
|
||||
}));
|
||||
st.msghdr.msg_iov = st.iovecs.as_ptr() as _;
|
||||
st.msghdr.msg_iovlen = st.iovecs.len();
|
||||
st.data = Some(SendmsgTaskData {
|
||||
_fd: fd.clone(),
|
||||
_buf: buf,
|
||||
res: pr.clone(),
|
||||
});
|
||||
st.has_timeout = timeout.is_some();
|
||||
|
|
@ -73,14 +87,14 @@ impl IoUring {
|
|||
|
||||
struct SendmsgTaskData {
|
||||
_fd: Rc<OwnedFd>,
|
||||
_buf: Buf,
|
||||
res: PendingResult,
|
||||
}
|
||||
|
||||
pub struct SendmsgTask {
|
||||
id: u64,
|
||||
iovec: c::iovec,
|
||||
iovecs: Vec<c::iovec>,
|
||||
msghdr: c::msghdr,
|
||||
bufs: Vec<Buf>,
|
||||
fd: i32,
|
||||
has_timeout: bool,
|
||||
fds: Vec<Rc<OwnedFd>>,
|
||||
|
|
@ -93,8 +107,9 @@ impl Default for SendmsgTask {
|
|||
unsafe {
|
||||
SendmsgTask {
|
||||
id: 0,
|
||||
iovec: MaybeUninit::zeroed().assume_init(),
|
||||
iovecs: vec![],
|
||||
msghdr: MaybeUninit::zeroed().assume_init(),
|
||||
bufs: vec![],
|
||||
fd: 0,
|
||||
has_timeout: false,
|
||||
fds: vec![],
|
||||
|
|
@ -112,6 +127,7 @@ unsafe impl Task for SendmsgTask {
|
|||
|
||||
fn complete(mut self: Box<Self>, ring: &IoUringData, res: i32) {
|
||||
self.fds.clear();
|
||||
self.bufs.clear();
|
||||
if let Some(data) = self.data.take() {
|
||||
data.res.complete(res);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue