Skip to content

Commit

Permalink
Merge pull request #918 from psychon/async-io-2
Browse files Browse the repository at this point in the history
Update to async-io 2
  • Loading branch information
mergify[bot] committed Feb 9, 2024
2 parents 713b04f + a539f06 commit 2b2d115
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion x11rb-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11", "async"]

[dependencies]
async-io = "1.13.0"
async-io = "2.3"
async-lock = "3.3"
blocking = "1.5"
event-listener = "5.0"
Expand Down
41 changes: 6 additions & 35 deletions x11rb-async/src/rust_connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::pin::Pin;
use std::task::{Context, Poll};

#[cfg(unix)]
use std::os::unix::io::{AsRawFd as AsRaw, RawFd};
use std::os::unix::io::AsFd;

#[cfg(windows)]
use std::os::windows::io::{AsRawSocket as AsRaw, RawSocket};
use std::os::windows::io::AsSocket as AsFd;

use async_io::Async;
use futures_lite::future;
Expand Down Expand Up @@ -46,42 +46,13 @@ pub struct StreamAdaptor<S> {
inner: Async<S>,
}

impl<S: AsRaw> StreamAdaptor<S> {
impl<S: AsFd> StreamAdaptor<S> {
/// Create a new `StreamAdaptor` from a stream.
pub fn new(stream: S) -> io::Result<Self> {
Async::new(stream).map(|inner| Self { inner })
}
}

impl<S> StreamAdaptor<S> {
/// Get a reference to the inner stream.
pub fn get_ref(&self) -> &S {
self.inner.get_ref()
}

/// Get a mutable reference to the inner stream.
pub fn get_mut(&mut self) -> &mut S {
self.inner.get_mut()
}

/// Consume this adaptor and return the inner stream.
pub fn into_inner(self) -> io::Result<S> {
self.inner.into_inner()
}
}

impl<S: AsRaw> AsRaw for StreamAdaptor<S> {
#[cfg(unix)]
fn as_raw_fd(&self) -> RawFd {
self.inner.get_ref().as_raw_fd()
}

#[cfg(windows)]
fn as_raw_socket(&self) -> RawSocket {
self.inner.get_ref().as_raw_socket()
}
}

/// A future for reading from a [`StreamAdaptor`].
#[derive(Debug)]
pub struct Readable<'a, S>(async_io::Readable<'a, S>);
Expand Down Expand Up @@ -138,18 +109,18 @@ impl<S: X11rbStream> X11rbStream for StreamAdaptor<S> {
}

fn read(&self, buf: &mut [u8], fd_storage: &mut Vec<RawFdContainer>) -> io::Result<usize> {
self.get_ref().read(buf, fd_storage)
self.inner.get_ref().read(buf, fd_storage)
}

fn write(&self, buf: &[u8], fds: &mut Vec<RawFdContainer>) -> io::Result<usize> {
self.get_ref().write(buf, fds)
self.inner.get_ref().write(buf, fds)
}

fn write_vectored(
&self,
bufs: &[io::IoSlice<'_>],
fds: &mut Vec<RawFdContainer>,
) -> io::Result<usize> {
self.get_ref().write_vectored(bufs, fds)
self.inner.get_ref().write_vectored(bufs, fds)
}
}

0 comments on commit 2b2d115

Please sign in to comment.