Skip to the content.

< Previous: Performance Metrics | 🏠 Home


Architecture & Examples

cpp-udpnet is designed for high performance and low latency. It achieves this by decoupling the OS-level socket polling from the user-level data processing.

Threading Model

The library employs a producer-consumer architecture:

  1. Event Loop Thread (Producer): A single background thread continuously polls the UDP socket using native system calls (poll on POSIX, WSAPoll on Windows). When a datagram arrives, it is immediately read into a buffer.
  2. Worker Pool (Consumers): The datagram is then dispatched to a built-in thread pool provided by cpp-asyncworker.

Peer Affinity

To ensure correct ordering, cpp-udpnet guarantees Peer Affinity. This means that all datagrams received from a specific PeerAddress (IP + Port) are always executed serially by the same worker thread. This prevents race conditions in your application logic, while still allowing data from different peers to be processed concurrently.

Included Examples

The examples/ directory contains several complete, buildable programs demonstrating how to use cpp-udpnet in various scenarios:

To build the examples, simply configure CMake from the project root:

mkdir build && cd build
cmake ..
cmake --build .

< Previous: Performance Metrics 🏠 Home