Browse the docs

silk.http.server_native.

Accepts native socket connections and serves each one with silk.http.server.

When to use#

Make a listener with silk.net.socket_native, then call serveNext in a loop. Each call accepts one connection and serves it with your ConnectionHandler until the handler returns.

Details#

serveNext serves one connection at a time, on the calling task. This module has no queue, router, supervisor, or background task. To serve connections at the same time, start tasks yourself.

Errors#

  • NativeSocketError if the accept fails or the deadline passes.

  • ServerError, BufferError, and OutOfMemoryError from silk.http.server.

  • The error of the handler.

Gotchas#

The whole module exists only on Darwin on aarch64, and on Linux with GNU libc on x86_64 or aarch64. On other targets, an import from it fails to compile.

Import as HttpServerNative with import silk.http.server_native { HttpServerNative }.

Public declarations: 2.

HttpServerNative#

silk
pub struct HttpServerNative

An empty marker type for this module.

serveNext#

silk
pub effect<'env> fn serveNext<
    'listener,
    A,
    E,
    ?HandlerRequirements,
    H: ConnectionHandler<NativeConnection, A, E ? HandlerRequirements> + 'env,
    'env,
  >(
    listener: &'listener mut Listener,
    limits: Limits,
    acceptDeadline: Option<Instant>,
    handler: H,
  ) -> A
  ! E | NativeSocketError | ServerError | BufferError | OutOfMemoryError
  ? HandlerRequirements | &mut Allocator | &mut MonotonicClock
  where HandlerRequirements in Without<HandlerRequirements, ByteDuplex>

Accepts one connection from listener, and serves it with handler.

Details#

The accept waits until acceptDeadline, or with no limit if it is None. Then it calls withConnection of silk.http.server with limits. The socket is closed when the handler returns or fails. Call it in a loop. It serves one connection at a time, on the calling task, with no queue, router, supervisor, or background task. To serve connections at the same time, start tasks yourself.

Errors#

  • NativeSocketError if the accept fails or the deadline passes.

  • ServerError, BufferError, and OutOfMemoryError from silk.http.server.

  • The error of the handler.

Gotchas#

It exists only on Darwin on aarch64, and on Linux with GNU libc on x86_64 or aarch64.

Category: HTTP.

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.

View the source of this page