Language: English | νκ΅μ΄
A modern C++20 asynchronous network library providing reusable transport primitives for distributed systems and messaging applications. Originally extracted from messaging_system for enhanced modularity and ecosystem-wide reusability.
Key Characteristics:
- ποΈ Modular Architecture: Coroutine-friendly async I/O with pluggable protocol stack
- β‘ High Performance: ASIO-based non-blocking operations with synthetic benchmarks showing ~769K msg/s for small payloads
- π‘οΈ Production Grade: Comprehensive sanitizer coverage (TSAN/ASAN/UBSAN clean), RAII Grade A, multi-platform CI/CD
- π Secure: TLS 1.2/1.3 support, certificate validation, modern cipher suites
- π Cross-Platform: Ubuntu, Windows, macOS with GCC, Clang, MSVC support
| Dependency | Version | Required | Description |
|---|---|---|---|
| C++20 Compiler | GCC 11+ / Clang 14+ / MSVC 2022+ / Apple Clang 14+ | Yes | C++20 features required |
| CMake | 3.20+ | Yes | Build system |
| ASIO | latest | Yes | Asynchronous I/O (standalone) |
| OpenSSL | 3.x (recommended) / 1.1.1 (minimum) | Yes | TLS/SSL support |
| common_system | latest | Yes | Common interfaces and Result |
| thread_system | latest | Yes | Thread pool and async operations |
| logger_system | latest | Yes | Logging infrastructure |
| container_system | latest | Yes | Data container operations |
OpenSSL Version Note: OpenSSL 1.1.1 reached End-of-Life on September 11, 2023. We strongly recommend upgrading to OpenSSL 3.x for continued security support. The build system will display a warning if OpenSSL 1.1.1 is detected.
network_system
βββ common_system (required)
βββ thread_system (required)
β βββ common_system
βββ logger_system (required)
β βββ common_system
βββ container_system (required)
βββ common_system
# Clone all dependencies
git clone https://github.com/kcenon/common_system.git
git clone https://github.com/kcenon/thread_system.git
git clone https://github.com/kcenon/logger_system.git
git clone https://github.com/kcenon/container_system.git
git clone https://github.com/kcenon/network_system.git
# Build network_system
cd network_system
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build buildUbuntu/Debian (Ubuntu 22.04+ provides OpenSSL 3.x by default):
sudo apt update
sudo apt install -y cmake ninja-build libasio-dev libssl-dev liblz4-dev zlib1g-devmacOS (OpenSSL 3.x via Homebrew):
brew install cmake ninja asio openssl@3 lz4 zlibWindows (vcpkg):
# vcpkg provides OpenSSL 3.x
vcpkg install openssl asio lz4 zlib --triplet x64-windowsWindows (MSYS2):
pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja \
mingw-w64-x86_64-asio mingw-w64-x86_64-opensslgit clone https://github.com/kcenon/network_system.git
cd network_system
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build -j#include <kcenon/network/core/messaging_server.h>
#include <iostream>
int main() {
auto server = std::make_shared<kcenon::network::core::messaging_server>("MyServer");
auto result = server->start_server(8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Failed to start: " << err.message
<< " (code: " << err.code << ")" << std::endl;
return -1;
}
std::cout << "Server running on port 8080..." << std::endl;
server->wait_for_stop();
return 0;
}Note: Legacy
network_system::namespace is still supported via<kcenon/network/compatibility.h>for backward compatibility.
#include <kcenon/network/core/messaging_client.h>
#include <iostream>
int main() {
auto client = std::make_shared<kcenon::network::core::messaging_client>("MyClient");
auto result = client->start_client("localhost", 8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Failed to connect: " << err.message
<< " (code: " << err.code << ")" << std::endl;
return -1;
}
// Send message (std::move avoids extra copies)
std::string message = "Hello, Network System!";
std::vector<uint8_t> data(message.begin(), message.end());
auto send_result = client->send_packet(std::move(data));
if (send_result.is_err()) {
const auto& err = send_result.error();
std::cerr << "Failed to send: " << err.message
<< " (code: " << err.code << ")" << std::endl;
}
client->wait_for_stop();
return 0;
}-
TCP: Asynchronous TCP server/client with lifecycle management
- Non-blocking I/O, automatic reconnection, health monitoring
- Multi-threaded message processing, session management
-
UDP: Connectionless UDP for real-time applications
- Low-latency datagram transmission, broadcast/multicast support
-
TLS/SSL: Secure communication (TLS 1.2/1.3)
- Modern cipher suites (AES-GCM, ChaCha20-Poly1305)
- Certificate validation, forward secrecy (ECDHE)
-
WebSocket: RFC 6455 compliant
- Text and binary message framing, ping/pong keepalive
- Fragmentation/reassembly, graceful connection lifecycle
-
HTTP/1.1: Server and client with advanced features
- Routing, cookies, multipart/form-data, chunked encoding
- Automatic compression (gzip/deflate)
-
QUIC: RFC 9000/9001/9002 compliant
- UDP-based multiplexed transport with TLS 1.3 encryption
- Stream multiplexing, 0-RTT connection resumption
- Loss detection and congestion control
- Connection migration support
-
gRPC: High-performance RPC framework (NEW)
- Official gRPC library wrapper with network_system integration
- Service registry with dynamic method registration
- All streaming modes (unary, server, client, bidirectional)
- Health checking and reflection support
- Result to gRPC Status conversion
π Detailed Protocol Documentation β π gRPC Guide β
- ASIO-Based: Non-blocking event loop with async operations
- C++20 Coroutines: Optional coroutine-based async helpers
- C++20 Concepts: Compile-time type validation with clear error messages
- Pipeline Architecture: Message transformation with compression/encryption hooks
- Move Semantics: Zero-copy friendly APIs (move-aware buffer handling)
- All server/client start helpers return
Result<void>; checkresult.is_err()before continuing and logresult.error().message. - For historical fixes (session cleanup, backpressure, TLS rollout), review
IMPROVEMENTS.mdto understand the safeguards already in place and how to react if regression symptoms reappear. - When building higher-level services, propagate
common::error_infoup the stack so monitoring and alerting pipelines can correlate failures across tiers.
Result Pattern (75-80% migrated):
auto result = server->start_server(8080);
if (result.is_err()) {
const auto& err = result.error();
std::cerr << "Error: " << err.message
<< " (code: " << err.code << ")\n";
return -1;
}Error Codes (-600 to -699):
- Connection (-600 to -619):
connection_failed,connection_refused,connection_timeout - Session (-620 to -639):
session_not_found,session_expired - Send/Receive (-640 to -659):
send_failed,receive_failed,message_too_large - Server (-660 to -679):
server_not_started,server_already_running,bind_failed
| Payload | Throughput | Latency (ns/op) | Scope |
|---|---|---|---|
| 64 bytes | ~769K msg/s | 1,300 | CPU-only (allocation + memcpy) |
| 256 bytes | ~305K msg/s | 3,270 | CPU-only (allocation + memcpy) |
| 1 KB | ~128K msg/s | 7,803 | CPU-only (allocation + memcpy) |
| 8 KB | ~21K msg/s | 48,000 | CPU-only (allocation + memcpy) |
Note: Synthetic benchmarks measure CPU-only operations without real network I/O. Real network throughput/latency measurements are pending.
# Build with benchmarks
cmake -B build -DCMAKE_BUILD_TYPE=Release -DNETWORK_BUILD_BENCHMARKS=ON
cmake --build build -j
# Run benchmarks
./build/benchmarks/network_benchmarks
# Run specific category
./build/benchmarks/network_benchmarks --benchmark_filter=MessageThroughputβ‘ Full Benchmarks & Load Testing β
Platform: Apple M1 @ 3.2GHz (when tested on Apple Silicon)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Network System Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Public API Layer β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β β messaging β β messaging β β messaging_ws β β
β β _server β β _client β β _server / _client β β
β β (TCP) β β (TCP) β β (WebSocket) β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β ββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β β secure_messaging β β secure_messaging β β
β β _server (TLS/SSL) β β _client (TLS/SSL) β β
β ββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β β messaging_quic β β messaging_quic β β
β β _server (QUIC) β β _client (QUIC) β β
β ββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Protocol Layer β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β β tcp_socket β β udp_socket β β websocket_socket β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββ β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ β
β β secure_tcp_socket β β websocket_protocol β β
β β (SSL stream wrapper) β β (frame/handshake/msg handle) β β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β protocols/quic/ (RFC 9000/9001/9002) β β
β β connection, stream, packet, frame, crypto, varint β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Session Management Layer β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββ β
β β messaging β β secure β β ws_session_manager β β
β β _session β β _session β β (WebSocket mgmt) β β
β β (TCP) β β (TLS/SSL) β β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β quic_session (QUIC session management) ββ
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Core Network Engine (ASIO-based) β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β io_context β β async β β Result<T> β β
β β β β operations β β pattern β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Design Patterns: Factory, Observer, Strategy, RAII, Template Metaprogramming
ποΈ Detailed Architecture Guide β
This system integrates seamlessly with:
- messaging_system: High-performance message routing and delivery
- container_system: Type-safe data serialization (MessagePack, FlatBuffers)
- thread_system: Thread pool management for concurrent operations
- logger_system: Comprehensive network diagnostics and logging
- database_system: Network-based database operations and clustering
#include <kcenon/network/core/messaging_server.h>
#include <kcenon/network/integration/thread_system_adapter.h>
using namespace kcenon::network;
int main() {
// Bind thread_system for unified thread management
#if KCENON_WITH_THREAD_SYSTEM
integration::bind_thread_system_pool_into_manager("network_pool");
#endif
// Create and start server
auto server = std::make_shared<core::messaging_server>("IntegratedServer");
auto result = server->start_server(8080);
if (result.is_err()) {
std::cerr << "Failed: " << result.error().message << std::endl;
return -1;
}
// Get thread pool metrics
auto& manager = integration::thread_integration_manager::instance();
auto metrics = manager.get_metrics();
std::cout << "Workers: " << metrics.worker_threads << std::endl;
server->wait_for_stop();
return 0;
}Bidirectional adapters enable interoperability between network_system's thread pool and common_system's executor:
#include <kcenon/network/integration/thread_pool_adapters.h>
using namespace kcenon::network::integration;
// Use network_system pool where IExecutor is expected
auto network_pool = thread_integration_manager::instance().get_thread_pool();
auto executor = std::make_shared<network_to_common_thread_adapter>(network_pool);
// Pass executor to messaging_system, database_system, etc.
// Use external IExecutor in network_system
auto external_executor = container.resolve<common::interfaces::IExecutor>();
auto adapted = std::make_shared<common_to_network_thread_adapter>(external_executor);
thread_integration_manager::instance().set_thread_pool(adapted);π Full Integration Guide β
- π Features Guide - Comprehensive feature descriptions
- ποΈ Architecture - System design and patterns
- π API Reference - Complete API documentation
- π§ Build Guide - Detailed build instructions
- π Migration Guide - Migrating from messaging_system
- β‘ Performance & Benchmarks - Performance metrics and testing
- π Production Quality - CI/CD, security, quality assurance
- π Project Structure - Directory organization and modules
- π§© C++20 Concepts - Compile-time type validation
- π TLS Setup Guide - TLS/SSL configuration
- π Troubleshooting - Common issues and solutions
- π§ͺ Load Test Guide - Load testing procedures
- π Design Decisions - Architectural patterns and rationale
- π Integration Guide - Ecosystem integration patterns
- π Operations Guide - Deployment and operations
- π Changelog - Version history and updates
| Platform | Compiler | Architecture | Support Level |
|---|---|---|---|
| Ubuntu 22.04+ | GCC 11+ | x86_64, ARM64 | β Full Support |
| Ubuntu 22.04+ | Clang 14+ | x86_64, ARM64 | β Full Support |
| Windows 2022+ | MSVC 2022+ | x86_64 | β Full Support |
| Windows 2022+ | MinGW64 | x86_64 | β Full Support |
| macOS 12+ | Apple Clang 14+ | x86_64, ARM64 | β Full Support |
Comprehensive Multi-Platform Testing:
- β Sanitizer Coverage: ThreadSanitizer, AddressSanitizer, UBSanitizer
- β Multi-Platform: Ubuntu (GCC/Clang), Windows (MSVC/MinGW), macOS
- β Performance Gates: Automated regression detection
- β Static Analysis: clang-tidy, cppcheck with modernize checks
- β Code Coverage: ~80% with Codecov integration
TLS/SSL Implementation:
- TLS 1.2/1.3 protocol support
- Modern cipher suites (AES-GCM, ChaCha20-Poly1305)
- Forward secrecy (ECDHE), certificate validation
- Hostname verification, optional certificate pinning
Additional Security:
- Input validation and buffer overflow protection
- WebSocket origin validation and frame masking
- HTTP request size limits and path traversal protection
- Cookie security (HttpOnly, Secure, SameSite)
Thread Safety:
- β Comprehensive synchronization (mutex, atomic, shared_mutex)
- β ThreadSanitizer clean (zero data races)
- β Concurrent session handling tested
Memory Safety (RAII Grade A):
- β
100% smart pointer usage (
std::shared_ptr,std::unique_ptr) - β Zero manual memory management
- β AddressSanitizer clean (zero leaks, zero buffer overflows)
- β Automatic resource cleanup via RAII
π‘οΈ Complete Production Quality Guide β
- C++20 compatible compiler (GCC 11+, Clang 14+, MSVC 2022+, Apple Clang 14+)
- CMake 3.20+
- ASIO or Boost.ASIO 1.28+
- OpenSSL 1.1.1+ (for TLS/SSL and WebSocket)
- container_system (advanced serialization)
- thread_system (thread pool integration)
- logger_system (structured logging)
# Basic build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j
# With benchmarks
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DNETWORK_BUILD_BENCHMARKS=ON
# With tests
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTS=ON
# With optional integrations
cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DBUILD_WITH_THREAD_SYSTEM=ON \
-DBUILD_WITH_LOGGER_SYSTEM=ON \
-DBUILD_WITH_CONTAINER_SYSTEM=ON
# Build and run tests
cmake --build build -j
cd build && ctest --output-on-failureComplete examples are available in the samples/ directory:
- basic_usage.cpp - Basic TCP client/server
- simple_tcp_server.cpp - TCP server with session management
- simple_tcp_client.cpp - TCP client with reconnection
- simple_http_server.cpp - HTTP server with routing
- simple_http_client.cpp - HTTP client with various request types
- websocket_example.cpp - WebSocket server and client
- quic_server_example.cpp - QUIC server with multi-stream support
- quic_client_example.cpp - QUIC client with stream multiplexing
- grpc_service_example.cpp - gRPC service registration and management
Build and run examples:
cmake --build build --target samples
./build/bin/simple_tcp_server
./build/bin/simple_tcp_client- β QUIC Protocol Support: RFC 9000/9001/9002 compliant implementation
- β gRPC Integration: Official gRPC library wrapper with full streaming support
- π§ Real network load test validation and baseline establishment
- π§ Complete Result migration (currently 75-80%)
- π§ Documentation examples update
- π§ Connection Pooling: Enterprise-grade connection management
- π§ Zero-Copy Pipelines: Eliminate unnecessary buffer copies
- π§ HTTP/2 Client: Modern HTTP/2 protocol support
See IMPROVEMENTS.md for detailed roadmap and tracking.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow the Coding Style Rules
- Commit changes with conventional commits
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Before submitting:
- Ensure all tests pass (
ctest) - Run sanitizers (TSAN, ASAN, UBSAN)
- Check code formatting (
clang-format) - Update documentation as needed
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
| Contact Type | Details |
|---|---|
| Project Owner | kcenon (kcenon@naver.com) |
| Repository | https://github.com/kcenon/network_system |
| Issues & Bug Reports | https://github.com/kcenon/network_system/issues |
| Discussions & Questions | https://github.com/kcenon/network_system/discussions |
- ASIO Library Team: Foundation of asynchronous network programming
- C++ Standards Committee: C++20 features enabling modern networking
- Thread System: Seamless thread pool integration
- Logger System: Comprehensive logging and debugging
- Container System: Advanced serialization support
- Database System: Network-database integration patterns
- Monitoring System: Performance metrics and observability
Made with β€οΈ by πβππ₯ π