fix(libSceNet): let a datagram receive on an unbound socket wait on Windows #5966
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5966"
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:38Z.
What
Steam-Link-PS5 (PPSA99350), a homebrew Steam Remote Play client, never finds a PC on Windows. It stays on its first screen while Steam on the same PC answers discovery:
No
discovered ... at ...line follows.On Windows,
sceNetRecv,sceNetRecvfromandsceNetRecvmsgfail at once withEINVALon a datagram socket that has no local address yet. Winsock's receive returnsWSAEINVALfor a socket that isn't bound (recvfrom).On the console the receive waits. UDP receives through FreeBSD 11.4's
soreceive_dgram(udp_usrreq.cL1780), which sleeps on the receive buffer whether or not the socket has an address, and returnsEWOULDBLOCKfor a non-blocking socket. A send from another thread then binds the socket, and the reply arrives. Linux waits the same way.The title's stream library, ihslib, relies on that:
base.cL199-L213). Any error other thanEAGAIN,EWOULDBLOCKorETIMEDOUTends the worker, which closes the socket (ihs_udp_posix.cL68-L78).discovery.cL37-L47), and the title asks for a single one at start (main.cppL920). Its BSD socket calls go straight to libSceNet (ps5_sockets.cL192-L207).EINVALand closed the socket before the broadcast went out, so no PC could answer.With this change, on Windows a receive on a datagram socket with no local address waits until a bind, connect or send gives it one. Those calls wake the wait at once, and the wait also checks the host socket every 10 ms:
EAGAINat once;EAGAIN, and when the address comes first, the receive waits for a datagram only for what is left of the timeout;sceNetShutdownof the receive side (SHUT_RDorSHUT_RDWR) ends the wait, and the receive returns 0, as do later receives while the socket has no address. That's whatsoreceive_dgramdoes once the socket can't receive more (L2199-L2203). FreeBSD'ssoshutdownflushes the receive side of an unconnected datagram socket and returnsENOTCONN, keeping the old behaviour that programs use to release a thread blocked in a receive (L2352-L2383). Without this, a title that stops its receiver thread that way would hang on Windows;soreceive_dgramdoes when nothing was asked for (same lines);sceNetBindfails withEINVAL, as on the console.Commits:
fix: the wait.docs: records the wait indocs/dev/debt/libSceNet.md.refactor: insceNetRecvmsgthe wait comes after the socket type check. No change in behaviour.fix: shutdown and zero-byte receives return 0, with their test and the debt line.test: the bind and connect paths, next to the send path the first test covers.perf: bind, connect and send wake the wait instead of leaving it to the next 10 ms check. On Windows a connect or send marks the socket bound only once the host socket has its address.fix: one receive timeout covers the wait and the receive. Before, when the address came during the wait, the host receive waited its whole timeout again, so a call could take up to twice the timeout; now it polls (WSAPoll) only for what is left and fails withEAGAINwhen that runs out. The debt line says so.Scope: sockets a title opens through libkernel rather than libSceNet (
socket, thenrecv,recvfrom,recvmsgorreadon them) still fail such a receive withEINVALon Windows. That's libkernel's socket layer, which this PR doesn't change.Related: #4614, which gave an unbound socket's
sceNetGetsocknamethe zero address on Windows.Overlap: #5141 adds a stream-socket loopback check right above
sceNetConnect's::connectline, which commit 6 turned into a block for the datagram wake-up. Whichever merges second keeps both.Tested
On GitHub's runners from my fork:
-DANYPS5_ENABLE_SPIRV_TOOLS=ON.In
guest_sce_net:CheckUnboundDatagramReceive:sceNetRecv,sceNetRecvfromandsceNetRecvmsgeach fail withEAGAINafter at least 40 ms. Made non-blocking (0x1200),sceNetRecvfromfails withEAGAINat once.sceNetRecvfromon an unbound socket gets the reply to that socket's firstsceNetSendto, sent from the main thread. AsceNetBindon that socket then fails withEINVAL.CheckUnboundDatagramShutdown:sceNetRecvfromon an unbound socket returns 0 within a second ofsceNetShutdown(socket, SHUT_RD). After that,sceNetRecvreturns 0, andsceNetRecvmsgreturns 0 with no address.sceNetRecvfromwith an address buffer returns 0 with size 0. A zero-bytesceNetRecvandsceNetRecvfromon a new unbound socket return 0 at once.CheckUnboundDatagramLaterAddress: a thread waits insceNetRecvon an unbound socket while the main thread binds it, or connects it to a peer. In both cases the peer's datagram to the new address reaches the waiting receive.CheckUnboundDatagramTimeoutAfterAddress: with a 500 ms receive timeout, another thread binds the unbound socket 300 ms intosceNetRecvand nothing is sent. The receive fails withEAGAINafter 450-750 ms.Results:
mainata453108cf(run):main'sExport.cppthe test aborts on Windows. On Linux it passes, since Linux waits as FreeBSD does;Export.cppand the new tests, Windows aborts: the waiting receive doesn't return after the shutdown;guest_sce_netpasses 20 runs in a row on Windows and Linux. On Linux it also passes with commit 3's code, since Linux returns 0 after the shutdown, as FreeBSD does.Export.cpp, the new case aborts on Windows: that code waits the whole 500 ms timeout again after the 300 ms wait;guest_sce_netpasses 20 runs in a row on Windows and Linux. Linux passes either way, since its receive timeout runs from the start of the call.core/libs/prx/libcandcore/libs/prx/libkernelpasses: 71 and 136 on Linux, 93 and 140 on Windows.tools/check_conventions.pypasses for every commit.main8856f180ca: 1265 of 1265 tests pass, 473 skipped, all expected bycheck_skips.py(run). The workflow carried the runner-image CA-bundle fix (CI only, no source change).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, with Steam running on the same PC and Remote Play on:
mainata453108cf, once withmain'sExport.cppand once with the first commit's; nothing pressed, so Steam got no stream request.main: the title stays on "LOOKING FOR A PC RUNNING STEAM" for the whole 75 s run, with nodiscoveredline.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 github-actions[bot] on 2026-10-15T09:26:47Z.
Some 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:05:52Z.
Checked the diff,
guest_sce_netand the libSceNet/libs scope on Linux (37/37). The wait is Windows-only, so the Windows behaviour rests on the full Build's windows job and your run. The locking inwait_for_local_addressand the bind/connect/send wake-ups look right; merging once that is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T21:35:57Z.
Re-checked against the current
main: it merges cleanly andguest_sce_netpasses on the merged tree. The wait is Windows-only, so the Windows behaviour rests on the full Build's windows job and your run; merging once that is green.