Mymoduo is a small C++11 Reactor-style TCP networking library inspired by
muduo. It is a learning-oriented implementation of the core pieces behind a
multi-threaded event-driven server: EventLoop, Channel, Poller,
Acceptor, TcpConnection, TcpServer, and a round-robin event loop thread
pool.
This repository is positioned as a systems programming project rather than a production networking framework. The goal is to make the event-driven design, thread ownership model, and connection lifecycle explicit enough to discuss in C++ backend and AI infrastructure interviews.
- Linux
epollbased I/O multiplexing (edge-triggered reads, level-triggered writes). - One loop per thread Reactor model.
eventfdwakeup path for cross-thread task dispatch.- Non-blocking accept and connection file descriptors.
- Input/output buffering with
readv. - Round-robin assignment from the main accept loop to worker subloops.
timerfd+std::settimer queue, exposed asEventLoop::runAfter/runEvery/runAt/cancel.std::packaged_task+std::futureasync thread pool.- Fixed-size-block memory pool with a
thread_localper-thread cache. - Idle-connection timeout detection with
forceClose. - A lightweight RPC server example (
Calculator.Add,Echo.Repeat) on top of the core. - CMake, Makefile, CI, and focused unit tests.
The full networking library uses Linux-specific APIs:
epolleventfdaccept4SOCK_NONBLOCKSOCK_CLOEXEC
Build the complete server on Linux. On macOS, the CMake project still builds
and tests the portable Buffer component, but skips the Linux-only Reactor
targets.
git clone https://github.com/FILWYZ/Mymoduo.git
cd Mymoduo
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
ctest --test-dir build --output-on-failureOn Linux, run the RPC server:
./build/mymoduo_rpc_serverThen call it from another terminal with the bundled client:
./build/mymoduo_rpc_client 127.0.0.1 8080Expected client output:
Calculator.Add(3 5) => 8
Echo.Repeat(hello reactor rpc) => hello reactor rpc
Calculator.Sub failed: method not found: Calculator.Sub
The legacy Makefile path is also kept:
make
./bin/rpc_server
./bin/rpc_client 127.0.0.1 8080TcpServer
|-- Acceptor: accepts new sockets in the main EventLoop
|-- EventLoopThreadPool: owns worker loops
|-- TcpConnection map: tracks live connections by name
EventLoop
|-- Poller / EPollPoller: waits for active file descriptors
|-- Channel: binds fd events to callbacks
|-- eventfd: wakes the loop when other threads queue work
TcpConnection
|-- Channel: handles read, write, close, and error events
|-- Buffer: stores input and output data
|-- callbacks: exposes connection and message events to user code
- The main loop owns listening socket registration and connection bookkeeping.
- Worker loops own established connection I/O.
- Cross-thread operations are routed through
EventLoop::runInLoopandEventLoop::queueInLoop. TcpConnection::sendcapturesshared_from_this()for cross-thread sends so queued writes do not outlive the connection object.Buffer::readFduses scatter/gather I/O to reduce reallocations for bursts.
- Linux-only network backend; no kqueue or IOCP implementation.
- No high-water-mark callback, TLS, or backpressure policy yet.
- Logging is intentionally minimal.
- This is a learning project and has not been production load-tested.
- Add graceful shutdown and integration tests.
- Add a small benchmark for concurrent RPC/echo throughput.
- Add structured logging and configurable log levels.
- Add documentation that maps this implementation against muduo's original abstractions.