Skip to content
FILWYZPublic

About

C++11 Reactor-style TCP networking library inspired by muduo, with epoll, eventfd, thread pool, CI, and docs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Mymoduo

CI C++ Platform License: MIT

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.

Highlights

  • Linux epoll based I/O multiplexing (edge-triggered reads, level-triggered writes).
  • One loop per thread Reactor model.
  • eventfd wakeup 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::set timer queue, exposed as EventLoop::runAfter/runEvery/runAt/cancel.
  • std::packaged_task + std::future async thread pool.
  • Fixed-size-block memory pool with a thread_local per-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.

Requirements

The full networking library uses Linux-specific APIs:

  • epoll
  • eventfd
  • accept4
  • SOCK_NONBLOCK
  • SOCK_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.

Quick Start

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-failure

On Linux, run the RPC server:

./build/mymoduo_rpc_server

Then call it from another terminal with the bundled client:

./build/mymoduo_rpc_client 127.0.0.1 8080

Expected 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 8080

Architecture

TcpServer
  |-- 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

Design Notes

  • The main loop owns listening socket registration and connection bookkeeping.
  • Worker loops own established connection I/O.
  • Cross-thread operations are routed through EventLoop::runInLoop and EventLoop::queueInLoop.
  • TcpConnection::send captures shared_from_this() for cross-thread sends so queued writes do not outlive the connection object.
  • Buffer::readFd uses scatter/gather I/O to reduce reallocations for bursts.

Current Limits

  • 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.

Roadmap

  • 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.

About

C++11 Reactor-style TCP networking library inspired by muduo, with epoll, eventfd, thread pool, CI, and docs.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages