Skip to main content

ConnectionHook

Trait ConnectionHook 

Source
pub trait ConnectionHook<Io>:
    Send
    + Sync
    + 'static
where Io: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{ type Error: StdError + Send + Sync + 'static; // Required method fn on_connection( &self, io: Io, ) -> impl Future<Output = HookResult<Io, Self::Error>> + Send; }
Expand description

Connection hook executed during connection establishment.

For server sockets: called when a connection is accepted. For client sockets: called after connecting.

The connection hook receives the raw IO stream and has full control over the handshake protocol.

Required Associated Types§

Source

type Error: StdError + Send + Sync + 'static

The hook-specific error type.

Required Methods§

Source

fn on_connection( &self, io: Io, ) -> impl Future<Output = HookResult<Io, Self::Error>> + Send

Called when a connection is established.

§Arguments
  • io - The raw IO stream for this connection
§Returns
  • Ok(io) - The IO stream on success (potentially wrapped/transformed)
  • Err(Error::Io(..)) - An I/O error occurred
  • Err(Error::Hook(Self::Error)) - A hook-specific error to reject the connection

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Io> ConnectionHook<Io> for ClientHook
where Io: AsyncRead + AsyncWrite + Send + Unpin + 'static,

Source§

impl<Io, F> ConnectionHook<Io> for ServerHook<F>
where Io: AsyncRead + AsyncWrite + Send + Unpin + 'static, F: Fn(&Bytes) -> bool + Send + Sync + 'static,