Skip to content

net: Windows writes through IOCP, broadcast receivers per listener (net engine N1 follow-ups) - #1394

Merged
transfix merged 1 commit into
masterfrom
feat/net-engine-n1-followups
Nov 22, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/net-engine-n1-followups

Conversation

@transfix

@transfix transfix commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Two follow-ups to the connection engine's C++ core, N1 (#1392). See docs/roadmap/ARIADNE_NET_ENGINE.md.

Rebased onto master after #1392 merged (squash 35f5575): one commit, three files.

1. Windows: writes through IOCP. Reads needed no change.

Reads. #1392 listed a Windows read path as a follow-up. The reason given was that Asio implements async_wait with a select() reactor thread on Windows. That is true for wait_write but not for wait_read. In Asio 1.32 (detail/win_iocp_socket_service_base.hpp, async_wait), wait_read on a stream socket calls start_null_buffers_receive_op. That function issues a zero-byte overlapped WSARecv, which is the usual way to wait for input on IOCP. So N1's reads already go through IOCP, and an idle connection still holds no read buffer.

An async_read_some into a buffer per connection would give up that property and gain nothing, so reads are unchanged. A comment at start_read and the file's header now say why.

Writes. wait_write (and wait_error) do use the select() reactor (start_reactor_op(impl, select_reactor::write_op, ...)). So on Windows, a write that finds the socket full now sends the rest as an overlapped async_write_some of the gathered buffers:

  • The first attempt is still a non-blocking write_some, so a socket with room costs no completion.
  • Asio copies the buffer list into the operation. The connection keeps the payloads the buffers point into (in_flight) until the handler runs, because a close clears the output queue before that.
  • The handler does what the readiness wait's handler did: wrote(n), then write_now(). Closing, flushing closes, lingering and want_writable behave as before. linger() still runs only once no write is in flight.

-DCVC_NET_ASYNC_WRITES=1 takes the same path on Linux and macOS, so it can be tested off Windows (see Tests).

Fan-out default. The benchmark's Windows default N goes from 1000 to 6000, the same as elsewhere. On this PR's first CI run (before the rebase), recipe / windows-2022 / Release ran it at 6000 and passed in 8.8 s under a parallel ctest. All 24 NetEngine cases passed there.

2. Broadcast receivers per listener

worker::apply's broadcast walk now bumps conn->lst.broadcast_receivers for each receiver, so each listener's block counts the receivers it gave. broadcasts stays the engine's only: one broadcast's receivers can come from several listeners. The header now says so (a listener's block reads 0).

New test: NetEngine.EachListenerCountsItsOwnBroadcastReceivers. One group has two connections from listener "hub" and one from "admin". It sends two broadcasts, one of them excluding a hub connection. Expected per listener:

  • broadcast_receivers: hub 3, admin 2;
  • messages_out: 3 and 2;
  • broadcasts: 0 on each listener, 2 on the engine.

Tests (prettyhatemachine, gcc 13)

  • Release CMake build, ctest -R NetEngine: 24/24 (N1's 23 plus the new one).
  • The overlapped-write path forced on, on Linux (-DCVC_NET_ASYNC_WRITES=1, -O2 standalone): 24/24. Under gdb, its handler ran in the backpressure and close tests. The fan-out run at 6000 receivers measured 18.2 µs per receiver, against 17.6 µs on net: the connection engine's C++ core (ARIADNE_NET_ENGINE N1) #1392.
  • gcc -fsanitize=thread standalone, three runs each of the default build and the forced-on build: 24/24 every time, no reports. These runs used setarch -R, because this kernel's ASLR entropy makes TSan abort at startup otherwise.
  • clang-format 18 clean on the three files.

Windows itself is untested locally; the Windows CI jobs are the check. Both macOS failures on the first CI run were the fan-out's "Too many open files" at connection 5114. That came from a pre-rebase base: #1392 fixed it later with a macOS descriptor ceiling, and the rebase brings that fix in.

Do not merge without Joe's OK.

…et engine N1 follow-ups)

Windows writes. A write that finds the socket full waited for room with
async_wait(wait_write), which Asio implements on Windows with a select()
thread beside IOCP. There, the rest of the output now goes as an overlapped
async_write_some of the gathered buffers; the connection keeps their payloads
until the handler runs, since a close clears the queue first. The first write
is still a non-blocking write_some. -DCVC_NET_ASYNC_WRITES=1 takes the same path
on other systems, to test it.

Windows reads need no change: Asio's async_wait(wait_read) on a stream socket is
a zero-byte overlapped WSARecv, so it already goes through IOCP and an idle
connection still holds no read buffer. The fan-out benchmark's Windows default
goes from 1000 receivers to 6000, the same as elsewhere.

Counters. Each listener's block now counts broadcast_receivers: the receivers a
broadcast reached through that listener's connections. broadcasts stays the
engine's only, as the header now says. New test:
NetEngine.EachListenerCountsItsOwnBroadcastReceivers.
@transfix
transfix force-pushed the feat/net-engine-n1-followups branch from a5659ae to 3e6327a Compare November 21, 2026 11:07
@transfix
transfix merged commit 272c2bb into master Nov 22, 2026
31 checks passed
@transfix
transfix deleted the feat/net-engine-n1-followups branch November 22, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant