Skip to content

Commit

Permalink
io cleanup (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 authored Sep 11, 2024
1 parent 1d529fa commit 69f150e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
33 changes: 2 additions & 31 deletions ntex-io/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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.
///
Expand Down
23 changes: 11 additions & 12 deletions ntex-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(()))
}
}
Expand All @@ -126,7 +125,7 @@ pub enum IoStatusUpdate {
/// Stop io stream handling
Stop,
/// Peer is disconnected
PeerGone(Option<sio::Error>),
PeerGone(Option<IoError>),
}

/// Recv error
Expand All @@ -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
Expand Down

0 comments on commit 69f150e

Please sign in to comment.