Skip to content

Integrate io_uring in the Reactor #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ categories = ["asynchronous", "network-programming", "os"]
exclude = ["/.*"]

[dependencies]
cfg-if = "1"
concurrent-queue = "1.2.2"
futures-lite = "1.11.0"
log = "0.4.11"
once_cell = "1.4.1"
parking = "2.0.0"
polling = "2.0.0"
polling = { git = "https://github.com/smol-rs/polling" }
slab = "0.4.2"
socket2 = { version = "0.4.2", features = ["all"] }
waker-fn = "1.1.0"

[target.'cfg(target_os = "linux")'.dependencies]
io-uring = { version = "=0.5.3", features = ["unstable"] }

[build-dependencies]
autocfg = "1"

Expand Down
40 changes: 10 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,17 +1012,14 @@ impl<T> Drop for Async<T> {

impl<T: Read> AsyncRead for Async<T> {
fn poll_read(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
loop {
match (&mut *self).get_mut().read(buf) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return Poll::Ready(res),
}
ready!(self.poll_readable(cx))?;
}
let this = self.get_mut();

// Manually access the fields in order to keep the borrow checker happy.
Reactor::get().poll_read(this.io.as_mut().unwrap(), &this.source, buf, cx)
}

fn poll_read_vectored(
Expand All @@ -1049,13 +1046,7 @@ where
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
loop {
match (*self).get_ref().read(buf) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return Poll::Ready(res),
}
ready!(self.poll_readable(cx))?;
}
Reactor::get().poll_read(&mut self.get_ref(), &self.source, buf, cx)
}

fn poll_read_vectored(
Expand All @@ -1075,17 +1066,12 @@ where

impl<T: Write> AsyncWrite for Async<T> {
fn poll_write(
mut self: Pin<&mut Self>,
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
loop {
match (&mut *self).get_mut().write(buf) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return Poll::Ready(res),
}
ready!(self.poll_writable(cx))?;
}
let this = self.get_mut();
Reactor::get().poll_write(this.io.as_mut().unwrap(), &this.source, buf, cx)
}

fn poll_write_vectored(
Expand Down Expand Up @@ -1126,13 +1112,7 @@ where
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
loop {
match (*self).get_ref().write(buf) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return Poll::Ready(res),
}
ready!(self.poll_writable(cx))?;
}
Reactor::get().poll_write(&mut self.get_ref(), &self.source, buf, cx)
}

fn poll_write_vectored(
Expand Down
Loading