feat(libkernel): apply SO_RCVTIMEO and SO_SNDTIMEO on a guest socket #5617
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5617"
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 Dripl1x on 2026-10-14T01:15:36Z.
What
The first commit of this branch is #5565 as ported to
main(7e79f36ed), unchanged. This PR is the second commit. It adds two options to the same structure: the handling is inSocket/src/SocketOptions.cpp, and the values are inSocketOptionStateundermodeMutex.setsockoptandgetsockopton a socket fromsocket()failSO_SNDTIMEO(0x1005) andSO_RCVTIMEO(0x1006) withENOPROTOOPT, and a blocking receive never times out. Now:sosetoptdoes. It is a 16-bytetimeval; a negative field or 1000000 microseconds or more fails withEDOM, and more thanINT32_MAXseconds becomes the longest wait. It is stored inSocketOptionState::sendTimeoutandreceiveTimeoutand read back through the same 32.32 fixed-point conversion (tvtosbt,sbttotv), so half a second reads back as 499999 microseconds and one microsecond as 0. A short or null value fails withEINVAL, as for the other options there.send,recv,sendto,recvfromandrecvmsgon a blocking socket wait that long for the host to report the socket readable or writable, then fail withEWOULDBLOCK. The wait reads the timeout and the non-blocking flag together undermodeMutex. A call withMSG_DONTWAIT, whichmainnow accepts on Linux, does not wait, as FreeBSD'ssoreceiveandsosenddo not sleep for it. The other calls reach these five:readandreadvgo throughrecv,writeandwritevthroughsend, andsendmsgthroughsendto. A non-blocking socket and a timeout of 0 behave as before.sonewconncopies them, in the same locked block that copies the other options.SocketOptions.cppentry ofdocs/dev/debt/libkernel.md:sendfileignores the send timeout.Titles that ask for them:
main90d0cb481, not part of this PR, showssetsockopt(SOL_SOCKET, SO_RCVTIMEO)andSO_SNDTIMEOwith 2 s failing withENOPROTOOPT(42). It happens three times while the title checks for a local FTP server. The title does not stop there: each check ends after about 2 s withno answer.mainboth calls fail, and the sockets wait without a limit. This is read from their sources; neither title was run.SO_RCVTIMEOis set by 27 titles andSO_SNDTIMEOby 24, and each is read by 19. The option was recovered at 840 of 2661setsockoptcall sites, so these are lower bounds. The lists and the method are in this comment.No title is known to stop on these options on
main.Related: #5565 is the first commit of this branch and the base of this change. Once it lands, this PR is rebased to carry only its own commit.
Tested
Windows 11, Ryzen 7 5800H, WinLibs MinGW-w64 GCC 15.2.0 r7; Ubuntu 26.04 under WSL, GCC 15.2.0. Release,
BUILD_TESTING=ON, root configuration withFFMPEG_PREBUILT_DIRpointed at an already unpacked package. Head17ded56f1, on #55657e79f36ed, onmain4c1de0c0c.guest_socket_timeoutscovers values and read-back with FreeBSD's rounding,EDOM, short arguments and a truncated read. It checksEWOULDBLOCKfromrecv,recvfrom,recvmsgandreadon a datagram socket and fromrecvon a stream socket. On Linux it checks thatrecv,recvfromandrecvmsgwithMSG_DONTWAITfail withEWOULDBLOCKat once under a 60 s timeout; without the check for the flag the test runs into its 20 s limit. It also covers a datagram received while the timeout is set, inheritance by an accepted socket, and a streamsendthat stops withEWOULDBLOCKonce the peer's buffers are full. Its only clock check is a lower bound: a 60 ms wait does not end before 59 ms.SocketOptions.hpp,SocketOptions.cppandUdp.cppof the first commit and the new test,guest_socket_timeoutsfails on both systems withsocket timeout check failed at line 93, errno 42.guest_udptimes out after 20 s, and does so onmaintoo: a VPN on this machine drops IPv6 loopback traffic, so a datagram to[::1]never arrives, even between two plain host sockets.guest_udpincluded.git diff --checkpass.Not tested: any title, a console, macOS, the full test suite. Full PR builds need a collaborator's manual Build run.
Checklist
mainthrough #5565, the first commit of this branch; no other open PR implements these two options.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T01:15:38Z.
Evidence for head
8b4309fbf. Local paths are replaced with<build>.Which catalog titles ask for the two options
setsockopt(SOL_SOCKET, SO_RCVTIMEO)setsockopt(SOL_SOCKET, SO_SNDTIMEO)getsockopt(SOL_SOCKET, SO_RCVTIMEO)getsockopt(SOL_SOCKET, SO_SNDTIMEO)Method: as in #5565. The 65 release archives listed in the catalog were downloaded (SHA-256 equal to the catalog records) and the 63
eboot.binunwrapped; nothing was run. The level and option were read from the instructions before each call site and recovered at 840 of 2661setsockoptcall sites, so the counts are lower bounds.Tests
Windows: guest_socket_timeouts, 20 repeated runs
Windows: the ten socket tests (guest_udp times out on this machine on main too)
Windows control: Udp.cpp of the first commit, new test
Linux: the eleven socket tests
Linux control: Udp.cpp of the first commit, new test
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T14:16:19Z.
Review: CHANGES_REQUESTED
This is stacked on #5565, which still needs to be ported to main: #4796 is merged, so
setsockopt/getsockoptnow delegate toGuestSockets::SetSocketLevelOption/GetSocketLevelOptioninSocket/src/SocketOptions.cpp, with per-socket state inSocket::optionsundermodeMutex. The branch conflicts withmaininUdp.cppfor that reason.Udp.cppOwnOption/SetOwnOption/GetOwnOptionis a second dispatcher in front of that code. Please putSO_SNDTIMEO/SO_RCVTIMEOintoSocketOptions.cppand keep the timeouts inSocketOptionStaterather than two separate atomics onSocket.WaitForTransfercalls insend/recv/sendto/recvfrom/recvmsg(andread/write/sendmsgas the description says; I only see the five in the diff, please check the others go through them).Happy to re-review once it is rebased on the ported base.
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T15:39:59Z.
@adriadam10 done. The branch is now the ported #5565 (
1e4783573) plus this PR's own commit,514d0033e:SO_SNDTIMEOandSO_RCVTIMEOare handled inSetSocketLevelOptionandGetSocketLevelOptioninSocketOptions.cpp. The values areSocketOptionState::sendTimeoutandreceiveTimeout. The two atomics onSocketand the dispatcher inUdp.cppare gone.WaitForTransferreads the timeout and the non-blocking flag together undermodeMutex, then waits without holding it.acceptcopies both timeouts in the locked block that copies the other options.read,writeandsendmsgdo go through the five calls with the wait.GuestSockets::ReadandReadvcallrecv_nid_postfix,WriteandWritevcallsend_nid_postfix, andsendmsg_nid_postfixcallssendto_nid_postfix. The test coversreaddirectly; the description now says which call each one goes through.main. The one I saw call them at run time is PokeMMO Prospero (PPSA98001). A temporary trace onmain90d0cb481showsSO_RCVTIMEOandSO_SNDTIMEOwith 2 s failing withENOPROTOOPTthree times during its local FTP check. Each check still ends after about 2 s withno answer, so nothing visible changes there. RommPS and SwanStationPS5 remain read from their sources. The description says so.Results at
514d0033e:guest_socket_timeoutspasses 20 of 20 repeated runs, and 12 of the 13 socket tests pass.guest_udptimes out onmaintoo, because the VPN on this machine drops IPv6 loopback traffic.1e4783573,guest_socket_timeoutsfails on both systems atline 92, errno 42.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dripl1x on 2026-10-14T19:33:59Z.
Rebased both branches onto
main4c1de0c0cafter #5020 and #4676 landed.7e79f36ed. The only conflict was #5020'sF_GETFD/F_SETFDlines next toF_GETFL; the latter reads the flag fromSocketOptionState. #5565 no longer declares a dependency.17ded56f1, with one change in substance. #4676 madesend/recv/sendto/recvfrom/recvmsgacceptMSG_DONTWAITon Linux.WaitForTransfernow takes the call's flags and does not wait whenMSG_DONTWAITis set, as FreeBSD'ssoreceiveandsosenddo not sleep for it. Before this, a blocking socket with a receive timeout waited out the timeout before the non-blocking host call.guest_socket_timeoutschecks the three receive calls withMSG_DONTWAITunder a 60 s timeout on Linux. Without the check for the flag, the test runs into its 20 s limit.Results: Linux, all 13 socket tests pass on this head and all 12 on #5565's. Windows, 12 of 13 and 11 of 12 (
guest_udponly, the VPN on this machine).guest_socket_timeouts,guest_socket_stream_optionsandguest_socket_optionspass 20 repeated runs on Windows. The controls still fail:guest_socket_timeoutsagainst #5565's code atline 93, errno 42, and the option tests againstmain's code atline 91, errno 42.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:08:16Z.
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/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:18:58Z.
Review: APPROVED
Re-checked against the points of the previous review: the timeouts now live in
SocketOptions.cppwith the values inSocketOptionStateundermodeMutex, the branch is one commit on currentmain, andread/readvgo throughrecv,write/writevthroughsend,sendmsgthroughsendto. Built and ran the libs/libkernel ctest scope (174 tests, all pass),guest_socket_timeoutsincluded, and it fails with the non-test changes reverted. Merging once the Windows build is green.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T14:13:17Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), MinGW GCC 15.2, PR head
17ded56f1merged on mainb08db6a09:#5565 is already on
main(1036905b5), so the merge adds only this PR's commit. Catalog releases,app0/eboot.binstaged,relinker --windows --registry unused-filter=0, display on, 90 s per run. The host was busy with other builds, so frame counts follow load. To see the calls I wrapped libkernelsetsockopt/getsockoptin a local stderr trace (not part of the PR).RommPS (PPSA76677)
main(run, traced run):RommPS | FPS: 59.46 (4794),RommPS | FPS: 46.13 (4677).RommPS | FPS: 49.26 (3675),RommPS | FPS: 55.76 (4277).setsockoptcall at all:http_requestonly runs when the title talks to RomM Sync.SwanStationPS5 (PPSA98510)
main:SwanStationPS5 | FPS: 33.23 (3316),FPS: 65.75 (7143).FPS: 116.35 (8461),FPS: 36.17 (4232).setsockoptcall.request_over_tcponly runs when/datais not listable; here the log hasstorage probe before unlock: sandboxed read no, write no, list okandstorage: unlocked.Other titles
TCP_NODELAY,SO_NOSIGPIPEand0x1200(all= 0), but never0x1005or0x1006.FPS: 46.19 (4531), VITA5FPS: 59.68 (3570), ProsperoStoreFPS: 12.43 (1106).Tests
guest_socket_timeouts,guest_socket_optionsandguest_socket_stream_optionspass 3/3 (--repeat until-fail:3).SocketOptions.hpp,SocketOptions.cppandUdp.cppfromb08db6a09, new test kept):socket timeout check failed at line 93, errno 42.Suite.
ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 825 tests, 16 failed under host load. 14 of the 16 pass when rerun serially.prx_thread_local_destructorsreports the libSceAgcDrivertraceDrawKeyLookupthread_local, which #6349 fixes afterb08db6a09.hardware_oracle_comparehits its 20 s limit under load.Conventions.
tools/check_conventions.pywith title and description passes.git diff --checkis clean.Review. The checks and conversions match the pinned FreeBSD 11.4 sources:
EDOMandSBT_MAXfromsosetopt,tvtosbt/sbttotvexactly (hence 499999 µs, and(0x7fffffff, 999999)forSBT_MAX),sogetoptread-back, andsonewconncopying both timeouts. The known limits are in the debt entry.One difference on Windows. On a TCP socket that was never connected, FreeBSD's
sosend_genericandsoreceive_genericreturnENOTCONNbefore any wait (uipc_socket.cL1271-1291 and L1567-1573). Without a timeout this PR does too:sendgives errno 57 at once. With a 300 msSO_SNDTIMEO/SO_RCVTIMEO,sendandrecvwait the full 300 ms and fail withEWOULDBLOCK(35). I measured this with a temporary probe appended to the test:send no timeout=-1 errno 57 (0 ms); send 300 ms timeout=-1 errno 35 (301 ms); recv 300 ms timeout=-1 errno 35 (300 ms). The cause is thatWSAPollreports nothing on an unconnected TCP socket until the timeout; a host probe got0andrevents 0after 2 s for bothPOLLWRNORMandPOLLRDNORM. Skipping the wait when the stream socket is not connected (for example whengetpeernamegivesWSAENOTCONN) would let the host call reportENOTCONN. Otherwise it could go into the debt entry. I did not check Linux.Written with Claude Code assistance.