pub struct Context<W> { /* private fields */ }Expand description
Context passed to a TCP crate::Handler.
Writes through this context are staged in a handler-local outbox. They are encoded into the connection write buffer when the handler returns or when a flush is requested. Flush handles may be dropped for fire-and-forget behavior or awaited to wait until the local socket write completes.
Implementations§
Source§impl<W: Send + 'static> Context<W>
impl<W: Send + 'static> Context<W>
pub fn id(&self) -> u64
Sourcepub fn peer_addr(&self) -> SocketAddr
pub fn peer_addr(&self) -> SocketAddr
Remote peer address for this connection.
Sourcepub fn local_addr(&self) -> SocketAddr
pub fn local_addr(&self) -> SocketAddr
Local socket address for this connection.
Sourcepub fn channel(&self) -> Channel<W>
pub fn channel(&self) -> Channel<W>
Returns a cloneable channel for writing from outside the current handler.
Sourcepub fn stats(&self) -> Option<ConnectionStats>
pub fn stats(&self) -> Option<ConnectionStats>
Connection stats when tracking was enabled on the server/client.
Sourcepub fn write(&mut self, msg: W) -> WriteHandle
pub fn write(&mut self, msg: W) -> WriteHandle
Stages a message for outbound processing.
The returned handle is ready immediately; awaiting it is supported for source compatibility with earlier async-style handlers.
Sourcepub fn flush(&mut self) -> FlushHandle<'_, W>
pub fn flush(&mut self) -> FlushHandle<'_, W>
Requests a flush of messages staged by this handler so far.
Dropping the returned handle is fire-and-forget. Awaiting it waits until the connection runtime has completed the local socket write.
Sourcepub fn write_and_flush(&mut self, msg: W) -> FlushHandle<'_, W>
pub fn write_and_flush(&mut self, msg: W) -> FlushHandle<'_, W>
Stages a message and requests an outbound flush.
Dropping the returned handle is fire-and-forget. Awaiting it waits until the connection runtime has completed the local socket write for this flush boundary.