Skip to main content

AsyncIo

Struct AsyncIo 

Source
pub struct AsyncIo<B>
where B: Backend,
{ /* private fields */ }
Expand description

TCP, UDP, local-pipe or stdio adapter with stable owned staging buffers.

Writes are buffered: poll_write reports bytes accepted into owned storage; poll_flush, poll_close, or the next write waits for their native completion and reports delayed errors. Flush before dropping to preserve buffered output. Dropping cancels pending reads and writes and closes the owned loop handle. A Pending poll never consumes the current write slice, so it may be replaced. UDP writes accept one complete datagram or reject it if staging is too small; UDP reads expose payload bytes without the sender address.

AsyncIo::poll_shutdown half-closes a stream: the write direction ends while reads continue until the peer’s EOF, and the handle stays open until poll_close or drop. poll_close still fully closes the handle.

Implementations§

Source§

impl<B> AsyncIo<B>
where B: Backend,

Source

pub fn handle(&self) -> Handle

Borrow the underlying loop handle for configuration or address queries.

Source

pub fn executor(&self) -> ExecutorHandle<B>

The executor that owns this stream’s handle, for deadlines and timers on the same loop (for example a lingering close). Cloning allocates nothing.

Source

pub fn is_write_shut(&self) -> bool

Whether AsyncIo::poll_shutdown has completed: writes now fail with BrokenPipe, while reads continue until the peer’s EOF.

Source

pub fn is_read_shut(&self) -> bool

Whether receive shutdown completed for this adapter.

Source

pub fn shutdown_receive(&mut self) -> Result<(), Error>

Stop receiving, discard this adapter’s buffered input, and preserve sends.

Calls native receive shutdown first; an unsupported transport leaves the adapter unchanged. After success all reads return EOF, including when a previous read was Pending or retained a partially consumed completion. Pending native access is cancelled, but its internal buffer remains owned by the executor until terminal acknowledgement. Repeated calls succeed. Supports TCP on Unix, Windows and WASI 0.2 and Unix-domain streams. WASI 0.3 and web currently return Unsupported; they require asynchronous stream cancellation before dropping the receive endpoint.

Source

pub fn poll_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Error>>

Gracefully end the write direction without closing the handle.

Flushes accepted writes first, then submits the backend’s stream shutdown after them: TCP shutdown(SHUT_WR) on epoll/kqueue, shutdown(SD_SEND) on IOCP, shutdown(send) on WASI 0.2 and closing the send stream on WASI 0.3. The peer reads EOF after every byte written before it. Reads on this adapter continue until the peer’s own EOF, so a server can drain unread peer input instead of closing with bytes unread (which sends RST, and on macOS and Windows discards data the peer has not read yet). Close or drop afterwards.

Repeated calls after completion return Ok. Transports that cannot half-close return io::ErrorKind::Unsupported: UDP adapters, Windows named pipes and console/synchronous handles, and non-socket Unix descriptors (ttys, FIFOs, regular files). WASI stdout and stderr close their output stream; a web WebSocket starts its close handshake. A pending poll never loses progress: the submitted shutdown stays owned by this adapter until it completes.

Trait Implementations§

Source§

impl<B> AsyncRead for AsyncIo<B>
where B: Backend,

Source§

fn poll_read( self: Pin<&mut AsyncIo<B>>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<B> AsyncWrite for AsyncIo<B>
where B: Backend,

Source§

fn poll_write( self: Pin<&mut AsyncIo<B>>, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from buf into the object. Read more
Source§

fn poll_flush( self: Pin<&mut AsyncIo<B>>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Source§

fn poll_close( self: Pin<&mut AsyncIo<B>>, cx: &mut Context<'_>, ) -> Poll<Result<(), Error>>

Attempt to close the object. Read more
Source§

fn poll_write_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>], ) -> Poll<Result<usize, Error>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
Source§

impl<B> Drop for AsyncIo<B>
where B: Backend,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<B: Backend> HalfClose for AsyncIo<B>

Source§

type Backend = B

Backend of the executor that owns the native handle.
Source§

fn executor(&self) -> Option<ExecutorHandle<B>>

The executor owning the native handle, whose timers bound a lingering close. None once the transport has been released.
Source§

fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>

Flush accepted writes, then end the write direction without closing the handle (TLS sends close_notify first). Reads continue until the peer’s EOF; later writes fail. Completed shutdowns stay complete on repeated polls. Transports without a separate write direction return io::ErrorKind::Unsupported (see AsyncIo::poll_shutdown).
Source§

impl<B> Unpin for AsyncIo<B>
where B: Backend,

Auto Trait Implementations§

§

impl<B> !RefUnwindSafe for AsyncIo<B>

§

impl<B> !Send for AsyncIo<B>

§

impl<B> !Sync for AsyncIo<B>

§

impl<B> !UnwindSafe for AsyncIo<B>

§

impl<B> Forget for AsyncIo<B>

§

impl<B> Freeze for AsyncIo<B>
where Rc<Shared<B>>: Freeze,

§

impl<B> UnsafeUnpin for AsyncIo<B>
where Rc<Shared<B>>: UnsafeUnpin,

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> Stream for T
where T: AsyncRead + AsyncWrite + Unpin,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.