pub trait SocketHandler {
Show 13 methods
// Required methods
fn socket_read(&mut self, buf: &mut [u8]) -> (usize, SocketResult);
fn socket_write(&mut self, buf: &[u8]) -> (usize, SocketResult);
fn socket_write_vectored(
&mut self,
_buf: &[IoSlice<'_>],
) -> (usize, SocketResult);
fn socket_ref(&self) -> &TcpStream ⓘ;
fn socket_mut(&mut self) -> &mut TcpStream ⓘ;
fn peer_addr(&self) -> Option<SocketAddr>;
fn protocol(&self) -> TransportProtocol;
fn read_error(&self);
fn write_error(&self);
// Provided methods
fn socket_wants_write(&self) -> bool { ... }
fn socket_close(&mut self) { ... }
fn socket_write_then_close(&mut self, buf: &[u8]) -> (usize, SocketResult) { ... }
fn session_ulid(&self) -> Option<Ulid> { ... }
}Required Methods§
fn socket_read(&mut self, buf: &mut [u8]) -> (usize, SocketResult)
fn socket_write(&mut self, buf: &[u8]) -> (usize, SocketResult)
fn socket_write_vectored( &mut self, _buf: &[IoSlice<'_>], ) -> (usize, SocketResult)
fn socket_ref(&self) -> &TcpStream ⓘ
fn socket_mut(&mut self) -> &mut TcpStream ⓘ
Sourcefn peer_addr(&self) -> Option<SocketAddr>
fn peer_addr(&self) -> Option<SocketAddr>
Peer address of this connection, preferring a snapshot taken when the
handler was built over a live getpeername(2).
getpeername(2) fails with ENOTCONN the moment the peer resets, so a
live lookup renders peer=None on exactly the error lines an operator
reads during an incident. It also reports the transport peer, which on a
PROXY-protocol frontend is the load balancer rather than the client the
rest of the session is logged against.
Implementations that cache an address (SessionTcpStream,
FrontRustls) return it and fall back to the live lookup only when
they have none; the raw TcpStream impl carries no context and has
nothing but the live lookup. Deliberately has no default body: a new
handler must state which of the two it is.
fn protocol(&self) -> TransportProtocol
fn read_error(&self)
fn write_error(&self)
Provided Methods§
fn socket_wants_write(&self) -> bool
fn socket_close(&mut self)
Sourcefn socket_write_then_close(&mut self, buf: &[u8]) -> (usize, SocketResult)
fn socket_write_then_close(&mut self, buf: &[u8]) -> (usize, SocketResult)
Write buf, then begin the close Self::socket_close begins, and
report what Self::socket_write would for buf.
The close is begun only when the whole of buf was accepted, so a
caller that gets back less resumes with the rest and the close still
follows its last byte. A handler without a close of its own does
exactly the two calls; FrontRustls puts the plaintext and its
close_notify behind one flush, so the last application bytes and
the alert leave in one writev(2) instead of two.
Sourcefn session_ulid(&self) -> Option<Ulid>
fn session_ulid(&self) -> Option<Ulid>
Returns the owning connection’s session ULID when known. Used by
log_socket_context! to render the [<session_ulid> - - -] segment
of the socket-layer log prefix, matching the format used by the
rest of the mux stack. Returns None for contextless implementations
(e.g. raw mio::TcpStream); the macro renders - in the ULID slot.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl SocketHandler for TcpStream
impl SocketHandler for TcpStream
Source§fn peer_addr(&self) -> Option<SocketAddr>
fn peer_addr(&self) -> Option<SocketAddr>
No context to cache: a bare stream is all there is, so this is the live
lookup and renders None once the peer has reset. Call sites that need
a surviving address use SessionTcpStream or FrontRustls.
Fully-qualified so it reads as the inherent mio method, not a
recursive call into the trait method being defined.