fix(libSceNet): report the receive queue length in sceNetGetSockInfo #9932

Merged
ntamas94 merged 8 commits from upstream-pr/9932 into main 2026-11-02 07:59:29 +00:00
ntamas94 commented 2026-10-22 22:28:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T22:28:51Z.


What

sceNetGetSockInfo always reported 0 in recv_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 from socket(), which libSceNet does not see on main yet (it answers EBADF), so the title also needs that separate change. The record now carries the host's FIONREAD count for the socket, read where the other fields are filled; a socket where the host refuses FIONREAD (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.md together with the other measured values of that record (n 0, pid, priority, state, and that a socket made with socket() is listed). guest_sce_net gains 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_net passed on the final head (1aa5b30), python tools/check_conventions.py --base origin/main passes. 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 from sceNetSocket and one from socket(); both records read recv_queue_length 0. Not run with a title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4974972142 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9932). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-22T22:28:51Z. --- ### What `sceNetGetSockInfo` always reported 0 in `recv_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 from `socket()`, which libSceNet does not see on `main` yet (it answers `EBADF`), so the title also needs that separate change. The record now carries the host's `FIONREAD` count for the socket, read where the other fields are filled; a socket where the host refuses `FIONREAD` (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.md` together with the other measured values of that record (`n` 0, pid, priority, state, and that a socket made with `socket()` is listed). `guest_sce_net` gains 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_net` passed on the final head (1aa5b30), `python tools/check_conventions.py --base origin/main` passes. 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 from `sceNetSocket` and one from `socket()`; both records read `recv_queue_length` 0. Not run with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
harisibrar1 commented 2026-10-23 03:19:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-23T03:19:04Z.

Review: COMMENTED


Checked against main 3875f8c8ff and FreeBSD releng/11.4 (sys/kern/sys_socket.c, sys/kern/uipc_sockbuf.c):

  • It still merges cleanly. recv_queue_length is at 0x2C in main's NetSockInfo, matching the test, and for TCP the FIONREAD count matches FreeBSD's sbavail(&so->so_rcv). The ordering with #9930/#9931/#9948 is already covered above.
  • On datagram sockets FreeBSD 11.4 counts more than either host: sbappendaddr_locked_internal queues a 16-byte MT_SONAME mbuf in front of each datagram, and sballoc adds it to sb_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 from so_rcv, which is unmeasured, it would match neither Linux nor Windows. Worth one sentence in the debt entry next to the Linux/Windows note.
  • A related edge case, from reading only (I couldn't run it): on Linux a queued zero-length UDP datagram makes FIONREAD 0, where FreeBSD would report 16. A title that reads only when the length is nonzero, as CUSA12435 is described to, would not drain it, nor anything queued after it. Not blocking; maybe worth noting in debt too.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623501527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9932#pullrequestreview-5623501527). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-23T03:19:04Z. **Review:** COMMENTED --- Checked against main 3875f8c8ff and FreeBSD releng/11.4 (`sys/kern/sys_socket.c`, `sys/kern/uipc_sockbuf.c`): - It still merges cleanly. `recv_queue_length` is at 0x2C in main's `NetSockInfo`, matching the test, and for TCP the FIONREAD count matches FreeBSD's `sbavail(&so->so_rcv)`. The ordering with #9930/#9931/#9948 is already covered above. - On datagram sockets FreeBSD 11.4 counts more than either host: `sbappendaddr_locked_internal` queues a 16-byte `MT_SONAME` mbuf in front of each datagram, and `sballoc` adds it to `sb_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 from `so_rcv`, which is unmeasured, it would match neither Linux nor Windows. Worth one sentence in the debt entry next to the Linux/Windows note. - A related edge case, from reading only (I couldn't run it): on Linux a queued zero-length UDP datagram makes FIONREAD 0, where FreeBSD would report 16. A title that reads only when the length is nonzero, as CUSA12435 is described to, would not drain it, nor anything queued after it. Not blocking; maybe worth noting in debt too. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
jotitadev commented 2026-10-23 04:42:28 +00:00 (Migrated from github.com)

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 FIONREAD on 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's sbappendaddr path. 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 with sendto, then ioctl(FIONREAD).

queued datagrams (payload bytes) FIONREAD SO_NREAD
none 0 0
6 22 6
6, 6 60 6
6, 6, 6 98 6
6, 6, 6, 10 140 6
6, 6, 6, 10, 100 272 6
6, 6, 6, 10, 100, 0 304 6

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 #else branch would report these inflated totals for datagram sockets. Worth one more host in that sentence, or SO_NREAD under __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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5623974533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9932#pullrequestreview-5623974533). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-23T04:42:28Z. **Review:** COMMENTED --- A third host for the datagram note in the debt entry: macOS's `FIONREAD` on 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's `sbappendaddr` path. 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 with `sendto`, then `ioctl(FIONREAD)`. | queued datagrams (payload bytes) | FIONREAD | SO_NREAD | |---|---|---| | none | 0 | 0 | | 6 | 22 | 6 | | 6, 6 | 60 | 6 | | 6, 6, 6 | 98 | 6 | | 6, 6, 6, 10 | 140 | 6 | | 6, 6, 6, 10, 100 | 272 | 6 | | 6, 6, 6, 10, 100, 0 | 304 | 6 | 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 `#else` branch would report these inflated totals for datagram sockets. Worth one more host in that sentence, or `SO_NREAD` under `__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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9932
No description provided.