io cleanup (#418)

This commit is contained in:
Nikolay Kim 2024-09-11 18:35:55 +05:00 committed by GitHub
parent 1d529fab3c
commit 69f150e3f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 43 deletions

View file

@ -347,19 +347,12 @@ impl<F> Io<F> {
poll_fn(|cx| self.poll_read_ready(cx)).await
}
#[doc(hidden)]
#[inline]
/// Wait until read becomes ready.
/// Wait until io reads any data.
pub async fn read_notify(&self) -> io::Result<Option<()>> {
poll_fn(|cx| self.poll_read_notify(cx)).await
}
#[doc(hidden)]
#[deprecated]
pub async fn force_read_ready(&self) -> io::Result<Option<()>> {
poll_fn(|cx| self.poll_read_notify(cx)).await
}
#[inline]
/// Pause read task
pub fn pause(&self) {
@ -446,21 +439,8 @@ impl<F> Io<F> {
}
}
#[doc(hidden)]
#[inline]
/// Polls for read readiness.
///
/// If the io stream is not currently ready for reading,
/// this method will store a clone of the Waker from the provided Context.
/// When the io stream becomes ready for reading, Waker::wake will be called on the waker.
///
/// Return value
/// The function returns:
///
/// `Poll::Pending` if the io stream is not ready for reading.
/// `Poll::Ready(Ok(Some(()))))` if the io stream is ready for reading.
/// `Poll::Ready(Ok(None))` if io stream is disconnected
/// `Some(Poll::Ready(Err(e)))` if an error is encountered.
/// Polls for any incoming data.
pub fn poll_read_notify(&self, cx: &mut Context<'_>) -> Poll<io::Result<Option<()>>> {
let ready = self.poll_read_ready(cx);
@ -477,15 +457,6 @@ impl<F> Io<F> {
}
}
#[doc(hidden)]
#[deprecated]
pub fn poll_force_read_ready(
&self,
cx: &mut Context<'_>,
) -> Poll<io::Result<Option<()>>> {
self.poll_read_notify(cx)
}
#[inline]
/// Decode codec item from incoming bytes stream.
///

View file

@ -2,9 +2,8 @@
#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)]
#![allow(async_fn_in_trait)]
use std::{
any::Any, any::TypeId, fmt, io as sio, io::Error as IoError, task::Context, task::Poll,
};
use std::io::{Error as IoError, Result as IoResult};
use std::{any::Any, any::TypeId, fmt, task::Context, task::Poll};
pub mod testing;
pub mod types;
@ -39,16 +38,16 @@ pub use self::flags::Flags;
#[doc(hidden)]
pub trait AsyncRead {
async fn read(&mut self, buf: BytesVec) -> (BytesVec, sio::Result<usize>);
async fn read(&mut self, buf: BytesVec) -> (BytesVec, IoResult<usize>);
}
#[doc(hidden)]
pub trait AsyncWrite {
async fn write(&mut self, buf: &mut WriteContextBuf) -> sio::Result<()>;
async fn write(&mut self, buf: &mut WriteContextBuf) -> IoResult<()>;
async fn flush(&mut self) -> sio::Result<()>;
async fn flush(&mut self) -> IoResult<()>;
async fn shutdown(&mut self) -> sio::Result<()>;
async fn shutdown(&mut self) -> IoResult<()>;
}
/// Status for read task
@ -90,10 +89,10 @@ pub trait FilterLayer: fmt::Debug + 'static {
///
/// Inner filter must process buffer before current.
/// Returns number of new bytes.
fn process_read_buf(&self, buf: &ReadBuf<'_>) -> sio::Result<usize>;
fn process_read_buf(&self, buf: &ReadBuf<'_>) -> IoResult<usize>;
/// Process write buffer
fn process_write_buf(&self, buf: &WriteBuf<'_>) -> sio::Result<()>;
fn process_write_buf(&self, buf: &WriteBuf<'_>) -> IoResult<()>;
#[inline]
/// Query internal filter data
@ -103,7 +102,7 @@ pub trait FilterLayer: fmt::Debug + 'static {
#[inline]
/// Gracefully shutdown filter
fn shutdown(&self, buf: &WriteBuf<'_>) -> sio::Result<Poll<()>> {
fn shutdown(&self, buf: &WriteBuf<'_>) -> IoResult<Poll<()>> {
Ok(Poll::Ready(()))
}
}
@ -126,7 +125,7 @@ pub enum IoStatusUpdate {
/// Stop io stream handling
Stop,
/// Peer is disconnected
PeerGone(Option<sio::Error>),
PeerGone(Option<IoError>),
}
/// Recv error
@ -141,7 +140,7 @@ pub enum RecvError<U: Decoder> {
/// Unrecoverable frame decoding errors
Decoder(U::Error),
/// Peer is disconnected
PeerGone(Option<sio::Error>),
PeerGone(Option<IoError>),
}
/// Dispatcher item