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

Closed
xXPBSXx wants to merge 4 commits from upstream-pr/12683 into main
xXPBSXx commented 2026-10-29 01:59:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-29T01:59:01Z.


What

Carries #9932 (ntamas94, head 641b92a91c; its three commits keep their authorship, the four merge commits of that branch are not carried), rebased onto current main. The maintainer asked on that PR to merge main, keep its socket-option wording and combine the sceNetGetSockInfo entries in docs/dev/debt/libSceNet.md; the author has not answered since 23 October, and the hand-off was offered there on 27 October.

sceNetGetSockInfo always reported 0 in recv_queue_length (offset 0x2c), so a title that polls the record and reads only when the queue is not empty never reads. The record now carries the host's FIONREAD count for the socket; a socket where the host refuses FIONREAD keeps 0. 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.

The only conflict was in docs/dev/debt/libSceNet.md. After the rebase the sceNetGetSockInfo entry of main keeps its wording except that "queue lengths" now reads "send queue length", and a new entry below it records the receive queue: the host count, the datagram-socket differences between hosts, and the author's PS4 Pro readings. Those readings are the author's report and were not measured here.

The read goes through the host's FIONREAD directly, so on macOS it does not follow the datagram counting that #10628 gave sceNetIoctl; that difference is not measured here and is left to a follow-up.

Tested

Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Ninja Release, BUILD_TESTING=ON, on main 3a2b919816 with this branch on top (ninja exit code 0), 3 runs each:

  • This branch: guest_sce_net passes in all three runs, and again in three runs after the changed files were restored.
  • Same main with libSceNet/Export.cpp reverted and the test kept: guest_sce_net aborts in all three runs (exit code 0xc0000409). A one-off build that printed the failing line showed it stops at the new check that the receive queue length equals the seven bytes queued (GuestSceNet.cpp, three runs); that build carried a temporary change to the test's Require and is not part of this branch.
  • python tools/check_conventions.py --base upstream/main passes, git diff --check is clean, and git merge-tree against current main is clean.
  • Not run here: Linux and macOS, the full suite, and any title. The PS4 Pro values come from #9932's description and are not re-measured.

Overlap

I took the changed files of each of the 1379 open pull requests from git diff --name-only against its merge base with main (3a2b919816; every ref was fetched): 20 of them, this one's source #9932 included, change at least one of libSceNet/Export.cpp, GuestSceNet.cpp and docs/dev/debt/libSceNet.md. git merge-tree of this branch with each of the other 19, each on the merge base git finds, reports a conflict for 6 (#5836, #9948, #11134, #11272, #11872, #11969). Four of those already conflict with main on their own, so this change adds no landing order for them. #9948 (by the same author, whose description says it depends on #9932) and #11272 (Queuse, "keep TCP option state") conflict only with this branch. #9948 follows this pull request and rebases onto it. For #11272, whichever lands second rebases and keeps both changes; which of the two lands first is open, and this pull request does not fix the order.

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: #9948
  • GPUs tested: n/a
  • AI-assisted: yes

Co-authored by the original author of #9932.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5060763045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12683). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-29T01:59:01Z. --- ### What Carries #9932 (ntamas94, head `641b92a91c`; its three commits keep their authorship, the four merge commits of that branch are not carried), rebased onto current `main`. The maintainer [asked](https://github.com/boykopovar/AnyPS5/pull/9932#issuecomment-6403424841) on that PR to merge `main`, keep its socket-option wording and combine the `sceNetGetSockInfo` entries in `docs/dev/debt/libSceNet.md`; the author has not answered since 23 October, and the hand-off was [offered](https://github.com/boykopovar/AnyPS5/pull/9932#issuecomment-6456040648) there on 27 October. `sceNetGetSockInfo` always reported 0 in `recv_queue_length` (offset 0x2c), so a title that polls the record and reads only when the queue is not empty never reads. The record now carries the host's `FIONREAD` count for the socket; a socket where the host refuses `FIONREAD` keeps 0. `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. The only conflict was in `docs/dev/debt/libSceNet.md`. After the rebase the `sceNetGetSockInfo` entry of `main` keeps its wording except that "queue lengths" now reads "send queue length", and a new entry below it records the receive queue: the host count, the datagram-socket differences between hosts, and the author's PS4 Pro readings. Those readings are the author's report and were not measured here. The read goes through the host's `FIONREAD` directly, so on macOS it does not follow the datagram counting that #10628 gave `sceNetIoctl`; that difference is not measured here and is left to a follow-up. ### Tested Windows 10 Pro (19045), WinLibs GCC 15.2.0 r7, Ninja Release, `BUILD_TESTING=ON`, on `main` `3a2b919816` with this branch on top (ninja exit code 0), 3 runs each: - This branch: `guest_sce_net` passes in all three runs, and again in three runs after the changed files were restored. - Same `main` with `libSceNet/Export.cpp` reverted and the test kept: `guest_sce_net` aborts in all three runs (exit code `0xc0000409`). A one-off build that printed the failing line showed it stops at the new check that the receive queue length equals the seven bytes queued (`GuestSceNet.cpp`, three runs); that build carried a temporary change to the test's `Require` and is not part of this branch. - `python tools/check_conventions.py --base upstream/main` passes, `git diff --check` is clean, and `git merge-tree` against current `main` is clean. - Not run here: Linux and macOS, the full suite, and any title. The PS4 Pro values come from #9932's description and are not re-measured. ### Overlap I took the changed files of each of the 1379 open pull requests from `git diff --name-only` against its merge base with `main` (`3a2b919816`; every ref was fetched): 20 of them, this one's source #9932 included, change at least one of `libSceNet/Export.cpp`, `GuestSceNet.cpp` and `docs/dev/debt/libSceNet.md`. `git merge-tree` of this branch with each of the other 19, each on the merge base git finds, reports a conflict for 6 (#5836, #9948, #11134, #11272, #11872, #11969). Four of those already conflict with `main` on their own, so this change adds no landing order for them. #9948 (by the same author, whose description says it depends on #9932) and #11272 (Queuse, "keep TCP option state") conflict only with this branch. #9948 follows this pull request and rebases onto it. For #11272, whichever lands second rebases and keeps both changes; which of the two lands first is open, and this pull request does not fix the order. ### Checklist - [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: #9948 - [x] GPUs tested: n/a - [x] AI-assisted: yes Co-authored by the original author of #9932. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
rooklz commented 2026-10-29 02:03:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T02:03:25Z.

Review: COMMENTED


Ran the host side on macOS and Linux, which the body lists as not run. I used a plain C probe of the same calls fill_sock_info now makes (ioctl(FIONREAD)), plus the SO_NREAD path that sceNetIoctl uses on macOS. I did not build guest_sce_net on either host.

Stream sockets (what the new test checks): matches on both hosts.

socket macOS 26.2 arm64 FIONREAD Ubuntu 24.04 x86_64 glibc 2.39 FIONREAD
accepted, empty 0 0
accepted, 7 bytes queued ("queued" + NUL) 7 7
accepted, 7 bytes + peer FIN 7 7
listener 0 fails EINVAL → record keeps 0

So the new rows should pass on macOS and Linux as well, and the Linux listener case goes through the "host refuses FIONREAD keeps 0" branch as the body describes. This matters because the PR's linux CI lane is skipped.

Datagram sockets: one correction to the new debt line, and the follow-up the body left open is now measured.

macOS, one bound UDP socket, loopback sends, FIONREAD after each step (SO_NREAD in brackets):

fresh socket : send 10 -> 26 [10]   send 30 -> 88 [10]   recv -> 62 [30]   recv -> 0
same socket  : send 10 -> 42        send 30 -> 104       recv -> 62        recv -> 0
             : send 0  -> 32        send 5  -> 69        recv -> 37        recv -> 0
             : send 1 x4 -> 33 66 99 132                 recv x4 -> 99 66 33 0

The debt line says "macOS adds 16 bytes for the first datagram and 32 for each later one". That only holds for the first datagram a socket ever receives. Once that socket's queue has drained, every datagram adds 32, including the first one queued afterwards (10 → 42, 0 → 32). Suggested wording: "macOS adds 16 bytes for the first datagram a socket receives and 32 for every other". Linux in the same sequence: 10, 10, 30, 0 and 0 → 0 for the empty-first case, which matches the line.

On macOS, sceNetIoctl(FIONREAD) (the #10628 SO_NREAD path) and this record now disagree on the same datagram socket: 10 vs 26, then 10 vs 88 in the first row above. On stream sockets they agree, since both use FIONREAD. The body leaves the macOS difference unmeasured, and the numbers above settle it. Neither host value is the PS4 Pro's payload+16 count, so I would not block on it. Two ways to close it: one shared pending bytes helper so the two exports can't drift apart, or a sentence in the new debt line saying the record and sceNetIoctl disagree on macOS datagrams.

No change requested to the code. The stream path is right on macOS and Linux here, and on Windows in your runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5691997126 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12683#pullrequestreview-5691997126). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-29T02:03:25Z. **Review:** COMMENTED --- Ran the host side on macOS and Linux, which the body lists as not run. I used a plain C probe of the same calls `fill_sock_info` now makes (`ioctl(FIONREAD)`), plus the `SO_NREAD` path that `sceNetIoctl` uses on macOS. I did not build `guest_sce_net` on either host. **Stream sockets (what the new test checks): matches on both hosts.** | socket | macOS 26.2 arm64 `FIONREAD` | Ubuntu 24.04 x86_64 glibc 2.39 `FIONREAD` | |---|---|---| | accepted, empty | 0 | 0 | | accepted, 7 bytes queued (`"queued"` + NUL) | 7 | 7 | | accepted, 7 bytes + peer FIN | 7 | 7 | | listener | 0 | **fails `EINVAL`** → record keeps 0 | So the new rows should pass on macOS and Linux as well, and the Linux listener case goes through the "host refuses `FIONREAD` keeps 0" branch as the body describes. This matters because the PR's `linux` CI lane is skipped. **Datagram sockets: one correction to the new debt line, and the follow-up the body left open is now measured.** macOS, one bound UDP socket, loopback sends, `FIONREAD` after each step (`SO_NREAD` in brackets): ``` fresh socket : send 10 -> 26 [10] send 30 -> 88 [10] recv -> 62 [30] recv -> 0 same socket : send 10 -> 42 send 30 -> 104 recv -> 62 recv -> 0 : send 0 -> 32 send 5 -> 69 recv -> 37 recv -> 0 : send 1 x4 -> 33 66 99 132 recv x4 -> 99 66 33 0 ``` The debt line says "macOS adds 16 bytes for the first datagram and 32 for each later one". That only holds for the first datagram a socket ever receives. Once that socket's queue has drained, every datagram adds 32, including the first one queued afterwards (10 → 42, 0 → 32). Suggested wording: "macOS adds 16 bytes for the first datagram a socket receives and 32 for every other". Linux in the same sequence: 10, 10, 30, 0 and 0 → 0 for the empty-first case, which matches the line. On macOS, `sceNetIoctl(FIONREAD)` (the #10628 `SO_NREAD` path) and this record now disagree on the same datagram socket: 10 vs 26, then 10 vs 88 in the first row above. On stream sockets they agree, since both use `FIONREAD`. The body leaves the macOS difference unmeasured, and the numbers above settle it. Neither host value is the PS4 Pro's payload+16 count, so I would not block on it. Two ways to close it: one shared `pending bytes` helper so the two exports can't drift apart, or a sentence in the new debt line saying the record and `sceNetIoctl` disagree on macOS datagrams. No change requested to the code. The stream path is right on macOS and Linux here, and on Windows in your runs.

Pull request closed

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!12683
No description provided.