fluke_buffet/io/
non_uring.rs

1use crate::{BufResult, IoBufMut, Piece, ReadOwned, WriteOwned};
2
3use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
4
5impl<T> ReadOwned for T
6where
7    T: AsyncRead + Unpin,
8{
9    async fn read_owned<B: IoBufMut>(&mut self, mut buf: B) -> BufResult<usize, B> {
10        let buf_slice = unsafe { buf.slice_mut() };
11        let res = tokio::io::AsyncReadExt::read(self, buf_slice).await;
12        (res, buf)
13    }
14}
15
16impl<T> WriteOwned for T
17where
18    T: AsyncWrite + Unpin,
19{
20    async fn write_owned(&mut self, buf: impl Into<Piece>) -> BufResult<usize, Piece> {
21        let buf = buf.into();
22        let res = tokio::io::AsyncWriteExt::write(self, &buf[..]).await;
23        (res, buf)
24    }
25
26    // TODO: implement writev, for performance. this involves wrapping
27    // everything in `IoSlice`, advancing correctly, etc. It's not fun, but it
28    // should yield a boost for non-uring codepaths.
29
30    async fn shutdown(&mut self) -> std::io::Result<()> {
31        AsyncWriteExt::shutdown(self).await
32    }
33}