$ show nanomsg/nng
NNG (nanomsg-next-gen) is a lightweight, high-performance asynchronous messaging library written in C. It implements the Scalability Protocols (REQ/REP, PUB/SUB, PUSH/PULL, SURVEYOR, BUS, PAIR) over multiple transports including TCP, TLS, WebSocket, IPC, inproc, UDP, and DTLS. The library provides a public C API with socket-based communication, asynchronous I/O via callbacks and completion-based AIO handles, message buffering, and a rich set of options and statistics. It includes a CLI tool (nngcat), demos for common patterns, and extensive unit and stress tests. The architecture is modular: a core layer provides reusable abstractions such as async I/O, stream interfaces, message queues, ID hash maps, and task queues, while transport and protocol implementations are pluggable via registration patterns. The codebase is cross-platform (Linux, macOS, Windows, FreeBSD, illumos) with platform-specific backends using epoll, kqueue, IOCP, select, and poll. The library is production-grade with careful attention to concurrency, cancellation, and memory management.
The LLM identified 2 files worth highlighting for reuse:
A standalone, clean implementation of base64 encoding/decoding used for WebSocket handshake. The code has no internal dependencies beyond its own header and standard C library. It can be extracted and reused in any C project requiring base64 encoding, demonstrating non-obvious bit manipulation skills for efficient encoding.
A self-contained SHA-1 implementation used for WebSocket key validation. Isolated from the rest of the codebase with its own header, it provides standard SHA-1 functionality with clear, compact code. Suitable for reuse in any project needing a lightweight SHA-1 hash without external dependencies.