fix(libSceNet): read SO_RCVTIMEO and SO_SNDTIMEO as a timeval in sceNetSetsockopt #5967
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5967"
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-14T17:23:59Z.
What
sceNetSetsockopttook the BSD timeout options,SO_SNDTIMEO(0x1005) andSO_RCVTIMEO(0x1006), like Sony's 0x1105 and 0x1106: as anintof microseconds read from the first four bytes. A caller passing astruct timevalgottv_sectaken as microseconds. So{0, 100000}, meant to wait 100 ms, became 0, which disables the timeout, and the receive blocked until data came.On the console, 0x1006 takes a
timeval, as FreeBSD 11.4'ssosetoptdoes:platform/ps5/ps5_sockets.cL194-197). It gives 0x1006 a{0, 100000}timeval for Moonlight's video and audio receives (moonlight-common-cPlatformSockets.cL72-93).VideoStream.c). With anintreading the timeout would have been 0 and the count "0 ms".timevalto 0x1105 and 0x1106, asints of microseconds. Its other socket options keep FreeBSD's numbers.#4371 kept the
intreading for 0x1006 insceNetSetsockopt, as it had been, while makingsetsockopt()on a libSceNet socket take atimeval. This change sends 0x1005 and 0x1006 insceNetSetsockoptthrough that sametimevalpath:EINVALfor a value shorter than atimeval,EDOMfor a negative or out-of-range one;sceNetGetsockoptgives them back as atimevalcut to the caller's length, as FreeBSD'ssooptcopyoutdoes;intof microseconds.The second commit records the formats in
docs/dev/debt/libSceNet.md. The errors and the cut follow FreeBSD and aren't measured on a console.What the titles do on
main:LiStopConnectionjoins them before closing their sockets (AudioStream.cL409-416,VideoStream.cL289-311). So when a session ends from the PC side, or the user stops while the PC sends nothing, the stream screen freezes and the app never returns to its launcher.{0, 10000}the same way (ihslibclient.cL238-L241). When the PC doesn't answer a stream request, the worker never wakes to see its stop flag, so the app stays on "THE PC DID NOT ANSWER".Related: #4371; #5617 adds the same two options to libkernel's own sockets, the ones from
socket(). The two changes touch different files.Tested
On GitHub's runners from my fork, on
mainata453108cf(run):-DANYPS5_ENABLE_SPIRV_TOOLS=ON.guest_sce_net:{0, 50000}throughsceNetSetsockopt, reads 50000 back through 0x1106, and checks thatsceNetRecv,sceNetRecvfromandsceNetRecvmsgfail withEAGAIN;EINVALfor a 4-byte value andEDOMfor{0, 1000000}and{-1, 0}, all leaving the timeouts unchanged;timevalback through 0x1006, also cut to 4 bytes;intof microseconds.Results:
main'sExport.cppthe test aborts on both, because 0x1006 still takes the first four bytes as microseconds.core/libs/prx/libcandcore/libs/prx/libkernelpasses: 71 and 136 on Linux, 93 and 140 on Windows.tools/check_conventions.py --base origin/mainpasses for both commits.mainate34c47921: 1198 of 1198 tests pass (run).Steam-Link-PS5 (PPSA99350, homebrew, 1.0.0) on Windows 11 Home 10.0.26300, RTX 3070 Laptop (driver 617.42), Ryzen 9 5900HS, 15.4 GB RAM:
mainata453108cfwith #5966, once without this change and once with it. Without #5966 the title finds no PC on Windows at all.WSAECONNRESETon the next receive ends the worker by itself, which hides the hang.IHS_ClientThreadedJoinnever returns: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 screamm on 2026-10-15T02:00:25Z.
Cross-check on Windows: #5967 head
7f82da108merged ontomain6239ceffc; the merge is clean, including over #5536'ssceNetGetsockoptchange.Host: Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, NVIDIA RTX 4070 (Ryzen 7 5700X).
cmake --build build -- -k 0) andlibsboth succeed, with no new warnings.guest_sce_net,--repeat until-fail:3: 3/3, plus 20/20 when run directly, on an idle host. Earlier, under heavy host load (other builds running), it aborted (0xc0000409) on the second run twice:CheckEmptyEpoll, which this PR does not touch;sceNetEpollWaitwaits is under 8 ms;APS5_NO_TIMER_RESOLUTION=1, which skips that check, the PR's binary passed 20/20 under the same load;main's binary failed 8/20 at the same place and the PR's 6/20. So this is a load-sensitive flake onmain, not a regression.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 808 tests. 807 pass, including the 2 skipped, andguest_sce_netpassed.conventions_function_bodiestimed out under host load and passes alone.ProsperoLight (PPSA99002). Catalog release,
app0/eboot.binstaged,relinker --windows --registry unused-filter=0. 60 s per run with the display on, two alternating pairs.mainProsperoLight | FPS: 1.85 (241)ProsperoLight | FPS: 6.81 (391)ProsperoLight | FPS: 8.77 (467)ProsperoLight | FPS: 8.40 (474)All four reach the launcher.
prosperolight-launcher.loghas[PL] launcher: first frame after 3032-5853 ms, splash hidden=1and[PL] update check: result=unknown ..., then the launcher keeps drawing frames. The first pair's gap is host load. No stop line with either build.poll: descriptor 10 is neither a socket nor a pipedoes not appear with either build. An earlier catalog run (mainc2565f0, eboot staged) stopped with it. It went away onmainitself, most likely through #4933 (fix(libkernel): poll libSceNet sockets with the host wait). This PR does not change it.With no PC host to stream from, the launcher logs no socket activity. The
sceNetSetsockoptpath for 0x1005/0x1006 is imported (2mKX2Spso7I) but not reached in this run.Verdict: build and
guest_sce_netconfirmed, and ProsperoLight behaves the same as onmain(launcher, no stop). The streaming path the PR fixes cannot be exercised without a PC host.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T02:05:31Z.
Thanks for the Windows cross-check, and for running down the
guest_sce_netabort to the epoll timer check onmain. You're right that ProsperoLight only reaches the fixed path when it streams from a PC host. The red/green in the description,guest_sce_net's new receive-timeout cases, is what covers it.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T02:34:11Z.
I ran this PR's test on Linux, to go with screamm's Windows check above. This adds a run with the fix taken out.
Setup: this PR's diff applied to main at
8cd937e29(the PR's base is 425 commits behind it), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), clean environment.ctest -R '^guest_sce_net$', 3 runs each. The test did not open a GPU device, so this is a CPU-only run.Requireprints no message, so I took a backtrace of one more run under gdb: it stops inRequireTimeout(changed by this PR), called fromCheckKernelTimeouts.So the new test catches the old option handling here. I did not check Windows or macOS.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-15T02:39:45Z.
Thanks for the run with the fix taken out. That's the Linux half of the red/green, from an independent build.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:12:27Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceNet.mdL14Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/tests/GuestSceNet.cppcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdcore/libs/prx/libSceNet/Export.cppdocs/dev/debt/libSceNet.mdImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T19:08:10Z.
Checked on the PR merged onto current
main: build and the 37 tests in scope pass,guest_sce_netincluded. WithExport.cppreverted the new test fails, so it covers the change. 0x1005/0x1006 now take atimevallike FreeBSD'ssosetopt/sogetopt, 0x1105/0x1106 stayintmicroseconds, and the debt line is in place. Also confirmed by @screamm (Windows) and @Dextroid17 (Linux). Merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:00:18Z.
Re-checked on the PR merged onto current
main: build and the 40 tests in scope pass,guest_sce_netincluded. WithExport.cppreverted the new test fails, so it covers the change. 0x1005/0x1006 now take atimevallike FreeBSD'ssosetopt/sogetopt, 0x1105/0x1106 stayintmicroseconds, and the debt line is in place. Also confirmed by @screamm (Windows) and @Dextroid17 (Linux). Merging once CI is green.