Skip to content

feat(fast_io): IOCP socket I/O via WSARecv/WSASend (#1928)#3539

Merged
oferchen merged 2 commits into
masterfrom
feat/iocp-socket-io-1928
May 2, 2026
Merged

feat(fast_io): IOCP socket I/O via WSARecv/WSASend (#1928)#3539
oferchen merged 2 commits into
masterfrom
feat/iocp-socket-io-1928

Conversation

@oferchen
Copy link
Copy Markdown
Owner

@oferchen oferchen commented May 1, 2026

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 CompletionPump from #1897, so file I/O and socket I/O share a single drain thread.

  • New IocpSocketReader / IocpSocketWriter in crates/fast_io/src/iocp/socket.rs with 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.
  • Cross-platform stub in iocp_stub.rs exposes the same public surface so Linux and macOS continue to build.
  • Win32_Networking_WinSock added to the windows-sys feature 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.rs allocates a Box<OVERLAPPED> so the kernel-visible pointer is stable, registers a oneshot handler, calls WSARecv/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) and STATUS_END_OF_FILE collapse to Ok(0). Send mirrors safe_write (io.c:312, :316-336): short counts are returned so the caller's loop re-issues; broken-pipe errors map to io::ErrorKind::BrokenPipe.

Files added / modified

  • new crates/fast_io/src/iocp/socket.rs
  • crates/fast_io/src/iocp/mod.rs (single pub mod socket; line, no other changes)
  • crates/fast_io/src/iocp_stub.rs (parallel socket stub module)
  • crates/fast_io/Cargo.toml (Win32_Networking_WinSock feature added)

Cross-platform compile preserved

Real implementation is gated behind cfg(all(target_os = \"windows\", feature = \"iocp\")) at the fast_io::iocp module level (in lib.rs); non-Windows builds fall through to the stub which returns io::ErrorKind::Unsupported from every constructor and method.

Test plan

  • CI: fmt + clippy on all platforms.
  • CI: nextest on Windows runs the six new socket tests under fast_io::iocp::socket::tests.
  • CI: nextest on Linux/macOS exercises the stub and confirms the workspace still cross-compiles.

@github-actions github-actions Bot added the enhancement New feature or request label May 1, 2026
@oferchen oferchen force-pushed the feat/iocp-socket-io-1928 branch from f2c8caf to ca19ab0 Compare May 1, 2026 22:31
oferchen added 2 commits May 2, 2026 04:27
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.
@oferchen oferchen force-pushed the feat/iocp-socket-io-1928 branch from ca19ab0 to 9cc8cec Compare May 2, 2026 01:27
@oferchen oferchen merged commit 430631c into master May 2, 2026
38 checks passed
@oferchen oferchen deleted the feat/iocp-socket-io-1928 branch May 2, 2026 03:49
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant