net: resolve guest PEEK and WAITALL flags on Windows #751
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!751
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/751/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@rudy-07 on GitHub · 2026-09-21 15:19 UTC · original
fix/win32-msg-peek-waitall-505→main· +164 −2 · 2 files · 4 commits · closed without mergingCloses #505
Summary
Resolves the Windows linker failure and test failure in
KernelFileSystemTests(guest PEEK and WAITALL preserve the wake bytes, exit code0xc0000409).Root Cause
#include "SDL.h"withoutSDL_MAIN_HANDLEDredirectsmaintoSDL_main, causinglld-linkto fail withundefined symbol: mainwhen buildingkernel_file_system_testson Windows.MSG_PEEKandMSG_WAITALLis valid. However, on Windows Winsock, passing both flags to::recv()causes Winsock to returnWSAEOPNOTSUPP(10045).Solution
SDL_MAIN_HANDLED: Defined ahead of#include "SDL.h"inKernelFileSystemTests.cppso the test binary links without rewritingmain.ConvertMessageFlags): On Windows, masks outMSG_WAITALLwhenMSG_PEEKis active to prevent Winsock from rejecting the call withWSAEOPNOTSUPP.MSG_WAITALLEmulation (Recvfrom):MSG_WAITALLsemantics when peeking: awaitshost_lenbytes viaioctlsocket(FIONREAD)/select/WSAPollbefore peeking, avoiding short reads on chunked arrivals.POLLHUP) or error (POLLERR) and returns partial data.SO_RCVTIMEOif configured on the socket.ORBIS_SO_NBIOorMSG_DONTWAIT) bypass the wait loop and delegate to nativerecvto return immediately or fail withWSAEWOULDBLOCK.SOCKET_ERRORfromWSAPoll.KernelFileSystemTests.cppverifying both non-blockingEWOULDBLOCKand chunked partial-arrival behavior.Testing
clang-cl: clean build passes full test suite (40/40).@copilot-pull-request-reviewer[bot] on GitHub · 2026-09-21 15:21 UTC · original · reviewed
Copilot review overview
🟡 Changes recommended
Windows peeks must preserve
MSG_WAITALLsemantics for partial arrivals.Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR fixes Windows handling of
MSG_PEEK | MSG_WAITALLand SDL entry-point rewriting in the filesystem test.Changes:
SDL_MAIN_HANDLEDbefore including SDL headers.tests/KernelFileSystemTests.cppmain.src/libs/network.cppMSG_WAITALLfor Windows peeks, but may lose wait-all behavior for partial arrivals.💡 Add a
code-reviewagent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.@ -1076,0 +1090,4 @@// Winsock fails with WSAEOPNOTSUPP if MSG_PEEK and MSG_WAITALL are combined.// When peeking on Windows, clear MSG_WAITALL so host recv/recvfrom succeeds while preserving socket data.if ((host_flags & MSG_PEEK) != 0) {host_flags &= ~MSG_WAITALL;@Copilot on GitHub · 2026-09-21 15:21 UTC · original
This drops the guest
MSG_WAITALLsemantic wheneverMSG_PEEKis present: on Windows a peek forlenbytes can now return as soon as any bytes are available, whereas POSIX waits for the requested length (subject to its normal interruption/EOF rules). The current regression test sends the complete payload before receiving, so it does not expose this partial-arrival case. Please preserveWAITALLbehavior by emulating the wait before peeking, rather than silently returning short reads.@coderabbitai[bot] on GitHub · 2026-09-21 15:23 UTC · original · edited 2026-09-21 19:24 UTC
Understand this PR’s impact
Explore downstream dependencies and potential security impact with Blast Radius.
View blast radius →
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
b02c990d-f1c1-44eb-aabd-5b9e56b0c1c1📥 Commits
Reviewing files that changed from the base of the PR and between
1ce0fc8550and007c68ca4a.📒 Files selected for processing (1)
tests/KernelFileSystemTests.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough
On Windows, stream receives with guest
MSG_PEEKandMSG_WAITALLskip wait emulation for nonblocking sockets andMSG_DONTWAIT. Blocking sockets still wait for data, EOF, timeout, or error.WSAPollfailures now return converted host errors. The kernel file system test configures SDL entry-point handling and verifies delayed two-part payload delivery.Suggested reviewers:
defektuPriority: ➖ Normal
Change: Bug fix
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
#505] requires Windows guestPEEK | WAITALLto preserve wake bytes and allowkernel_file_systemto pass.ConvertMessageFlagsclears unsupported WindowsMSG_WAITALLfor peeks.Recvfrom…#505]. The socket changes fix the reported Windows flag combination. The test changes provide regression coverage and required Windows SDL linkage. The nonblocking state track…Comment
@coderabbitai helpto get the list of available commands.@rudy-07 on GitHub · 2026-09-21 15:38 UTC · original
Thanks for the feedback! I have updated the PR (commit
1361216):MSG_WAITALL Emulation on Windows: Rather than returning short reads on partial arrivals, Recvfrom now emulates MSG_WAITALL when combined with MSG_PEEK on stream sockets by awaiting host_len pending bytes via FIONREAD / select / WSAPoll. It also properly handles remote peer disconnection (POLLHUP / EOF) by returning partial accumulated data per POSIX semantics, and respects SO_RCVTIMEO.
Docstrings: Added Doxygen documentation for ConvertMessageFlags and Recvfrom to satisfy docstring coverage checks.
@coderabbitai[bot] on GitHub · 2026-09-21 15:44 UTC · original · edited 2026-09-21 15:54 UTC
On
src/libs/network.cppline 2257 (outdated):🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6598
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 36657
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 36505
Skip
MSG_WAITALLemulation for nonblocking sockets.When
ORBIS_SO_NBIOenablesFIONBIO,Recvfromstill enters this Windows stream branch forMSG_PEEK|MSG_WAITALL. If fewer thanhost_lenbytes are available andSO_RCVTIMEOis zero, the loop can block indefinitely inselector keep sleeping and retrying. Track the native nonblocking state inSocketSlotwhenSetsockoptchanges it, and run this emulation only for blocking sockets. Nativerecvcan then return available data orWSAEWOULDBLOCK.✅ Addressed in commit
1ce0fc8@coderabbitai[bot] on GitHub · 2026-09-21 15:44 UTC · original · edited 2026-09-21 15:54 UTC
On
src/libs/network.cppline 2282 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4285
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4423
Propagate
WSAPollerrors.WSAPollreturnsSOCKET_ERRORwhen polling fails. The> 0condition ignores that result. The loop can then enterselect, sleep, or return a timeout instead of propagating the poll error.Proposed fix
📝 Committable suggestion
✅ Addressed in commit
1ce0fc8@coderabbitai[bot] on GitHub · 2026-09-21 15:44 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
bc81aa0a-53f8-4401-b9f6-fc8ce09f0805📥 Commits
Reviewing files that changed from the base of the PR and between
97bb9baf90and136121615b.📒 Files selected for processing (1)
src/libs/network.cppIncluded review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@francoisatt on GitHub · 2026-09-21 19:10 UTC · original
Tested on Windows (native build, clang-cl, full clean build), as the reporter of #505. Since the CI workflow is still awaiting approval, this may be the only Windows run so far.
Same base for all three builds (
ba55ba5, the merge-base of this PR):undefined symbol: main, SDL)0xc0000409, "guest PEEK and WAITALL preserve the wake bytes" (the #505 failure)1ce0fc8)So both parts are needed: the SDL define makes the test link, and the network.cpp change fixes the actual PEEK+WAITALL failure.
Full suite on this PR: 39/40 as run, the 40th (save_data_memory) was only missing from my local build script; built separately, it passes.
Not verified: the regression test sends the whole payload before receiving, so it does not exercise the WAITALL emulation added in
1361216(partial arrival, peer close, SO_RCVTIMEO), nor the nonblocking skip from1ce0fc8. That is the case Copilot raised. Also, the PR description still describes the first approach (clearing MSG_WAITALL), which may be worth updating for reviewers.@rudy-07 on GitHub · 2026-09-21 19:22 UTC · original
Thank you so much for taking the time to test all three configurations natively with clang-cl and confirming the fix! That validation is super helpful.
Regarding your observations:
Regression Test Coverage: I've pushed commit
007c68c, adding explicit test assertions in KernelFileSystemTests.cpp for both:PR Description: Updated the PR description to accurately detail the MSG_WAITALL emulation, non-blocking bypass, error handling, and test coverage for reviewers.
@francoisatt on GitHub · 2026-09-24 18:40 UTC · original
Heads-up: #797 (theantipopau) covers the same Winsock MSG_PEEK | MSG_WAITALL limitation and the same SDL_MAIN_HANDLED fix, with a broader implementation (accepted sockets, datagrams, MSG_DONTWAIT, EOF) that also handles the partial-arrival case Copilot raised above. Both are open and neither references the other. My test results above still stand for this PR; posting this so it gets resolved rather than both stalling.
@Nmzik on GitHub · 2026-10-03 17:16 UTC · original
Credited
Pull request closed