Skip to main content

serve

Function serve 

Source
pub async fn serve<S, H>(
    scheduler: &S,
    listener: S::Socket,
    handler: &H,
    options: &Options,
    cancellation: &Cancellation,
) -> Result<Statistics, Error>
Expand description

Serve an already-bound listener with bounded concurrent connection futures. No hidden tasks or detached jobs are created. Cancellation stops acceptance, closes the owned listener, then cancels active exchanges and joins their retirement. Individual peer/handler failures are counted without stopping other peers.

Transient accept failures do not stop the listener: those belonging to one pending peer, such as ECONNABORTED, are retried immediately, and resource exhaustion, such as EMFILE, pauses acceptance briefly on the scheduler’s clock while existing connections continue. Repeated per-peer failures also pause after a few immediate retries, so a persistent one cannot spin. Both are counted in Statistics::accept_errors. Any other accept failure, including scheduler closure or a failed backoff wait, is returned after the same shutdown sequence, in preference to a listener close failure.