Skip to content

Read ahead on IOCP with one WSARecv per socket into a pool buffer for ReadBuffer() - #211

Draft
resetius wants to merge 1 commit into
read-buffer-uringfrom
read-buffer-iocp
Draft

resetius wants to merge 1 commit into
read-buffer-uringfrom
read-buffer-iocp

Conversation

@resetius

@resetius resetius commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Depends on #210 (stacked: the diff of this PR is the third commit only).

TIOCp reads ahead for ReadBuffer() on sockets:

  • The first wait posts one WSARecv into a buffer acquired from the pool. Each completed one is committed as a lease and the next one is posted, up to PerSocketLimit queued leases. The read-ahead operation is an ordinary TOperation (its OVERLAPPED) inside a per-socket state held by unique_ptr, so it never moves.
  • A completion of such an operation goes to the read-ahead state instead of resuming a coroutine, both in Poll() and in the wait of Cancel(op).
  • A coroutine destroyed while waiting only drops its waiter.
  • Close: the waiter gets WSA_OPERATION_ABORTED, as ReadSome() does today. The state of a WSARecv in flight waits in a closing list until its packet comes. ~TIOCp cancels the WSARecvs in flight (CancelIoEx) and waits for their packets before the memory goes away.
  • All buffers leased: ReadBuffer() throws std::errc::no_buffer_space, as on the readiness pollers (TUring waits instead, because its kernel picks from the ring).
  • ReadSome() after ReadBuffer() takes from the same leases (the adapter of Read ahead on TUring with multishot reads into a buffer ring for ReadBuffer() #210).
  • File handles keep the one-shot read of Add ReadBuffer(): reads into buffers of the poller, on every backend #209 (BufferedFiles = false), because WSARecv is for sockets only.

Tests on Windows 10 (MSYS2 MINGW64, GCC 16.2, Debug), head 4b8e203:

  • ctest 4/4.
  • test_read_buffer_*: 28/28 (TSelect, TPoll, TEPoll, TIOCp).
  • The 7 TIOCp ones 10 times in a row: 10/10.
  • Stacked PRs get no CI here, because the workflow runs for PRs into master only.

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