net: fix Windows MSG_PEEK/MSG_WAITALL receives and preserve socket modes #1174

Closed
github-bot wants to merge 1 commit from gh-pr/1174/head into gh-pr/1174/base
Owner

@⁠theantipopau on GitHub · 2026-10-08 00:01 UTC · original
theantipopau:net-win-recv → main · +216 −15 · 2 files · 1 commits · closed without merging

Summary

Windows guest networking fixes found while running real PS5 dumps on our fork:

  • Datagram MSG_PEEK|MSG_WAITALL → WSAEOPNOTSUPP. Winsock rejects the combined flag on connectionless sockets even though a datagram is delivered whole (proven with a standalone probe: len=0 MSG_PEEK works, MSG_PEEK|MSG_WAITALL → 10045). Stream sockets keep the combined flag; datagram receives strip MSG_WAITALL.
  • Guest non-blocking mode is tracked per socket. Winsock cannot report the current mode, so the guest-side flag is stored on the transport and inherited across accept() the way FreeBSD inherits O_NONBLOCK, keeping native and guest bookkeeping in agreement.
  • Peeked stream bytes are replayed from a bounded receive buffer instead of re-peeking the socket, so a peeked prefix survives for the following WAITALL receive and end-of-file short reads complete correctly.

Test coverage (tests/KernelFileSystemTests.cpp)

  • fragmented message completes a PEEK|WAITALL receive, peeked bytes stay available afterwards
  • MSG_DONTWAIT returns the buffered prefix without waiting, then EWOULDBLOCK on empty
  • peer-closes-early ends the wait with the buffered bytes; EOF reports work for both plain and PEEK|WAITALL receives
  • accepted sockets inherit non-blocking mode (Windows)
  • defines SDL_MAIN_HANDLED so the Windows entry point is not renamed — the same two lines as #948; identical additions, so merge order between the two PRs does not matter.

Verification (Windows x64, local)

  • full build clean (all target).
  • kernel_file_system_tests fresh binaries:
    • against plain upstream/main + this branch: reaches and fails only at upstream's own new datagram check "Net unknown socket options return protocol-option errors" — the Windows ENOPROTOOPT gap fixed by #1159, unrelated to this change.
    • with #1159's f5d8d52a applied on top: KernelFileSystemTests: all cases passed.
  • real game-run (Astro Bot, PPSA21564) on a build containing these changes: 300 s timeout-survival, no faults.

Notes for maintainers

  • kernel_file_system is not in .github/workflows/build.yml's ctest -R subsets on any platform, so none of this runs in CI today. Recommend adding it to the workflow once #1159 lands (otherwise the Windows job fails on the ENOPROTOOPT gap).
**@⁠theantipopau** on GitHub · 2026-10-08 00:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1174) `theantipopau:net-win-recv` → `main` · +216 −15 · 2 files · 1 commits · closed without merging ## Summary Windows guest networking fixes found while running real PS5 dumps on our fork: - **Datagram `MSG_PEEK|MSG_WAITALL` → `WSAEOPNOTSUPP`.** Winsock rejects the combined flag on connectionless sockets even though a datagram is delivered whole (proven with a standalone probe: len=0 `MSG_PEEK` works, `MSG_PEEK|MSG_WAITALL` → 10045). Stream sockets keep the combined flag; datagram receives strip `MSG_WAITALL`. - **Guest non-blocking mode is tracked per socket.** Winsock cannot report the current mode, so the guest-side flag is stored on the transport and **inherited across `accept()`** the way FreeBSD inherits `O_NONBLOCK`, keeping native and guest bookkeeping in agreement. - **Peeked stream bytes are replayed from a bounded receive buffer** instead of re-peeking the socket, so a peeked prefix survives for the following `WAITALL` receive and end-of-file short reads complete correctly. ## Test coverage (`tests/KernelFileSystemTests.cpp`) - fragmented message completes a `PEEK|WAITALL` receive, peeked bytes stay available afterwards - `MSG_DONTWAIT` returns the buffered prefix without waiting, then `EWOULDBLOCK` on empty - peer-closes-early ends the wait with the buffered bytes; EOF reports work for both plain and `PEEK|WAITALL` receives - accepted sockets inherit non-blocking mode (Windows) - defines `SDL_MAIN_HANDLED` so the Windows entry point is not renamed — **the same two lines as #948**; identical additions, so merge order between the two PRs does not matter. ## Verification (Windows x64, local) - full build clean (`all` target). - `kernel_file_system_tests` fresh binaries: - against plain `upstream/main` + this branch: reaches and fails only at upstream's own new datagram check *"Net unknown socket options return protocol-option errors"* — the Windows `ENOPROTOOPT` gap fixed by **#1159**, unrelated to this change. - with #1159's `f5d8d52a` applied on top: **`KernelFileSystemTests: all cases passed`**. - real game-run (Astro Bot, PPSA21564) on a build containing these changes: 300 s timeout-survival, no faults. ## Notes for maintainers - `kernel_file_system` is not in `.github/workflows/build.yml`'s ctest `-R` subsets on any platform, so none of this runs in CI today. Recommend adding it to the workflow once #1159 lands (otherwise the Windows job fails on the `ENOPROTOOPT` gap).
Winsock rejects MSG_PEEK|MSG_WAITALL on datagram sockets with
WSAEOPNOTSUPP even though a datagram is delivered whole, so strip
MSG_WAITALL for non-stream receives. Track the guest non-blocking mode
per socket (Winsock cannot report it), inherit it across accept the way
FreeBSD does, and replay peeked stream bytes from a bounded receive
buffer instead of re-peeking the socket.

KernelFileSystemTests gains coverage for fragmented WAITALL receives,
peeked-byte persistence, MSG_DONTWAIT prefixes, end-of-file short reads
and accepted-mode inheritance, and defines SDL_MAIN_HANDLED so the
Windows entry point is not renamed (same two lines as #948).

Verified locally on Windows x64: kernel_file_system passes end to end
when the ENOPROTOOPT gap from #1159 is applied on top; without #1159
upstream's own new datagram check fails on Windows regardless of this
change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:26 +00:00
github-bot closed this pull request 2026-11-26 09:46:26 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 00:05 UTC · original

Review in Change Stack →

📝 Walkthrough

Walkthrough

The network layer now tracks Windows guest blocking mode and applies the listener’s mode to accepted sockets. Stream receives retain MSG_WAITALL, while datagram receives clear it. The tests cover fragmented and nonblocking TCP receives, EOF behavior, accepted-socket mode, and zero-length UDP datagrams.

Suggested reviewers: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🔵 Low · up to 47ad3

The change fixes Windows peek and wait-all receives and preserves socket modes. One new accepted-socket test may abort on a valid would-block result. That is a bounded, test-only risk worth fixing before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the Windows networking fixes, test coverage, verification results, and CI limitation. It is directly related to the changeset.
Title check ✅ Passed The title clearly identifies the Windows networking fixes for MSG_PEEK/MSG_WAITALL receives and socket-mode preservation. It is concise and related to the primary changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 00:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1174#issuecomment-6049347204) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1174?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The network layer now tracks Windows guest blocking mode and applies the listener’s mode to accepted sockets. Stream receives retain `MSG_WAITALL`, while datagram receives clear it. The tests cover fragmented and nonblocking TCP receives, EOF behavior, accepted-socket mode, and zero-length UDP datagrams. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"47ad391f8eede5617b4c9f922ac4f67a5ec926d5" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🔵 Low** · up to `47ad3` <!-- final_review_risk_coverage:{"sourceCommitId":"47ad391f8eede5617b4c9f922ac4f67a5ec926d5","coveredCommitId":"47ad391f8eede5617b4c9f922ac4f67a5ec926d5","kind":"reviewed"} --> The change fixes Windows peek and wait-all receives and preserves socket modes. One new accepted-socket test may abort on a valid would-block result. That is a bounded, test-only risk worth fixing before merge. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ✅ Passed | The description clearly explains the Windows networking fixes, test coverage, verification results, and CI limitation. It is directly related to the changeset. | | Title check | ✅ Passed | The title clearly identifies the Windows networking fixes for MSG_PEEK/MSG_WAITALL receives and socket-mode preservation. It is concise and related to the primary changes. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1174)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -1377,0 +1498,4 @@
inherited_consumed += static_cast<size_t>(inherited_chunk);
continue;
}
Check(inherited_chunk == -1 && *net_errno == Libs::Posix::POSIX_EWOULDBLOCK,
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 00:05 UTC · original

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Check the errno set by Net::Recv.

If the suffix has not arrived, this nonblocking Net::Recv can return would-block. The assertion then reads net_errno, which belongs to the separate Net ABI path and still holds POSIX_EINVAL. The test aborts instead of retrying. Check *Libs::Posix::GetErrorAddr() here. (learn.microsoft.com)

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 00:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1174#discussion_r4213268159) **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** **Check the errno set by `Net::Recv`.** If the suffix has not arrived, this nonblocking `Net::Recv` can return would-block. The assertion then reads `net_errno`, which belongs to the separate Net ABI path and still holds `POSIX_EINVAL`. The test aborts instead of retrying. Check `*Libs::Posix::GetErrorAddr()` here. ([learn.microsoft.com](https://learn.microsoft.com/windows/win32/api/winsock/nf-winsock-recv?utm_source=openai)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:bd0d95cd1f09fa6d622fa6fa --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 00:05 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9a39c2ea-b53f-449a-a0cc-1d950e681ec5
📥 Commits

Reviewing files that changed from the base of the PR and between 5a8808086a and 47ad391f8e.

📒 Files selected for processing (2)
  • src/libs/network.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 00:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1174#pullrequestreview-5449856186) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `9a39c2ea-b53f-449a-a0cc-1d950e681ec5` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5a8808086a9815b67d4822cd20cf1e8a7a05f002 and 47ad391f8eede5617b4c9f922ac4f67a5ec926d5. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/libs/network.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=d22658fb-9019-4582-8d98-baf2c49610e8 attempt=001b00da-54b3-42f6-9b32-73296ec74702 batch=1/1 -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.