xKit
Welcome to the xKit documentation. xKit is a collection of low-level C building blocks for event-driven, asynchronous programming on macOS and Linux. (Windows is on the roadmap but not a near-term priority).
- Designed and reviewed by Leo X.
- Coded by Codebuddy with claude-4.6-opus
Architecture Overview
graph TD
subgraph "Application Layer"
APP["User Application"]
end
subgraph "High-Level Modules"
XHTTP["xhttp<br/>HTTP Client & Server & WebSocket"]
XLOG["xlog<br/>Async Logging"]
end
subgraph "Networking Layer"
XNET["xnet<br/>URL / DNS / TLS Config / TCP"]
end
subgraph "Buffer Layer"
XBUF["xbuf<br/>Buffer Primitives"]
end
subgraph "Core Layer"
XBASE["xbase<br/>Core Primitives"]
end
APP --> XHTTP
APP --> XLOG
APP --> XNET
APP --> XBUF
APP --> XBASE
XHTTP --> XNET
XHTTP --> XBASE
XHTTP --> XBUF
XNET --> XBASE
XLOG --> XBASE
XBUF -->|"atomic.h"| XBASE
style XBASE fill:#50b86c,color:#fff
style XBUF fill:#4a90d9,color:#fff
style XNET fill:#e74c3c,color:#fff
style XHTTP fill:#f5a623,color:#fff
style XLOG fill:#9b59b6,color:#fff
Module Index
xbase — Core Primitives
The foundation of xKit. Provides event loop, timers, tasks, async sockets, memory management, and lock-free data structures.
| Sub-Module | Description |
|---|---|
| event.h | Cross-platform event loop — kqueue (macOS) / epoll (Linux) / poll (fallback) |
| timer.h | Monotonic timer with Push (thread-pool) and Poll (lock-free MPSC) fire modes |
| task.h | N:M task model — lightweight tasks multiplexed onto a thread pool |
| socket.h | Async socket abstraction with idle-timeout support |
| memory.h | Reference-counted allocation with vtable-driven lifecycle |
| error.h | Unified error codes and human-readable messages |
| heap.h | Min-heap with index tracking (used by timer subsystem) |
| mpsc.h | Lock-free multi-producer / single-consumer queue |
| atomic.h | Compiler-portable atomic operations (GCC/Clang builtins) |
| log.h | Per-thread callback-based logging with optional backtrace |
| backtrace.h | Platform-adaptive stack trace (libunwind > execinfo > stub) |
time.h | Time utilities: xMonoMs() (monotonic) and xWallMs() (wall-clock) |
xbuf — Buffer Primitives
Three buffer types for different I/O patterns — linear, ring, and block-chain.
| Sub-Module | Description |
|---|---|
| buf.h | Linear auto-growing byte buffer with 2× expansion |
| ring.h | Fixed-size ring buffer with power-of-2 mask indexing |
| io.h | Reference-counted block-chain I/O buffer with zero-copy split/cut |
xnet — Networking Primitives
Shared networking utilities: URL parser, async DNS resolver, and TLS configuration types used by higher-level modules.
| Sub-Module | Description |
|---|---|
| url.h | Lightweight URL parser with zero-copy component extraction |
| dns.h | Async DNS resolution via thread-pool offload |
| tls.h | Shared TLS configuration types (client & server) |
| tcp.h | Async TCP connection, connector & listener with optional TLS |
xhttp — Async HTTP Client & Server & WebSocket
Full-featured async HTTP framework: libcurl-powered client with SSE streaming, event-driven server with HTTP/1.1 & HTTP/2 (h2c), TLS support (OpenSSL / mbedTLS), and RFC 6455 WebSocket (server & client).
| Sub-Module | Description |
|---|---|
| client.h | Async HTTP client (GET / POST / PUT / DELETE / PATCH / HEAD) |
| sse.c | SSE streaming client with W3C-compliant event parsing |
| server.h | Event-driven HTTP server with HTTP/1.1 and HTTP/2 (h2c) |
| ws.h | RFC 6455 WebSocket server with handler-initiated upgrade |
| ws.h | RFC 6455 WebSocket client with async connect |
| transport.h | Pluggable TLS transport layer (OpenSSL / mbedTLS / plain) |
xlog — Async Logging
High-performance async logger with MPSC queue, three flush modes, and file rotation.
| Sub-Module | Description |
|---|---|
| logger.h | Async logger with Timer / Notify / Mixed modes and XLOG_* macros |
bench — End-to-End Benchmarks
End-to-end benchmark results comparing xKit against other frameworks in real-world scenarios.
| Benchmark | Description |
|---|---|
| HTTP/1.1 Server | xKit single-threaded HTTP/1.1 server vs Go net/http — GET/POST throughput and latency |
| HTTP/2 Server | xKit single-threaded HTTP/2 (h2c) server vs Go net/http h2c — GET/POST throughput and latency |
| HTTPS Server | xKit single-threaded HTTPS (TLS 1.3) server vs Go net/http — GET/POST throughput and latency |
Quick Navigation Guide
By Use Case
| I want to... | Start here |
|---|---|
| Build an event-driven server | xbase/event.h → xbase/socket.h |
| Schedule timers | xbase/timer.h |
| Run tasks on a thread pool | xbase/task.h |
| Make async HTTP requests | xhttp/client.h |
| Stream LLM API responses (SSE) | xhttp/sse.c |
| Build an HTTP server | xhttp/server.h |
| Add WebSocket server | xhttp/ws.h |
| Connect as WebSocket client | xhttp/ws.h |
| Parse a URL | xnet/url.h |
| Resolve DNS asynchronously | xnet/dns.h |
| Make async TCP connections | xnet/tcp.h |
| Build a TCP server | xnet/tcp.h |
| Configure TLS | xnet/tls.h |
| Enable TLS (HTTPS) | xhttp/transport.h |
| Add async logging | xlog/logger.h |
| Manage object lifecycles | xbase/memory.h |
| Choose the right buffer type | xbuf overview |
| Build a lock-free producer/consumer pipeline | xbase/mpsc.h |
| See micro-benchmark results | Each module doc has a Benchmark section (e.g. mpsc.h) |
| See HTTP server benchmarks | HTTP/1.1 · HTTP/2 · HTTPS |
By Dependency Level
Level 0 (no deps) : atomic.h, error.h, time.h
Level 1 (atomic only) : heap.h, mpsc.h
Level 2 (Level 0-1) : memory.h, log.h, backtrace.h, buf.h, ring.h
Level 3 (Level 0-2) : event.h, io.h, url.h, tls.h
Level 4 (event loop) : timer.h, task.h, socket.h, dns.h, tcp.h, logger.h, client.h, server.h, ws.h
Module Dependency Graph
graph BT
subgraph "Level 0"
ATOMIC["atomic.h"]
ERROR["error.h"]
TIME["time.h"]
end
subgraph "Level 1"
HEAP["heap.h"]
MPSC["mpsc.h"]
end
subgraph "Level 2"
MEMORY["memory.h"]
LOG["log.h"]
BT_["backtrace.h"]
BUF["buf.h"]
RING["ring.h"]
end
subgraph "Level 3"
EVENT["event.h"]
IO["io.h"]
URL["url.h"]
TLS_CONF["tls.h"]
end
subgraph "Level 4"
TIMER["timer.h"]
TASK["task.h"]
SOCKET["socket.h"]
DNS["dns.h"]
TCP["tcp.h"]
LOGGER["logger.h"]
CLIENT["client.h"]
SERVER["server.h"]
WS["ws.h"]
end
HEAP --> ATOMIC
MPSC --> ATOMIC
MEMORY --> ERROR
LOG --> BT_
IO --> ATOMIC
IO --> BUF
EVENT --> HEAP
EVENT --> MPSC
EVENT --> TIME
TIMER --> EVENT
TASK --> EVENT
SOCKET --> EVENT
DNS --> EVENT
TCP --> EVENT
TCP --> DNS
TCP --> SOCKET
TCP --> TLS_CONF
LOGGER --> EVENT
LOGGER --> MPSC
LOGGER --> LOG
CLIENT --> EVENT
CLIENT --> BUF
CLIENT --> URL
CLIENT --> DNS
CLIENT --> TLS_CONF
SERVER --> SOCKET
SERVER --> BUF
SERVER --> TLS_CONF
WS --> SERVER
WS --> URL
style EVENT fill:#50b86c,color:#fff
style URL fill:#e74c3c,color:#fff
style DNS fill:#e74c3c,color:#fff
style TCP fill:#e74c3c,color:#fff
style TLS_CONF fill:#e74c3c,color:#fff
style CLIENT fill:#f5a623,color:#fff
style SERVER fill:#f5a623,color:#fff
style WS fill:#f5a623,color:#fff
style LOGGER fill:#9b59b6,color:#fff
Build & Test
# Build
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
cmake --build build --parallel
# Test
ctest --test-dir build --output-on-failure --parallel 4
See the project README for full build instructions, prerequisites, and container-based Linux testing.
Benchmark
Micro-benchmark results are included in each module's documentation page (see the Benchmark section at the bottom of each page, e.g. mpsc.h, buf.h).
End-to-end benchmarks:
| Benchmark | Description |
|---|---|
| HTTP/1.1 Server | xKit vs Go net/http — 152K req/s single-threaded, +15~60% faster across all scenarios |
| HTTP/2 Server | xKit vs Go h2c — single-threaded HTTP/2 (h2c) throughput comparison |
| HTTPS Server | xKit vs Go HTTPS — single-threaded TLS 1.3 throughput comparison |
License
MIT © 2025-present Leo X. and xKit contributors