fix(libSceNet): report the receive queue length in sceNetGetSockInfo #9932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9932"
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 ntamas94 on 2026-10-22T22:28:51Z.
What
sceNetGetSockInfoalways reported 0 inrecv_queue_length(offset 0x2c). A title that polls the record and reads only when the queue is not empty never reads. Knowledge is Power: Decades (CUSA12435) polls it on its PlayLink server socket; that socket comes fromsocket(), which libSceNet does not see onmainyet (it answersEBADF), so the title also needs that separate change. The record now carries the host'sFIONREADcount for the socket, read where the other fields are filled; a socket where the host refusesFIONREAD(a listening socket on Linux) keeps 0.A PS4 Pro on firmware 10.71 reports 0 for an empty queue, as before. A filled queue is not measured on a console, and on a datagram socket the hosts differ (Linux counts the first datagram, Windows every queued byte); both are recorded in
docs/dev/debt/libSceNet.mdtogether with the other measured values of that record (n0, pid, priority, state, and that a socket made withsocket()is listed).guest_sce_netgains rows that queue bytes on a connected TCP pair, wait for the receiver's record to report them and check that a receive empties it.Tested
Windows 11, MinGW-w64 GCC (winlibs), Ninja:
guest_sce_netpassed on the final head (1aa5b30),python tools/check_conventions.py --base origin/mainpasses. The empty-queue value and the record layout were measured on a PS4 Pro (firmware 10.71) with a homebrew probe on a bound UDP socket fromsceNetSocketand one fromsocket(); both records readrecv_queue_length0. Not run with a title.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 harisibrar1 on 2026-10-23T03:19:04Z.
Review: COMMENTED
Checked against main
3875f8c8ffand FreeBSD releng/11.4 (sys/kern/sys_socket.c,sys/kern/uipc_sockbuf.c):recv_queue_lengthis at 0x2C in main'sNetSockInfo, matching the test, and for TCP the FIONREAD count matches FreeBSD'ssbavail(&so->so_rcv). The ordering with #9930/#9931/#9948 is already covered above.sbappendaddr_locked_internalqueues a 16-byteMT_SONAMEmbuf in front of each datagram, andsballocadds it tosb_acc. So FIONREAD there is the sum over all queued datagrams of payload + 16 (e.g. 22 for one 6-byte datagram). If the console's record comes fromso_rcv, which is unmeasured, it would match neither Linux nor Windows. Worth one sentence in the debt entry next to the Linux/Windows note.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T04:42:28Z.
Review: COMMENTED
A third host for the datagram note in the debt entry: macOS's
FIONREADon a UDP socket counts neither the first datagram (Linux) nor only payload bytes (Windows). It also counts per-datagram overhead, close to what @harisibrar1 read from FreeBSD'ssbappendaddrpath. I measured it on M2 Max, macOS 27.2, x86-64 under Rosetta and native arm64, with the same results: a bound 127.0.0.1 UDP socket, datagrams sent withsendto, thenioctl(FIONREAD).The first datagram adds 16 bytes (its source address, 6 → 22). Each later one adds 32. A zero-length datagram still counts (32), so the Linux zero-length case Haris mentions doesn't apply on macOS. TCP isn't affected: on a loopback TCP pair, two 7-byte sends read 14, which is what this PR's new rows check.
SO_NREAD(macOS-only) gives the first datagram's payload, like Linux. When the port lands, the#elsebranch would report these inflated totals for datagram sockets. Worth one more host in that sentence, orSO_NREADunder__APPLE__if the Linux semantics are the intended ones.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.