-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux 6.0 introduced `IORING_OP_SEND_ZC`. This PR introduces the function `send_zc` on udp (todo: tcp) sockets which takes advantage of it. As IORING_OP_SEND_ZC can return multiple CQE's per SQE, this also extends the `Lifecycle` handling in `impl Fut for Op<T>` to check for these occurences. If does this using a new method `update` in `Completable`, which I added to minimise the scope of the changes - it just falls back to the `complete` method for implementations which are just single entry. This approach could probably be used as a the basis of streaming interfaces for some other submission types.
- Loading branch information
Showing
6 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ mod rename_at; | |
|
||
mod send_to; | ||
|
||
mod send_zc; | ||
|
||
mod shared_fd; | ||
pub(crate) use shared_fd::SharedFd; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use crate::driver::op::{self, Completable, Updateable}; | ||
use crate::{ | ||
buf::IoBuf, | ||
driver::{Op, SharedFd}, | ||
BufResult, | ||
}; | ||
use std::io; | ||
|
||
pub(crate) struct SendZc<T> { | ||
/// Holds a strong ref to the FD, preventing the file from being closed | ||
/// while the operation is in-flight. | ||
#[allow(dead_code)] | ||
fd: SharedFd, | ||
|
||
pub(crate) buf: T, | ||
|
||
/// Hold the number of transmitted bytes | ||
bytes: usize, | ||
} | ||
|
||
impl<T: IoBuf> Op<SendZc<T>> { | ||
pub(crate) fn send_zc(fd: &SharedFd, buf: T) -> io::Result<Op<SendZc<T>>> { | ||
use io_uring::{opcode, types}; | ||
|
||
Op::submit_with( | ||
SendZc { | ||
fd: fd.clone(), | ||
buf, | ||
bytes: 0, | ||
}, | ||
|send| { | ||
// Get raw buffer info | ||
let ptr = send.buf.stable_ptr(); | ||
let len = send.buf.bytes_init(); | ||
|
||
opcode::SendZc::new(types::Fd(fd.raw_fd()), ptr, len as _).build() | ||
}, | ||
) | ||
} | ||
} | ||
|
||
impl<T> Completable for SendZc<T> | ||
where | ||
T: IoBuf, | ||
{ | ||
type Output = BufResult<usize, T>; | ||
|
||
fn complete(self, cqe: op::CqeResult) -> Self::Output { | ||
// Convert the operation result to `usize` | ||
let res = cqe.result.map(|v| self.bytes + v as usize); | ||
// Recover the buffer | ||
let buf = self.buf; | ||
(res, buf) | ||
} | ||
} | ||
|
||
impl<T> Updateable for SendZc<T> | ||
where | ||
T: IoBuf, | ||
{ | ||
fn update(&mut self, cqe: op::CqeResult) { | ||
// uring send_zc promises there will be no error on CQE's marked more | ||
self.bytes += *cqe.result.as_ref().unwrap() as usize; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters