Trait WriteShutdown

Source
pub trait WriteShutdown: Write {
    // Provided method
    fn shutdown(&mut self) -> Result<(), Error> { ... }
}
Expand description

Notify the writer that there will be no more data written. In context of TLS providers, this is great time to send notify_close message.

Provided Methods§

Source

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

Initiates or attempts to shut down this writer, returning when the I/O connection has completely shut down.

For example this is suitable for implementing shutdown of a TLS connection or calling TcpStream::shutdown on a proxied connection. Protocols sometimes need to flush out final pieces of data or otherwise perform a graceful shutdown handshake, reading/writing more data as appropriate. This method is the hook for such protocols to implement the graceful shutdown logic.

This shutdown method is required by implementers of the AsyncWrite trait. Wrappers typically just want to proxy this call through to the wrapped type, and base types will typically implement shutdown logic here or just return Ok(().into()). Note that if you’re wrapping an underlying AsyncWrite a call to shutdown implies that transitively the entire stream has been shut down. After your wrapper’s shutdown logic has been executed you should shut down the underlying stream.

Invocation of a shutdown implies an invocation of flush. Once this method returns it implies that a flush successfully happened before the shutdown happened. That is, callers don’t need to call flush before calling shutdown. They can rely that by calling shutdown any pending buffered data will be written out.

§Errors

This function can return normal I/O errors through Err, described above. Additionally this method may also render the underlying Write::write method no longer usable (e.g. will return errors in the future). It’s recommended that once shutdown is called the write method is no longer called.

Implementors§