No matching definitions.

httpd/server

src/httpd/server.tur

POSIX socket listener + worker dispatch.

Since: H6 (pool dispatch added in H7)

defn

server-start

(server-start [port : int handler ptr<void>] :)

bind a TCP listener on `port` and dispatch requests to

portTCP port to bind on (IPv4, INADDR_ANY)
handler:ptr<void> function pointer with C signature
int64_t (*)(int64_t). In Turmeric, define it as a top-level
defn of type [req :int] :int returning a Response handle, and
pass the defn name. The handler is invoked from a worker
thread; it must be Send-safe. The server takes ownership of
the Response it returns (it is freed after the response is
written, regardless of return value of write).

:ptr<void> -- opaque server handle. Pass to server-stop to shut down, or NULL if the listening socket / pool could not be created.

(defn my-handler [req :int] :int
    (resp-ok "text/plain" "Hello"))

  (let [srv (server-start 8080 my-handler)]
    ;; ... handle SIGINT, etc. ...
    (server-stop srv))

Since: H6 (pool default added in H7)

defn

server-start-pool

(server-start-pool [port : int handler ptr<void> size : int] :)

like server-start but with an explicit pool size.

portTCP port to bind on
handler:ptr<void> request handler (see server-start)
sizenumber of worker threads in the pool (clamped to >= 1)

:ptr<void> -- opaque server handle, or NULL on failure.

(def srv (server-start-pool 8080 my-handler 32))

Since: H7

defn

server-start-spawn

(server-start-spawn [port : int handler ptr<void>] :)

thread-per-connection fallback (H6 dispatch mode).

portTCP port to bind on
handler:ptr<void> request handler (see server-start)

:ptr<void> -- opaque server handle, or NULL on failure.

(def srv (server-start-spawn 8080 my-handler))

Since: H7

defn

server-stop

(server-stop [s ptr<void>] :)

signal the listener to stop, close the socket, join the

s:ptr<void> server handle returned by server-start (or NULL: no-op).

:void

(server-stop srv)

Since: H6 (pool join added in H7)

Internal definitions
srv-make-listener
srv-accept-one
srv-close-fd
srv-shutdown-fd
srv-recv-request
srv-raw-bytes
srv-raw-len
srv-raw-free
srv-write-all
srv-call-handler
srv-worker-loop
srv-warg->int
srv-warg-fd
srv-warg-handler
srv-warg-free
srv-null-ptr
srv-spawn-worker
srv-state-new
srv-state->int
srv-state-listen-fd
srv-state-handler-ptr
srv-state-stopping?
srv-state-mark-stopping
srv-state-close-listen
srv-state-set-thread
srv-state-get-thread
srv-state-set-pool
srv-state-pool
srv-state-pool-int
srv-state-free
srv-listener-loop
srv-spawn-listener
srv-join-listener
srv-default-pool-size