main.ch
Declarations
Public Only
Publicnamespace net
namespace net
Publictypealias Socket
type Socket = usize
Publicstruct timeval
struct timeval
timeval struct for setsockopt SO_RCVTIMEO
Publicfunction inet_pton
func inet_pton(Family : int, pszAddrString : *char, pAddrBuf : *void) : int
Publicstruct in_addr
struct in_addr
IPv4 sockaddr structs (C layout)
Publicstruct sockaddr_in
struct sockaddr_in
Publicfunction set_recv_timeout
func set_recv_timeout(s : Socket, secs : long, usecs : long) : void
helper: set socket recv timeout (seconds + microseconds)
Publicfunction set_keep_alive
func set_keep_alive(s : Socket, enable : bool) : void
helper: set keep alive
Publicfunction htons_port
func htons_port(p : u16) : u16
Publicfunction listen_addr
func listen_addr(addr_str : *char, port : uint) : Socket
listen by address string and port using getaddrinfo -> bind -> listen loop
Publicfunction send_all
func send_all(s : Socket, p : *char, len : int) : void
Publicfunction close_socket
func close_socket(s : Socket) : void
Publicnamespace io
namespace io
===== Buffer implementation =====
Publicnamespace http
namespace http
===== HTTP utilities and parser =====
Publicstruct HeaderMap
struct HeaderMap
Publicfunction strcasecmp
func strcasecmp(a : *char, b : *char) : int
helper: simple ASCII case-insensitive strcmp
Publicstruct Body
struct Body
Body: lazy reader for request body. Does NOT close the socket by itself.
Publicfunction empty_make
func empty_make() : Body
how many body bytes have been delivered to user (enforce max_body)
function body_recv
low-level recv helper that honors timeout and returns <=0 on error/timeout
function copy_from_buffer
Helper: copy up to `want` bytes from the already-read buffer into dst, returning copied count.
function read
PUBLIC: read up to `cap` bytes into dst; returns number of bytes read or <=0 on error.
Publicfunction read_to_string
read all remaining body into a string (useful for small bodies)
Publicfunction read_exact
read exactly `n` bytes (or return None on error/EOF)
Publicfunction drain
drain remaining body to /dev/null (useful when you want to discard the body)
Publicfunction close
close returns resources (no-op here except mark closed)
Publicstruct Request
struct Request
Publicstruct ResponseWriter
struct ResponseWriter
Publicfunction constructor
Publicfunction set_header
Publicfunction set_header_view
Publicfunction send_headers
Publicfunction write_string
Publicfunction write_view
Publicfunction send_file
func send_file(self : &ResponseWriter, path_view : &string_view, content_type : &string_view) : bool
Adds a zero-copy send_file method to ResponseWriter.
Publicfunction finish
func finish(self : &ResponseWriter) : void
function delete
func delete(self : *ResponseWriter) : void
Publicfunction hex_value
func hex_value(c : char) : int
Publicfunction parse_query
Parse query string into simple vector of pairs
Publicnamespace web
namespace web
===== Router + middleware =====
Publictypealias Handler
Publicstruct Router
struct Router
Publicnamespace server
namespace server
===== Server wiring all pieces together =====
Publicstruct ServerConfig
struct ServerConfig
Publicfunction constructor
func constructor() : ServerConfig
function delete
func delete(self : *ServerConfig) : void
Publicstruct Server
struct Server
Publicfunction constructor
Publicfunction handle_conn
production handler: parse request, route, and respond
Publicfunction accept_main
func accept_main(arg : *void) : *void
accept loop — submit work to threadpool
Publicfunction start
func start(self : &Server, port : uint) : void
Publicfunction serve_non_iocp
func serve_non_iocp(self : &Server, port : uint) : void
Publicfunction serve
func serve(self : &Server, port : uint) : void
Publicfunction shutdown
func shutdown(self : &Server) : void
function delete
func delete(self : *Server) : void