Declarations
Public Only
namespace net
type Socket = usize
struct timeval {
var tv_sec : long
var tv_usec : long
}
timeval struct for setsockopt SO_RCVTIMEO
struct sockaddr_in {
var sin_family : u16
var sin_port : u16
var sin_addr : in_addr
var sin_zero : char[8]
}
func set_recv_timeout(s : Socket, secs : long, usecs : long) : void
helper: set socket recv timeout (seconds + microseconds)
func set_keep_alive(s : Socket, enable : bool) : void
helper: set keep alive
func listen_addr(addr_str : *char, port : uint) : Socket
listen by address string and port using getaddrinfo -> bind -> listen loop
func send_all(s : Socket, p : *char, len : int) : void
func close_socket(s : Socket) : void
namespace io
===== Buffer implementation =====
namespace http
===== HTTP utilities and parser =====
func strcasecmp(a : *char, b : *char) : int
helper: simple ASCII case-insensitive strcmp
struct Body {
var sock : Socket
var buf : *Buffer
var remaining : isize
var chunked : bool
var timeout_secs : long
var max_body : usize
var closed : bool
var cur_chunk_left : usize
var seen_total : usize
}
Body: lazy reader for request body. Does NOT close the socket by itself.
func empty_make() : Body
how many body bytes have been delivered to user (enforce max_body)
low-level recv helper that honors timeout and returns <=0 on error/timeout
Helper: copy up to `want` bytes from the already-read buffer into dst, returning copied count.
PUBLIC: read up to `cap` bytes into dst; returns number of bytes read or <=0 on error.
read all remaining body into a string (useful for small bodies)
read exactly `n` bytes (or return None on error/EOF)
func drain(b : &Body) : bool
drain remaining body to /dev/null (useful when you want to discard the body)
func close(b : &Body) : void
close returns resources (no-op here except mark closed)
struct ResponseWriter {
var sock : Socket
var headers : HeaderMap
var status : uint
var sent_headers : bool
}
func send_file(self : &ResponseWriter, path_view : &string_view, content_type : &string_view) : bool
Adds a zero-copy send_file method to ResponseWriter.
func finish(self : &ResponseWriter) : void
func delete(self : *ResponseWriter) : void
Parse query string into simple vector of pairs
namespace web
===== Router + middleware =====
func delete(self : *Route) : void
namespace server
===== Server wiring all pieces together =====
struct ServerConfig {
var addr : string
var worker_count : uint
var header_timeout_secs : long
var max_header_bytes : usize
var max_headers : uint
var max_body_bytes : usize
}
func constructor() : ServerConfig
func delete(self : *ServerConfig) : void
struct Server {
var cfg : ServerConfig
var pool : ThreadPool
var listen_sock : Socket
var router : Router
var run : bool
}
production handler: parse request, route, and respond
func accept_main(arg : *void) : *void
accept loop — submit work to threadpool
func start(self : &Server, port : uint) : void
func serve_non_iocp(self : &Server, port : uint) : void
func serve(self : &Server, port : uint) : void
func shutdown(self : &Server) : void
func delete(self : *Server) : void