23 size_t body_bytes,
double duration_ms,
36typedef void (*
KlLogFn)(
int level,
const char *fmt, va_list ap,
40#define KL_DEFAULT_MAX_CONNS 256
42#define KL_DEFAULT_READ_TIMEOUT 30000
44#define KL_DEFAULT_MAX_BODY_SIZE (1024 * 1024)
KlBodyReader *(* KlBodyReaderFactory)(KlAllocator *alloc, const KlRequest *req, void *user_data)
Factory creates a body reader for a given request.
Definition body_reader.h:34
KlError
Diagnostic error codes for Keel public functions.
Definition error.h:11
void(* KlHandler)(KlRequest *req, KlResponse *res, void *user_data)
Route handler function.
Definition router.h:11
int(* KlMiddleware)(KlRequest *req, KlResponse *res, void *user_data)
Middleware function signature.
Definition router.h:18
int kl_server_ws(KlServer *s, const char *pattern, KlWsServerConfig *config)
Register a WebSocket endpoint. Matches GET with Upgrade: websocket.
int kl_server_run(KlServer *s)
Start the event loop (blocks until stopped).
int kl_server_route(KlServer *s, const char *method, const char *pattern, KlHandler handler, void *user_data, KlBodyReaderFactory body_reader)
Register a route on the server.
void kl_server_free(KlServer *s)
Free all server resources (pool, router, event loop).
int kl_server_use_post(KlServer *s, const char *method, const char *pattern, KlMiddleware fn, void *user_data)
Register post-body middleware on the server.
void kl_server_stop(KlServer *s)
Request server shutdown. If drain_timeout_ms is configured, enters drain mode first (stops accepting,...
int kl_server_init(KlServer *s, const KlConfig *config)
Initialize server with the given configuration.
void(* KlAccessLogFn)(const KlRequest *req, int status, size_t body_bytes, double duration_ms, void *user_data)
Access log callback — called after each response is fully sent. NULL = disabled.
Definition server.h:22
void kl_server_stats(const KlServer *s, KlServerStats *out)
Populate a stats snapshot from current server state.
void(* KlLogFn)(int level, const char *fmt, va_list ap, void *user_data)
Diagnostic log callback. NULL = fprintf(stderr) fallback.
Definition server.h:36
KlParser *(* KlParserFactory)(KlAllocator *alloc)
Factory function for creating request parsers.
Definition server.h:19
int kl_server_use(KlServer *s, const char *method, const char *pattern, KlMiddleware fn, void *user_data)
Register pre-body middleware on the server.
Bring-your-own allocator vtable.
Definition allocator.h:12
An in-flight async operation that suspends a connection.
Definition async.h:29
Compression configuration for KlConfig.
Definition compress.h:81
KlAccessLogFn access_log
Definition server.h:54
KlH2ServerConfig * h2
Definition server.h:62
int install_signal_handlers
Definition server.h:58
KlParserFactory parser
Definition server.h:53
KlCompressConfig * compress
Definition server.h:65
int port
Definition server.h:47
int read_timeout_ms
Definition server.h:50
void * access_log_data
Definition server.h:55
int max_connections
Definition server.h:49
KlTlsConfig * tls
Definition server.h:61
size_t max_body_size
Definition server.h:63
const char * bind_addr
Definition server.h:48
KlAllocator * alloc
Definition server.h:52
int body_timeout_ms
Definition server.h:51
void * log_user_data
Definition server.h:57
KlLogFn log_fn
Definition server.h:56
int drain_timeout_ms
Definition server.h:60
size_t max_header_size
Definition server.h:64
Definition connection.h:86
Composable event loop context.
Definition event_ctx.h:42
Definition h2_server.h:74
Server load statistics — read-only snapshot for load-shedding decisions.
Definition server.h:159
int async_suspended
Definition server.h:162
int active_connections
Definition server.h:160
int listen_paused
Definition server.h:163
int max_connections
Definition server.h:161
KlEventCtx ev
Definition server.h:78
KlConfig config
Definition server.h:71
int bound_port
Definition server.h:80
KlAllocator alloc_storage
Definition server.h:72
_Atomic int running
Definition server.h:82
KlRouter router
Definition server.h:76
KlFileIO * file_io
Definition server.h:86
KlAsyncOp * async_ops
Definition server.h:85
KlConnPool pool
Definition server.h:77
KlCompressConfig compress_storage
Definition server.h:75
KlError last_error
Definition server.h:87
KlH2ServerConfig h2_storage
Definition server.h:74
int listen_fd
Definition server.h:79
uint64_t drain_deadline_ms
Definition server.h:84
int listen_paused
Definition server.h:81
_Atomic int draining
Definition server.h:83
KlTlsConfig tls_storage
Definition server.h:73
TLS configuration for KlConfig.
Definition tls.h:108
Definition websocket_server.h:34
void * user_data
Definition websocket_server.h:36