pub async fn handle_connection<H, T, const N: usize>(
io: T,
buf: &mut [u8],
keepalive_timeout_ms: Option<u32>,
task_id: impl Display + Copy,
handler: H,
)Expand description
A convenience function to handle multiple HTTP requests over a single socket stream, using the specified handler.
The socket stream will be closed only in case of error, or until the client explicitly requests that
either with a hard socket close, or with a Connection: Close header.
A note on timeouts:
- The function does NOT - by default - establish any timeouts on the IO operations except
an optional timeout for detecting idle connections, so that they can be closed and thus make
the server available for accepting new connections.
It is up to the caller to wrap the acceptor type with
edge_nal::WithTimeoutto establish timeouts on the socket produced by the acceptor. - Similarly, the server does NOT establish any timeouts on the complete request-response cycle.
It is up to the caller to wrap their complete or partial handling logic with
edge_nal::with_timeout, or its whole handler withedge_nal::WithTimeout, so as to establish a global or semi-global request-response timeout.
Parameters:
io: A socket streambuf: A work-area buffer used by the implementationkeepalive_timeout_ms: An optional timeout in milliseconds for detecting an idle keepalive connection that should be closed. If not provided, the server will not close idle connections.task_id: An identifier for the task, used for logging purposeshandler: An implementation ofHandlerto handle incoming requests