pub trait ListenerExt: Sized + Listener {
// Provided methods
fn limit_connections(self, limit: usize) -> ConnLimiter<Self> { ... }
fn tap_io<F>(self, tap_fn: F) -> TapIo<Self, F>
where F: FnMut(&mut Self::Io) + Send + 'static { ... }
}Expand description
Extensions to Listener.
Provided Methods§
Sourcefn limit_connections(self, limit: usize) -> ConnLimiter<Self>
fn limit_connections(self, limit: usize) -> ConnLimiter<Self>
Limit the number of concurrent connections. Once the limit has been reached, no additional connections will be accepted until an existing connection is closed. Listener implementations will typically continue to queue incoming connections, up to an OS and implementation-specific listener backlog limit.
Compare tower::limit::concurrency, which provides ways to
limit concurrent in-flight requests, but does not limit connections
that are idle or in the process of sending request headers.
Sourcefn tap_io<F>(self, tap_fn: F) -> TapIo<Self, F>
fn tap_io<F>(self, tap_fn: F) -> TapIo<Self, F>
Run a mutable closure on every accepted Io.
§Example
use axum::{Router, routing::get, serve::ListenerExt};
use tracing::trace;
let router = Router::new().route("/", get(|| async { "Hello, World!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
.await
.unwrap()
.tap_io(|tcp_stream| {
if let Ok(addr) = tcp_stream.peer_addr() {
trace!("accepted connection from {addr}");
}
});
axum::serve(listener, router).await;Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".