dope_uring/driver/
submit.rs1use std::future::Future;
2use std::io;
3use std::os::fd::{AsRawFd, RawFd};
4
5use dope_core::Fd;
6use dope_core::addr::SockAddr;
7use dope_core::submit::{RecvMsgPacket, SendMsgPacket, SubmitOps};
8
9use super::Driver;
10use super::request::Request;
11
12impl SubmitOps for &mut Driver {
13 fn submit_accept(
14 self,
15 fd: Fd,
16 ) -> impl Future<Output = io::Result<(RawFd, SockAddr)>> + 'static {
17 let raw = fd.as_raw_fd();
18 let req = self.try_submit_op(SockAddr::empty(), move |addr| {
19 io_uring::opcode::Accept::new(
20 io_uring::types::Fd(raw),
21 addr.addr_mut_ptr(),
22 addr.addr_len_ptr(),
23 )
24 .build()
25 });
26 async move {
27 let (res, addr) = Request::await_submit(req).await;
28 res.map(|n| (n as RawFd, addr))
29 }
30 }
31
32 fn submit_read<B>(self, fd: Fd, buf: B) -> impl Future<Output = (io::Result<u32>, B)> + 'static
33 where
34 B: AsMut<[u8]> + Unpin + 'static,
35 {
36 let raw = fd.as_raw_fd();
37 let req = self.try_submit_op(buf, move |buf| {
38 let slice = buf.as_mut();
39 io_uring::opcode::Read::new(
40 io_uring::types::Fd(raw),
41 slice.as_mut_ptr(),
42 slice.len() as u32,
43 )
44 .build()
45 });
46 Request::await_submit(req)
47 }
48
49 fn submit_send_raw<B>(
50 self,
51 fd: Fd,
52 buf: B,
53 len: usize,
54 ) -> impl Future<Output = (io::Result<u32>, B)> + 'static
55 where
56 B: AsRef<[u8]> + Unpin + 'static,
57 {
58 let raw = fd.as_raw_fd();
59 let req = self.try_submit_op(buf, move |buf| {
60 let full = buf.as_ref();
61 let n = len.min(full.len());
62 io_uring::opcode::Send::new(io_uring::types::Fd(raw), full.as_ptr(), n as u32).build()
63 });
64 Request::await_submit(req)
65 }
66
67 fn submit_sendmsg_raw<P>(
68 self,
69 fd: Fd,
70 packet: P,
71 ) -> impl Future<Output = (io::Result<u32>, P)> + 'static
72 where
73 P: SendMsgPacket + Unpin + 'static,
74 {
75 let raw = fd.as_raw_fd();
76 let req = self.try_submit_op(packet, move |packet| {
77 io_uring::opcode::SendMsg::new(io_uring::types::Fd(raw), packet.msg_ptr()).build()
78 });
79 Request::await_submit(req)
80 }
81
82 fn submit_recvmsg_raw<P>(
83 self,
84 fd: Fd,
85 packet: P,
86 ) -> impl Future<Output = (io::Result<u32>, P)> + 'static
87 where
88 P: RecvMsgPacket + Unpin + 'static,
89 {
90 let raw = fd.as_raw_fd();
91 let req = self.try_submit_op(packet, move |packet| {
92 io_uring::opcode::RecvMsg::new(io_uring::types::Fd(raw), packet.msg_mut_ptr()).build()
93 });
94 Request::await_submit(req)
95 }
96}