$ show an-tao/trantor
Trantor is a high-performance, non-blocking I/O TCP network library written in C++14, inspired by the Muduo library. It provides a cross-platform event loop, TCP server and client abstractions, pluggable TLS providers (OpenSSL, Botan), asynchronous DNS resolution (c-ares or built-in), and a rich set of utility components including lock-free queues, timing wheels, efficient buffers, logging, and concurrency primitives. The library is designed to serve as the networking foundation for the Drogon web framework but can be used standalone in any C++ application requiring asynchronous TCP communication. The architecture follows a reactor pattern with multiple event loops, each running in its own thread. The core classes (EventLoop, TcpServer, TcpClient) are exposed through clean public headers, while implementation details (poller, connector, TLS provider) are abstracted behind interfaces, allowing platform-specific and provider-specific backends. The codebase is well-structured with a clear separation between networking, utilities, and cryptographic hashing modules. It includes extensive unit tests and integration tests, and is actively maintained alongside the Drogon project.
The LLM identified 4 files worth highlighting for reuse:
A header-only, multi-producer single-consumer (MPSC) lock-free queue implemented using std::atomic and tagged pointers. It provides push and pop operations without locks, making it suitable for high-throughput inter-thread communication in event loops. The implementation is self-contained and can be extracted for use in other C++ projects requiring a lock-free queue.
An efficient timer-wheel data structure for managing timeouts (e.g., idle connections). It uses a circular buffer of buckets and a cursor to schedule and fire expiry callbacks. The implementation is well-encapsulated, requiring only standard containers and a callback type. It can be reused in any C++ project needing O(1) timeout scheduling and cancellation.
A lightweight, self-contained date and time utility class providing construction from time_t, conversion to std::string (e.g., ISO 8601), and arithmetic operations. It includes platform-independent implementation with no external dependencies beyond the C++ standard library. Suitable for logging, timestamps, and any project needing date/time formatting.
An efficient, dynamically-growing buffer class optimized for network I/O. It provides methods for reading, writing, appending, and swapping data, with built-in zero-copy when possible. The implementation avoids unnecessary allocations and is designed for use in event-loop-based networking. It is a standalone header that can be extracted for other asynchronous I/O libraries.