TcpCanceller

Struct TcpCanceller 

Source
pub struct TcpCanceller { /* private fields */ }
Expand description

A canceller that can be used to abort “pending” I/O operations

Each mtcp_rs::TcpCanceller instance is tied to an mtcp_rs::TcpManager instance. Calling the cancel() function will immediately abort any pending I/O operations in all mtcp_rs::TcpListener or mtcp_rs::TcpStream instances that are tied to the same mtcp_rs::TcpManager instance. Unlike the mtcp_rs::TcpManager instance, the mtcp_rs::TcpCanceller instance can be moved across the thread boundary. This is useful, for example, to implement a Ctrl+C (SIGINT) handler.

Cancelled I/O operations will fail with an TcpError::Cancelled error. However, there is no guarantee that I/O operations already in progress will actually be cancelled! Even after cancellation has been requested, an I/O operation that was just about to finish may still succeed, or even fail with a different error. Newly started operations are guaranteed to be cancelled.

Implementations§

Source§

impl TcpCanceller

Source

pub fn cancel(&self) -> Result<bool>

Request cancellation of any pending I/O operations belonging to the tied TcpManager instance.

Returns true, if cancellation was requested successfully; or false, if the tied TcpManager was already cancelled before.

Source

pub fn cancelled(&self) -> bool

Check whether the tied TcpManager instance has been cancelled yet.

Returns true, if cancellation has been requested for the tied TcpManager; or false otherwise.

Trait Implementations§

Source§

impl Debug for TcpCanceller

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.