feat(fast_io): IOCP socket I/O via WSARecv/WSASend (#1928)#3539
Merged
Conversation
f2c8caf to
ca19ab0
Compare
Adds an IOCP-backed async socket reader/writer that mirrors the io_uring socket surface and dispatches completions through the shared CompletionPump from #1897. Each WSARecv/WSASend issues an OVERLAPPED operation; synchronous completions and WSA_IO_PENDING paths both wait on a oneshot handler registered with the pump, so file I/O and socket I/O share a single drain thread. Mirrors upstream rsync's socket I/O semantics: - recv treats graceful peer close (WSAEDISCON, WSAESHUTDOWN, WSAENETRESET, WSAECONNRESET, WSAECONNABORTED) and STATUS_END_OF_FILE as Ok(0), matching safe_read breaking on n == 0 (target/interop/upstream-src/rsync-3.4.1/io.c:276). - send maps WSAESHUTDOWN/WSAECONNRESET/WSAECONNABORTED to BrokenPipe and returns short counts so the caller's loop re-issues, matching safe_write's partial-write retry (io.c:316-336). Files: - crates/fast_io/src/iocp/socket.rs (new): IocpSocketReader, IocpSocketWriter, SharedPump alias, six tests covering localhost TCP roundtrip, partial 64KB send accounting, peer-shutdown EOF, empty-buffer fast paths, and completion-key override. - crates/fast_io/src/iocp/mod.rs: pub mod socket; (single line) - crates/fast_io/src/iocp_stub.rs: matching stub module so the workspace cross-compiles on Linux and macOS, all methods returning io::ErrorKind::Unsupported. - crates/fast_io/Cargo.toml: add Win32_Networking_WinSock to the windows-sys feature list for WSARecv/WSASend bindings. Cross-platform compile preserved: the real implementation is gated behind cfg(all(target_os = "windows", feature = "iocp")) at the fast_io::iocp module level; non-Windows builds fall through to the stub.
ca19ab0 to
9cc8cec
Compare
oferchen
added a commit
that referenced
this pull request
May 5, 2026
* feat(fast_io): IOCP socket I/O via WSARecv/WSASend (#1928) Adds an IOCP-backed async socket reader/writer that mirrors the io_uring socket surface and dispatches completions through the shared CompletionPump from #1897. Each WSARecv/WSASend issues an OVERLAPPED operation; synchronous completions and WSA_IO_PENDING paths both wait on a oneshot handler registered with the pump, so file I/O and socket I/O share a single drain thread. Mirrors upstream rsync's socket I/O semantics: - recv treats graceful peer close (WSAEDISCON, WSAESHUTDOWN, WSAENETRESET, WSAECONNRESET, WSAECONNABORTED) and STATUS_END_OF_FILE as Ok(0), matching safe_read breaking on n == 0 (target/interop/upstream-src/rsync-3.4.1/io.c:276). - send maps WSAESHUTDOWN/WSAECONNRESET/WSAECONNABORTED to BrokenPipe and returns short counts so the caller's loop re-issues, matching safe_write's partial-write retry (io.c:316-336). Files: - crates/fast_io/src/iocp/socket.rs (new): IocpSocketReader, IocpSocketWriter, SharedPump alias, six tests covering localhost TCP roundtrip, partial 64KB send accounting, peer-shutdown EOF, empty-buffer fast paths, and completion-key override. - crates/fast_io/src/iocp/mod.rs: pub mod socket; (single line) - crates/fast_io/src/iocp_stub.rs: matching stub module so the workspace cross-compiles on Linux and macOS, all methods returning io::ErrorKind::Unsupported. - crates/fast_io/Cargo.toml: add Win32_Networking_WinSock to the windows-sys feature list for WSARecv/WSASend bindings. Cross-platform compile preserved: the real implementation is gated behind cfg(all(target_os = "windows", feature = "iocp")) at the fast_io::iocp module level; non-Windows builds fall through to the stub. * style(transport): cargo fmt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds IOCP-backed async socket I/O for issue #1928, completing the Windows-side counterpart to the io_uring socket reader/writer. Each WSARecv/WSASend issues an OVERLAPPED Winsock operation that completes through the shared
CompletionPumpfrom #1897, so file I/O and socket I/O share a single drain thread.IocpSocketReader/IocpSocketWriterincrates/fast_io/src/iocp/socket.rswith six tests (localhost TCP roundtrip, 64 KB partial-send accounting, peer-shutdown EOF, empty-buffer fast paths, completion-key override).SharedPump = Arc<CompletionPump>lets multiple sockets and the existing IOCP file readers/writers share one pump.iocp_stub.rsexposes the same public surface so Linux and macOS continue to build.Win32_Networking_WinSockadded to thewindows-sysfeature list for the WSARecv/WSASend bindings.Integration with the IOCP pump (#1897)
The pump already exposes
register(overlapped_ptr, handler)/unregister/associate_handle/pending_ops. Sockets reuse those primitives unchanged:socket.rsallocates aBox<OVERLAPPED>so the kernel-visible pointer is stable, registers a oneshot handler, callsWSARecv/WSASend, and waits on the channel for the completion. Synchronous completions still flow through the pump for registry consistency.Upstream parity
Recv mirrors
safe_read(target/interop/upstream-src/rsync-3.4.1/io.c:239,:276): graceful peer close paths (WSAEDISCON,WSAESHUTDOWN,WSAENETRESET,WSAECONNRESET,WSAECONNABORTED) andSTATUS_END_OF_FILEcollapse toOk(0). Send mirrorssafe_write(io.c:312,:316-336): short counts are returned so the caller's loop re-issues; broken-pipe errors map toio::ErrorKind::BrokenPipe.Files added / modified
crates/fast_io/src/iocp/socket.rscrates/fast_io/src/iocp/mod.rs(singlepub mod socket;line, no other changes)crates/fast_io/src/iocp_stub.rs(parallelsocketstub module)crates/fast_io/Cargo.toml(Win32_Networking_WinSockfeature added)Cross-platform compile preserved
Real implementation is gated behind
cfg(all(target_os = \"windows\", feature = \"iocp\"))at thefast_io::iocpmodule level (inlib.rs); non-Windows builds fall through to the stub which returnsio::ErrorKind::Unsupportedfrom every constructor and method.Test plan
fast_io::iocp::socket::tests.