C++26 brings senders and receivers (std::execution). stdnet is a header-only experiment in
what a standard networking library built on that model could look like: sockets, a TAPS
connection layer and TLS 1.3, all as senders you can compose or co_await.
Version 0.4 · C++23 · Linux, macOS, Windows, ESP32, RP2040 · Apache 2.0 with LLVM exception
| Sender/receiver everywhere | Every asynchronous operation is a std::execution sender, usable with sender algorithms or co_await-ed in std::execution::task. |
| Two layers | A socket layer shaped after P2762 (async_accept, async_receive, async_write, …) and a TAPS connection layer after P3185/P3482 (preconnection, initiate, listen, connection). |
| No data lost in the error channel | Byte counts are values, end of stream is set_value(0), and | as_expected turns error_codes into std::expected values. |
| Secure by default | The TAPS layer requires an explicit opt-out for cleartext; security_parameters{} means TLS 1.3. |
| TLS 1.3, four engines | A dependency-free built-in engine (client and server, reviewed for constant time), or OpenSSL, mbedTLS and Schannel. |
| Fast | No heap allocation and no epoll_ctl per operation; server CPU per message on par with raw sockets and Asio. |
| Happy Eyeballs | initiate races the resolved addresses (RFC 8305). |
| Named module | import stdnet;, with feature-test macros in <stdnet/version.hpp>. |
- Examples
- Getting started
- TLS
- Performance
- Configuration
- Status and platforms
- Documentation
- Development and releases
An echo server with the socket layer and coroutines:
#include <network>
namespace net = stdnet; // std::net in the standard
namespace ex = stdnet::ex; // std::execution
using net::ip::tcp;
net::task<void> serve(tcp::socket s) { // net::task: a std::execution::task bound to the io_context
char buf[4096];
while (std::size_t n = co_await net::async_receive(s, net::buffer(buf))) // 0 = end of stream
co_await net::async_write(s, net::buffer(buf, n));
}
net::task<void> accept_loop(tcp::acceptor& acc, ex::counting_scope& scope,
net::io_context::scheduler_type sch) {
for (;;) {
tcp::socket s = co_await net::async_accept(acc);
// log_errors: see examples/http_hello.cpp (spawn only takes senders that cannot fail)
ex::spawn(ex::starts_on(sch, log_errors(serve(std::move(s)))), scope.get_token());
}
}With the TAPS layer, the application states what it needs and the library picks the transport:
net::preconnection pc(net::remote_endpoint().with_hostname("example.com").with_port(80),
net::transport_properties::reliable_stream(),
net::security_parameters::disabled()); // cleartext must be explicit
net::connection conn = co_await net::initiate(sch, std::move(pc));
co_await net::async_send(conn, net::buffer(request));A TLS server states the identity it presents; the listener performs the handshakes:
auto id = net::tls::credentials::from_pem(chain_pem, key_pem);
net::listener l = net::listen(ctx, net::preconnection(net::local_endpoint().with_port(8443),
net::transport_properties::reliable_stream(),
net::security_parameters{}.local_identity(id).alpn({"http/1.1"})));
net::connection c = co_await net::async_accept(l); // TLS 1.3 handshake doneA TLS client states how it authenticates the server (here, by pinning its certificate):
net::preconnection pc(net::remote_endpoint().with_hostname("device.local").with_port(8443),
net::transport_properties::reliable_stream(),
net::security_parameters{}.pinned_server_certificate({server_cert}));
net::connection conn = co_await net::initiate(sch, std::move(pc)); // server authenticatedComplete programs in examples/:
| Program | What it shows |
|---|---|
| http_hello.cpp | HTTP/1.1 server, one coroutine per connection |
| https_hello.cpp | The same over TLS, with the TAPS layer and with tls::stream |
| taps_get.cpp | HTTPS or HTTP client over the TAPS API |
| echo_senders.cpp | Sender algorithms only, no coroutine |
Requirements: a C++23 compiler (GCC 13+, Clang 18+, MSVC 17.10+) and CMake 3.25+.
cmake -S . -B build -G Ninja
cmake --build build
ctest --test-dir build --output-on-failureConsume stdnet with add_subdirectory or FetchContent and link stdnet::stdnet:
include(FetchContent)
FetchContent_Declare(stdnet GIT_REPOSITORY https://github.com/ambroise-leclerc/stdnet.git GIT_TAG v0.4)
FetchContent_MakeAvailable(stdnet)
target_link_libraries(app PRIVATE stdnet::stdnet)std::execution comes from the standard library when it provides senders
(__cpp_lib_senders); otherwise CMake fetches NVIDIA's stdexec
at a pinned commit.
cmake -S . -B build -G Ninja -DSTDNET_BUILD_MODULE=ON -DCMAKE_CXX_COMPILER=clang++-18builds the module stdnet (src/stdnet.cppm; CMake 3.28+, Ninja or Visual Studio). Link
stdnet::module and write import stdnet;; the examples are also built that way (*_module).
- Named modules export no macro (P2465R3): include
<stdnet/version.hpp>next to the import for the feature macros, and include<coroutine>(orimport std;) before defining a coroutine. - The module has the configuration of the build that produced it; compile definitions of a consumer do not reach it.
- Tested with Clang 18 and 21 (libstdc++). GCC 15 refuses the module: stdexec, included in the global module fragment, exposes TU-local entities.
security_parameters{} gives TLS 1.3 through the engine chosen with STDNET_TLS_ENGINE; the
other engines stay usable with tls::stream when their library is linked.
| Engine | Library | Server authentication (client) | Typical use |
|---|---|---|---|
builtin (default) |
none | pin and/or trust-verification sender | every profile, embedded targets, servers with their own identity |
openssl |
OpenSSL 3 | pin and/or sender, else Web PKI (system store or trust_anchors) |
hosted clients of the public Internet |
mbedtls |
mbedTLS 3.6.3 or later 3.6 | pin and/or sender, else Web PKI (trust_anchors) |
ESP32 (ESP-IDF), RP2040 (pico-sdk), hardware acceleration |
schannel |
Schannel (Windows) | pin and/or sender, else Web PKI (Windows' chain engine) | Windows clients (no server role): nothing to ship |
Available features (per-engine exceptions in docs/TLS.md):
- client and server, ALPN, SNI with several identities, renewal of a running listener;
- client certificates and mutual TLS, with an identity-challenge callback;
- session resumption and external PSK;
- the RFC 9622 restrictions (protocols, cipher suites, groups, signature algorithms);
- RSA, ECDSA and Ed25519 keys, PEM bundles, encrypted PKCS#8, hardware-held keys;
- RFC 8449
record_size_limit, with record and handshake buffers sized at build time for small targets.
The built-in engine is checked for constant time with Valgrind on x86-64 and under QEMU on Cortex-M0, M3, M4 and M33. It is tested against GnuTLS, BoringSSL, wolfSSL, rustls, NSS and Go, and run through tlsfuzzer and libFuzzer. No third party has audited it; the audit is prepared in docs/TLS-AUDIT.md.
- No allocation and no
epoll_ctlper operation, thanks to the reactor of #11 (persistent per-descriptor state, epoll registered once, writability armed only while a write is blocked). - Server CPU per small echo message at 16 connections: the same as raw
poll(2)sockets within noise (ratio 1.00, 95 % CI 0.88–1.12×) and as Asio. - epoll vs poll: at most 4 % more CPU with every connection active; 0.56× and 0.24× with 2 000 and 10 000 mostly idle connections.
stdnet::taskposts one completion per operation, like the sender API, and costs the same CPU (ratio 0.96–1.01, #12).- Timers start without allocation, faster than Asio (#13).
- Known gaps: HTTP p99 latency (1.5× Asio, not significant after correction for multiple tests) and compile time.
The black ticks of the figure are stdnet before the reactor rework. Two runs of the same binary differ by about ±5 % in CPU per operation; the counters (allocations, completions) are exact.
Since #14 the system calls are made outside the io_context's mutex. On a 12-core machine, with each server thread on its own physical core, stdnet scales like Asio and raw epoll up to 4 threads (about 2.0× with 2 threads, 2.7× with 4, 256 connections); the dashed line is stdnet before the change (0.75–0.91× of one thread's throughput). At 8 threads all three flatten or fall, and stdnet is the lowest with 16 connections; why is not established.
| Measurement | Command |
|---|---|
| Main figure (about 100 s) | python3 bench/run.py |
| epoll / poll paired study (7 min) | python3 bench/run.py --only backend |
| Thread scaling | python3 bench/run.py --only scaling --reps 5 --scaling-conns 256 16 |
| Main figure drawing | python3 bench/infographic.py <results> docs/infographic.png [<baseline> [<backend study>]] |
| Scaling figure drawing | python3 bench/scaling_figure.py <results> docs/scaling.png [<baseline>] |
Source data: bench/results/timer-queue/ (baseline bench/results/2026-10-12-figure/before-0ec17e8/)
and bench/results/2026-10-12-backend/. Method and statistics: docs/PERF.md.
The library is configured once per program, by CMake cache options written to the generated
header <stdnet/config_site.hpp> (like libc++'s __config_site), which every header and the
module include:
| Option | Default | Effect |
|---|---|---|
STDNET_BACKEND |
auto |
auto: epoll on Linux, poll on other POSIX systems, WSAPoll on Windows; poll: poll(2) everywhere on POSIX |
STDNET_INLINE_DEPTH |
0 |
Nested inline completions per thread (0 keeps every completion queued, SPEC D3; #15) |
STDNET_REACTOR_INTERVAL |
256 |
Completions run before the reactor is polled again (PERF) |
STDNET_ENABLE_STATS |
OFF |
Reactor counters in io_context::stats() (benchmarks) |
STDNET_USE_STDEXEC |
OFF |
Use stdexec even when the standard library has senders |
STDNET_TLS_ENGINE |
builtin |
Engine of the TAPS layer: builtin, openssl, mbedtls, schannel (Windows, client role) or none (security_parameters{} reports not_supported) |
STDNET_TLS_MAX_RECORD |
16384 |
Built-in engine: largest record, advertised with RFC 8449 record_size_limit |
STDNET_TLS_MAX_HANDSHAKE |
16384 |
Built-in engine: largest handshake message accepted |
cmake -S . -B build -DSTDNET_BACKEND=poll -DSTDNET_INLINE_DEPTH=8Mismatches fail to link. The settings name the namespace that holds every stdnet entity
(stdnet::inline cfg_epoll_i0_r256_s0_x1_t1_m16384_h16384, never named by user code), so two
translation units built with different settings cannot exchange stdnet types: the program fails
to link instead of silently violating the ODR (MSVC also reports LNK2038 through
#pragma detect_mismatch). Without CMake the header is absent and the defaults apply. The former
macros (-DSTDNET_INLINE_DEPTH=8, -DSTDNET_FORCE_POLL, -DSTDNET_ENABLE_STATS) still work in
header mode for compatibility, but have no effect on an imported module.
Feature detection. <stdnet/version.hpp> is the analogue of <version>: macros only, with
SD-6 date values (STDNET_LIB_SOCKETS, STDNET_LIB_TAPS, STDNET_LIB_AS_EXPECTED,
STDNET_LIB_TASK, STDNET_LIB_TLS), absent when the feature is. The same values are
inline constexpr long stdnet::lib_sockets, … (0 when absent), which also work after
import stdnet;. An absent feature keeps its declaration where possible and fails to compile
when used, so the interface does not change between configurations.
The CI builds and tests these configurations on every pull request:
| Platform | Toolchain | Backend / TLS engine |
|---|---|---|
| Linux | GCC 13, GCC 14, Clang 18 | epoll, poll, inline completions; builtin, OpenSSL, mbedTLS, none |
| Linux | GCC 16 -O3 -Wall -Wextra -Werror |
epoll; builtin |
| Linux | GCC 14 with AddressSanitizer and ThreadSanitizer | epoll, inline completions |
| Linux | Clang 18, named module | epoll |
| macOS 15 | Apple Clang | poll; builtin, OpenSSL |
| Windows Server 2025 | MSVC | WSAPoll; builtin, OpenSSL (vcpkg), Schannel |
| ESP32, ESP32-C3 | ESP-IDF, run under QEMU | mbedTLS |
| RP2040, RP2350 | pico-sdk, build only | mbedTLS |
| Cortex-M0, M3, M4, M33 | GCC, run under QEMU, footprint report | builtin |
The TLS interop workflow tests interoperability with GnuTLS, BoringSSL, wolfSSL, rustls, NSS and Go, and runs tlsfuzzer conformance.
Not done yet:
- measurements on real ESP32 and RP2040 boards (#54);
- an external audit of the built-in TLS engine (#55);
- TLS 0-RTT, and Web PKI in the built-in engine (by design, the job of the other engines);
- QUIC and the other extensions listed in SPEC §10.
| Document | Contents |
|---|---|
| docs/SPEC.md | The specification: design decisions, API, semantics |
| docs/TLS.md | TLS: engines, trust policy, identities, resumption, footprint, constant time, conformance |
| docs/TLS-AUDIT.md | Scope and material for the external audit |
| docs/PERF.md | Benchmarks against raw sockets and Asio: method, statistics, results |
| docs/RESEARCH.md | Survey of the papers the design is based on |
develop is the default branch and the integration branch for ongoing work. Create
feature and fix branches from develop, and target develop with their pull requests.
main is reserved for official releases. To prepare a release, set project(VERSION) in
CMakeLists.txt and the version in this README on develop, then open a pull request
from develop to main. Merging requires an up-to-date branch and all nine required CI checks
to pass, including platform builds, sanitizers, and the benchmark smoke test. These
requirements also apply to administrators; force pushes and branch deletion are disabled.
No additional reviewer approval is required.
After merging the release pull request, create the version tag (for example, v0.4) on the released commit in main and publish the corresponding
GitHub release. Merge main back into develop before continuing development so both branches
share the release history. Release fixes follow the same pull request and CI requirements.
Apache License v2.0 with LLVM Exceptions.

