A high-performance, event-driven C++ networking library for Linux applications
Hohnor is a modern C++11 networking framework built around the Reactor pattern, providing asynchronous I/O, TCP/UDP networking, and comprehensive utilities for building scalable Linux applications. Inspired by industry-proven designs, it offers a clean, efficient API for developing everything from simple network services to high-performance servers.
- Event-driven architecture with epoll-based I/O multiplexing
- Zero-copy buffer management for efficient data handling
- TCP_NODELAY and SO_REUSEPORT optimizations for maximum throughput
- Connection pooling and keep-alive support
- Benchmarked performance: 50K+ requests/sec, 10K+ concurrent connections
- EventLoop core - Single-threaded event dispatcher with multi-threading support
- Timer management - Precise timing with microsecond resolution
- Signal handling - Graceful shutdown and custom signal processing
- Keyboard input - Interactive terminal applications with non-canonical mode
- ThreadPool with bounded blocking queues for optimal resource usage
- Thread-safe utilities - Mutex, Condition, CountDownLatch
- Lock-free programming - Atomic operations and smart pointer management
- Cross-thread communication - Safe callback queuing between threads
- Asynchronous logging - Non-blocking, high-performance log output
- Multiple log levels - TRACE, DEBUG, INFO, WARN, ERROR, FATAL
- Thread-safe - Concurrent logging from multiple threads
- Flexible output - File, stdout, or custom destinations
- Assertion macros - HCHECK family for runtime validation
- TCPAcceptor/TCPConnector - Server and client connection management
- TCPConnection - High-level connection abstraction with callbacks
- UDPSocket - Datagram communication support
- Buffer management - Efficient read/write buffers with automatic growth
- Flow control - Backpressure handling and high water mark callbacks
For a comprehensive understanding of Hohnor's architecture, design patterns, and implementation details, we encourage you to explore our detailed Design Specifications. This document covers:
- Complete architecture breakdown with module dependencies
- Core design patterns (Reactor, RAII, Observer, Producer-Consumer)
- Detailed component design and lifecycle management
- Performance considerations and thread safety guarantees
- Real-world use cases and production examples
Hohnor Framework
โโโ ๐ฏ Core (EventLoop, IOHandler, Timer, Signal)
โโโ ๐ Network (TCP/UDP, Sockets, Connections)
โโโ ๐งต Threading (ThreadPool, Mutex, Condition)
โโโ ๐ Logging (AsyncLogging, LogStream, Macros)
โโโ ๐ File (FileUtils, LogFile)
โโโ โฐ Time (Timestamp, Date)
โโโ ๐ง Process (ProcessInfo, Utilities)
โโโ ๐พ I/O (Epoll, FdUtils, Signal Wrappers)
- Linux (epoll-based, Unix-only)
- CMake 3.1+
- C++11 compatible compiler (GCC 4.8+, Clang 3.3+)
- pthread library
git clone <repository-url>
cd Hohnor
mkdir build && cd build
cmake ..
make -j$(nproc)cmake_minimum_required(VERSION 3.14)
project(MyProject)
include(FetchContent)
FetchContent_Declare(
Hohnor
GIT_REPOSITORY https://github.com/zpeng11/Hohnor.git
GIT_TAG main # or specific version tag
)
FetchContent_MakeAvailable(Hohnor)
# Your executable
add_executable(my_app main.cpp)
target_link_libraries(my_app PRIVATE Hohnor)#include "hohnor/core/EventLoop.h"
#include "hohnor/net/TCPAcceptor.h"
#include "hohnor/net/InetAddress.h"
using namespace Hohnor;
int main() {
auto loop = EventLoop::create();
auto acceptor = TCPAcceptor::create(loop);
acceptor->bindAddress(8080);
acceptor->setAcceptCallback([](TCPConnectionPtr conn) {
conn->setReadCompleteCallback([](TCPConnectionPtr conn) {
// Echo back received data
Buffer& readBuffer = conn->getReadBuffer();
std::string data = readBuffer.retrieveAllAsString();
conn->write(data);
conn->readRaw(); // Continue reading
});
conn->readRaw(); // Start reading
});
acceptor->listen();
loop->loop(); // Start event loop
return 0;
}- Snake Game - Terminal-based game with real-time controls
- Keyboard Handler - Interactive command-line applications
- iperf3-compatible - TCP throughput testing (50K+ req/s)
- wrk-compatible HTTP - HTTP server benchmarking (200K+ req/s)
auto loop = EventLoop::create();
loop->setThreadPools(4); // Background thread pool
// Timer events
loop->addTimer(callback, Timestamp::now(), 1.0); // 1-second interval
// Signal handling
loop->handleSignal(SIGINT, SignalAction::CUSTOM, [&]() {
loop->endLoop(); // Graceful shutdown
});
// I/O events
auto handler = loop->handleIO(sockfd);
handler->setReadCallback(readCallback);
loop->loop(); // Start processing events// Server side
auto acceptor = TCPAcceptor::create(loop);
acceptor->bindAddress(8080);
acceptor->setAcceptCallback([](TCPConnectionPtr conn) {
conn->setHighWaterMarkCallback(64*1024, [](TCPConnectionPtr conn) {
// Handle backpressure
});
conn->setReadCompleteCallback([](TCPConnectionPtr conn) {
// Process incoming data
Buffer& buf = conn->getReadBuffer();
// ... handle data ...
});
conn->readRaw(); // Start reading
});
// Client side
auto connector = TCPConnector::create(loop, InetAddress("127.0.0.1", 8080));
connector->setNewConnectionCallback([](TCPConnectionPtr conn) {
conn->write("Hello, Server!");
});
connector->start();#include "hohnor/log/Logging.h"
// Configure async logging
auto asyncLog = std::make_shared<AsyncLogFile>("app.log");
Logger::setAsyncLog(asyncLog);
Logger::setGlobalLogLevel(Logger::INFO);
// Use logging macros
LOG_INFO << "Server started on port " << port;
LOG_WARN << "High memory usage: " << usage << "MB";
LOG_ERROR << "Connection failed: " << error;
// Assertions
HCHECK(ptr != nullptr) << "Pointer must not be null";
HCHECK_EQ(status, 0) << "Operation must succeed";- High-performance TCP/UDP servers (web servers, game servers, proxies)
- Real-time applications (chat systems, live data feeds)
- Network utilities (load balancers, monitoring tools)
- Interactive CLI applications (games, system tools)
- Microservices with high concurrency requirements
- HTTP/HTTPS servers handling 10K+ concurrent connections
- Real-time messaging systems with sub-millisecond latency
- Network proxies and load balancers
- Game servers with tick-based simulation
- System monitoring and logging aggregators
| Metric | Performance |
|---|---|
| Concurrent Connections | 10,000+ simultaneous |
| Request Throughput | 50,000+ req/sec (TCP) |
| Latency | Sub-millisecond for simple operations |
| Memory Usage | ~2KB per connection |
| CPU Efficiency | Single-threaded event loop + worker threads |
Hohnor includes comprehensive unit tests for all components:
# Build with tests enabled (default)
cmake -DENABLE_UNIT_TEST=ON ..
make
ctest # Run all testsTest coverage includes:
- Core event loop functionality
- Network connection management
- Threading primitives
- Logging system
- Time utilities
- File operations
- Design Specifications - Architecture and design decisions
- API Reference - Complete header documentation
- Examples - Working code samples
- Benchmarks - Performance testing tools
We welcome contributions! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Hohnor draws inspiration from:
- muduo - Chen Shuo's excellent C++ network library
- libevent - Event-driven programming patterns
- Reactor pattern - Scalable I/O event handling
- UNIX Network Programming - Stevens' foundational work
Ready to build high-performance network applications? Start with our TCP Echo example or dive into the performance benchmarks to see Hohnor in action!