fix(libSceNet): report a stream whose peer closed as readable on Windows #9493
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9493"
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?
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T23:21:24Z.
Opened again from #5376: title-less conformance fixes of this kind are merged now, for example #7365 and #8411.
What
When the peer of a stream socket closes, Winsock's
WSAPollreportsPOLLHUPwithoutPOLLRDNORM, whether or not the socket's own sending side is shut down.sceNetEpollWaitpasses that on, so on Windows a socket whose peer has closed comes back asSCE_NET_EPOLLHUPalone and never as readable. A loop that waits forSCE_NET_EPOLLINto read the end of the stream never gets it, while every wait returns at once.FreeBSD's
sopoll_genericreports a socket that can receive no more as readable, and addsPOLLHUPonly once it can send no more either. Linux'spolldoes the same, sosceNetEpollWaitalready reports it this way on Linux.On Windows, a stream socket's
POLLHUPwithoutPOLLERRnow reportsPOLLRDNORMwhen reading was asked for. It keepsPOLLHUPonly aftersceNetShutdownhas shut the socket's own sending side, which libSceNet now records assending_shut, next to theread_shutthatmainrecords.Unchanged:
POLLHUPwithPOLLERR) keeps the flagsWSAPollreports.sceNetSocketAbortshuts the host socket down without being recorded as a shutdown.pollgets the same change for its own stream sockets in #9492.selectalready counts a hang-up as readable.No title is claimed.
Overlap: #8598, now on
main, changed howsceNetEpollWaitcaptures its registrations: each one is aWatchthat holds the registration and the socket's handle. The merge ofmaininto this branch (0a01fca94f) keeps that, with eachWatchholding the copy of the socket'sSockthis PR reads, whose handle is the sameshared_ptr.Tested
On GitHub's runners from my fork, merged with
mainata6dcea9279(run):The new
CheckEpollClosedStreaminguest_sce_netchecks three states in order:sceNetEpollWaitreports exactlySCE_NET_EPOLLIN;SCE_NET_EPOLLIN | SCE_NET_EPOLLOUTwhen both are asked for;sceNetShutdownof the sending side, it reportsSCE_NET_EPOLLIN | SCE_NET_EPOLLHUP.Results:
main'sExport.cppguest_sce_netfails. With the change, it passes 10 runs in a row.guest_sce_netpasses withmain's code and, 10 runs in a row, with the change.core/libs/prx/libc(142) andcore/libs/prx/libkernel(207) passes. Linux: libkernel (197) passes; in libc (115), the timing testprecise_waitfailed with and without the change in this run.mainat17f5335562(run):guest_sce_netand #8598's eightnet_epoll_lifetime_*tests pass 10 runs in a row on both runners, and withmain'sExport.cppguest_sce_netfails on Windows. The libc and libkernel suites pass on Windows (143, 207) and libkernel on Linux (197);precise_waitfailed on Linux with and without the change again.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:27:47Z.
Review: APPROVED
Reviewed the Windows epoll translation and regression test. The change limits the adjustment to stream sockets reporting
POLLHUPwithoutPOLLERR, adds the read bit only when requested, and retains hang-up after the local sending side is shut down. The test covers peer close, EOF, requested writable readiness and the subsequent local shutdown state. The reported Windows and Linux focused suites pass; conventions, intake, eligibility, labels and report checks pass, while hosted product build jobs are skipped.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:11:29Z.
Review: APPROVED
Re-reviewed the current head and manually checked the shared-file warnings. #8598 changes registration lifetime and snapshots; it composes with this PR's event translation, with the documented small rebase needed if both merge. The other shared-file warnings concern unrelated exports or tests. The Windows mapping is limited to stream without , only sets read readiness when requested, and preserves the local-send-shutdown state. Reported Windows/Linux tests exercise those states. Hosted policy checks pass; product and relinker jobs are skipped. I did not run local tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T02:13:07Z.
Review: APPROVED
Re-reviewed the current head and manually checked the shared-file warnings. #8598 changes registration lifetime and snapshots; it composes with this PR's event translation, with the documented small rebase needed if both merge. The other shared-file warnings concern unrelated exports or tests. The Windows mapping is limited to stream sockets reporting
POLLHUPwithoutPOLLERR, only sets read readiness when requested, and preserves the local-send-shutdown state. Reported Windows/Linux tests exercise those states. Hosted policy checks pass; product and relinker jobs are skipped. I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:27:01Z.
Review: DISMISSED
The Windows stream event translation is narrowly scoped to
POLLHUPwithoutPOLLERR; it adds requested read readiness, preservesPOLLERR, and retains hang-up after local send shutdown. The regression checks peer close, EOF, requested writable readiness and local shutdown. The #8598 registration-snapshot overlap is documented as composable with a rebase if needed. The branch and reported tests are based ona6dcea9279, while current upstream main isab347d144d. Please rebase and rerunguest_sce_netand conventions on current main, then refresh the overlap scan and preserve #8598’s registration changes. Hosted product jobs are skipped; I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T06:46:03Z.
Review: COMMENTED
macOS test: the new
CheckEpollClosedStreamfails, XNU has the same problemApple M2 Max, macOS 27.2, Apple clang (Xcode 27), x86-64 Release build under Rosetta 2,
BUILD_TESTING=ON, full default build. Head0a01fca94f.maindoes not build on macOS, so the platform is #8658 (feat/macos-port) @fa063d8b07with this PR's diff applied (clean apply).guest_sce_netpasses on #8658 alone.With this PR,
guest_sce_netaborts in the new case. The first wait after the peer closes returnsevents=0x11(SCE_NET_EPOLLIN | SCE_NET_EPOLLHUP), not0x1. XNU is not FreeBSD here either. A plain loopback probe (pollon the accepted socket after the clientcloses):So XNU sets
POLLHUPas soon as the peer closes, and dropsPOLLOUTwhilePOLLHUPis set, even though this side can still send. #8658 already handles this for libkernel'spollinClosedStreamEvents(Socket/src/Udp.cpp,#if defined(_WIN32) || defined(__APPLE__)): it adds the readable bit, re-pollsPOLLOUTalone whenPOLLOUTwas asked for, and keepsPOLLHUPonly after a send shutdown.As a check, I enabled
closed_stream_eventson__APPLE__too, usingPOLLINinstead ofPOLLRDNORMand with the samePOLLOUTre-poll, and called it after::pollinsceNetEpollWait. With that, the three waits return0x1,0x3and0x11as the test expects, andguest_sce_netplus thenet_*tests pass 20/20, 3/3. This PR does not have to carry the macOS part, sincemaindoes not build on macOS yet. But once #8658 (or the port) lands, this test will fail on macOS until the_WIN32guard also covers__APPLE__. The experiment diff is attached below in case it helps.macOS experiment (on top of this PR)
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.