forked from tokio-rs/tokio-uring
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf5417f
commit 22f1fbf
Showing
4 changed files
with
55 additions
and
0 deletions.
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
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,45 @@ | ||
use std::marker::PhantomData; | ||
use std::pin::Pin; | ||
|
||
use io_uring::cqueue::Entry; | ||
use io_uring::{opcode, types}; | ||
|
||
use crate::io::SharedFd; | ||
|
||
use crate::{OneshotOutputTransform, UnsubmittedOneshot}; | ||
|
||
/// An unsubmitted read operation. | ||
pub type UnsubmittedCmd<T> = UnsubmittedOneshot<CmdData<T>, CmdTransform<T>>; | ||
|
||
impl<T> UnsubmittedCmd<T> { | ||
pub(crate) fn cmd(fd: &SharedFd, op: u32, cmd: [u8; 16], data: Pin<Box<T>>) -> Self { | ||
Self::new( | ||
CmdData { data }, | ||
CmdTransform { | ||
_phantom: PhantomData, | ||
}, | ||
opcode::UringCmd16::new(types::Fd(fd.raw_fd()), op) | ||
.cmd(cmd) | ||
.build(), | ||
) | ||
} | ||
} | ||
|
||
#[allow(missing_docs)] | ||
pub struct CmdData<T> { | ||
data: Pin<Box<T>>, | ||
} | ||
|
||
#[allow(missing_docs)] | ||
pub struct CmdTransform<B> { | ||
_phantom: PhantomData<B>, | ||
} | ||
|
||
impl<T> OneshotOutputTransform for CmdTransform<T> { | ||
type Output = (i32, Pin<Box<T>>); | ||
type StoredData = CmdData<T>; | ||
|
||
fn transform_oneshot_output(self, data: Self::StoredData, cqe: Entry) -> Self::Output { | ||
(cqe.result(), data.data) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -56,3 +56,5 @@ pub(crate) mod writev; | |
|
||
mod writev_all; | ||
pub(crate) use writev_all::writev_at_all; | ||
|
||
pub(crate) mod cmd; |
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