Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.
  • 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.
  • Echo server example.
  • CMake, Makefile, CI, and focused unit tests for the portable buffer layer.

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 echo server:

./build/mymoduo_echo_server

Then connect from another terminal:

nc 127.0.0.1 8080

The legacy Makefile path is also kept:

make
./bin/muduo_echo_server

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 timer queue, 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 timer support with timerfd.
  • Add graceful shutdown tests and integration tests for the echo server.
  • Add a small benchmark for concurrent 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