Skip to main content

serve_on

Function serve_on 

Source
pub async fn serve_on<F>(listener: Listener, handler: F) -> Result<()>
where F: FnMut(HttpRequest) -> HttpResponse + Send + 'static,
Expand description

Serve on an already-bound Listener, looping forever — the TOKIO engine. Connections run CONCURRENTLY (one task each, capped at MAX_INFLIGHT) with HTTP/1.1 keep-alive, so a stalled or held-open connection never blocks the rest; handler calls are serialized on a mutex (one at a time, matching the single-threaded interpreter tier). A handler panic answers the shared internal_error 500 for that request and the server keeps serving. A parse error answers 400 and closes; a closed/errored socket just ends that connection.

A pre-bound tokio listener always serves on the tokio engine (the io_uring engine binds its own SO_REUSEPORT shard listeners); engine selection lives in serve/serve_with_statics. If LOGOS_HTTP_ENGINE=uring is set anyway, this says so on stderr rather than silently ignoring the knob.