~/bend-docscommunity

src/server.bend relies on unsafe/foreign

raw source on the hub · import 0x2731c2a5d4185b57cf5353061639642e/src/server.bend as Server

2 imports
import Base
import ./json.bend as Json

Types

type ServerHeader source · line 4 · raw

Data

type Config source · line 8 · raw

Data

One listener lifetime per process. Zero port asks the OS for a free port.

type TransportLimits source · line 15 · raw

Data

Accepted socket budget and absolute time to receive the complete request.

type Started source · line 18 · raw

Data

type Incoming source · line 22 · raw

Data

type Next source · line 25 · raw

Data

type IncomingHead source · line 30 · raw

Data

Opt-in upload streaming exposes validated request metadata before the body.

type StreamNext source · line 33 · raw

Data

type BodyNext source · line 37 · raw

Data

type Reply source · line 42 · raw

Data

type Replied source · line 45 · raw

Data

type ConnectionMode source · line 50 · raw

Data

Streaming is opt-in. Ordinary Reply keeps its connection-closing behavior.

type StreamHead source · line 54 · raw

Data

type Metrics source · line 200 · raw

Data

Process/listener lifetime counters and current bounded gauges. No reset API.

Definitions

def config source · line 11 · raw

@address:String -> @port:U32 -> Config

def json source · line 57 · raw

@status:U32 -> @body:String -> Reply

def encoded_reply source · line 60 · raw

@status:U32 -> @result:0x2731c2a5d4185b57cf5353061639642e/src/json.EncodeResult -> IO(Reply)

def json_value source · line 67 · raw

@status:U32 -> @value:0x2731c2a5d4185b57cf5353061639642e/src/json.Json -> IO(Reply)

def with_header source · line 70 · raw

@name:String -> @value:String -> @reply:Reply -> Reply

def header_step source · line 76 · raw

@equal:Bool -> @value:String -> @rest:(@_:Unit -> Maybe<&1, String>) -> Maybe<&1, String>

Incoming field names are normalized to lowercase by the native boundary.

def stream_start_mode source · line 119 · raw

@id:U32 -> @status:U32 -> @headers:List<&2, ServerHeader> -> @connection:ConnectionMode -> IO(Replied)

def Server.stream_start source · line 125 · raw

@id:U32 -> @head:StreamHead -> IO(Replied)

Begin one bounded chunked response. Statuses that forbid bodies are rejected.

def sse_head source · line 136 · raw

@connection:ConnectionMode -> StreamHead

def finish_reply source · line 152 · raw

@id:U32 -> @result:Replied -> IO(Unit)

def dispatch_live source · line 161 · raw

@handler:(@_:Incoming -> IO(Reply)) -> @request:Incoming -> IO(Unit)

def discard_request source · line 170 · raw

@request:Incoming -> IO(Unit)

def dispatch_active source · line 174 · raw

@active:Bool -> @handler:(@_:Incoming -> IO(Reply)) -> @request:Incoming -> IO(Unit)

def dispatch source · line 179 · raw

@handler:(@_:Incoming -> IO(Reply)) -> @request:Incoming -> IO(Unit)

def serve_next source · line 185 · raw

@handler:(@_:Incoming -> IO(Reply)) -> @rest:(@_:Unit -> IO(Unit)) -> @next:Next -> IO(Unit)

def metrics_json source · line 206 · raw

@metrics:Metrics -> 0x2731c2a5d4185b57cf5353061639642e/src/json.Json

Effects (foreign code)

effect Server.listen source · line 87 · raw

@config:Config -> IO(Started)

foreign: src/effects/server.c

effect Server.listen_with_limits source · line 90 · raw

@config:Config -> @limits:TransportLimits -> IO(Started)

foreign: src/effects/server.c

effect Server.listen_streaming source · line 95 · raw

@config:Config -> IO(Started)

Request streaming is a listener-wide opt-in. Buffered listeners retain their existing Incoming/next API and allocation behavior.

foreign: src/effects/server.c

effect Server.listen_streaming_with_limits source · line 98 · raw

@config:Config -> @limits:TransportLimits -> IO(Started)

foreign: src/effects/server.c

effect Server.next source · line 101 · raw

IO(Next)

foreign: src/effects/server.c

effect Server.next_stream source · line 104 · raw

IO(StreamNext)

foreign: src/effects/server.c

effect Server.body_next source · line 108 · raw

@id:U32 -> IO(BodyNext)

Bounded pending text is retained per request while the consumer works.

foreign: src/effects/server.c

effect Server.reply source · line 111 · raw

@id:U32 -> @reply:Reply -> IO(Replied)

foreign: src/effects/server.c

effect Server.stream_start_raw source · line 116 · raw

@id:U32 -> @status:U32 -> @headers:List<&2, ServerHeader> -> @keep_alive:U32 -> IO(Replied)

Native boundary uses a numeric flag instead of relying on the compiler's private representation of a nullary data constructor.

foreign: src/effects/server.c

effect Server.stream_write source · line 130 · raw

@id:U32 -> @chunk:String -> IO(Replied)

The aggregate body across writes is limited to 16 MiB.

foreign: src/effects/server.c

effect Server.stream_end source · line 133 · raw

@id:U32 -> IO(Replied)

foreign: src/effects/server.c

effect Server.active source · line 142 · raw

@id:U32 -> IO(Bool)

Cooperative checkpoint; does not preempt work or undo effects.

foreign: src/effects/server.c

effect Server.finish source · line 146 · raw

@id:U32 -> IO(Unit)

Manual dispatch must release its handler budget after all work finishes.

foreign: src/effects/server.c

effect Server.stop source · line 149 · raw

IO(Unit)

foreign: src/effects/server.c

effect Server.metrics source · line 203 · raw

IO(Metrics)

foreign: src/effects/server.c

Unsafe

unsafe serve source · line 196 · raw

@-handler:(@_:Incoming -> IO(Reply)) -> IO(Unit)

The accept loop ends on external shutdown, not a pure termination proof.