fix(libkernel): report the accept queue length for a listening socket's read event #7140

Merged
AlexOfTheForest merged 2 commits from upstream-pr/7140 into main 2026-10-18 12:21:56 +00:00
AlexOfTheForest commented 2026-10-17 13:30:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-17T13:30:54Z.


What

A read event on a listening socket (kevent EVFILT_READ and sceKernelAddReadEvent) took its data from FIONREAD, which Linux refuses on a listening socket. So the event fired with data 0: "ready, zero connections". FreeBSD 11.4 attaches filt_solisten to a listening socket, which reports so_qlen, the completed connections waiting for accept.

GuestSockets::Ready now checks SO_ACCEPTCONN. On Linux it reads a TCP listener's accept backlog from TCP_INFO; for a listening socket, tcp_get_info puts the number of children ready for accept() in tcpi_unacked. Where the host has no call for the count (Windows, macOS, a listener that is not TCP), it reports 1, the lower bound the readiness already implies. The debt entry says so.

Two commits:

  • fix(libkernel): report the accept queue length for a listening socket's read event: the Udp.cpp change and the debt entry.
  • test(libkernel): check the queued connection count on a listening socket: in guest_socket_events, data is 1 after the first connect and, on Linux, 2 once a second client is waiting, before both are accepted.

Tested

Linux x86_64: guest_socket_events, guest_kqueue, guest_poll and guest_select passed 5 of 5 runs. With the fix reverted, guest_socket_events fails at the new check. tools/check_conventions.py --base upstream/main passes; the progress report is unchanged. Not run on Windows or macOS, where the value is the fallback 1.

Stacked on the socket write-space PR, since both change the data reported by GuestSockets::Ready and the same debt entry. Until that one merges, its two commits also show here.

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 (#7076 is merged; its commits are no longer part of this PR)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4900459940 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-17T13:30:54Z. --- ### What A read event on a listening socket (`kevent` `EVFILT_READ` and `sceKernelAddReadEvent`) took its `data` from `FIONREAD`, which Linux refuses on a listening socket. So the event fired with `data` 0: "ready, zero connections". FreeBSD 11.4 attaches [`filt_solisten`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L3384-L3392) to a listening socket, which reports `so_qlen`, the completed connections waiting for `accept`. `GuestSockets::Ready` now checks `SO_ACCEPTCONN`. On Linux it reads a TCP listener's accept backlog from `TCP_INFO`; for a listening socket, `tcp_get_info` puts the number of children ready for `accept()` in `tcpi_unacked`. Where the host has no call for the count (Windows, macOS, a listener that is not TCP), it reports 1, the lower bound the readiness already implies. The debt entry says so. Two commits: - `fix(libkernel): report the accept queue length for a listening socket's read event`: the `Udp.cpp` change and the debt entry. - `test(libkernel): check the queued connection count on a listening socket`: in `guest_socket_events`, `data` is 1 after the first connect and, on Linux, 2 once a second client is waiting, before both are accepted. ### Tested Linux x86_64: `guest_socket_events`, `guest_kqueue`, `guest_poll` and `guest_select` passed 5 of 5 runs. With the fix reverted, `guest_socket_events` fails at the new check. `tools/check_conventions.py --base upstream/main` passes; the progress report is unchanged. Not run on Windows or macOS, where the value is the fallback 1. Stacked on the socket write-space PR, since both change the data reported by `GuestSockets::Ready` and the same debt entry. Until that one merges, its two commits also show here. ### 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 (#7076 is merged; its commits are no longer part of this PR) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-17 13:46:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T13:46:29Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6542 docs/dev/debt/libkernel.md L127-128
PR 7299 docs/dev/debt/libkernel.md L127-128

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.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 5918 docs/dev/debt/libkernel.md
PR 5999 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestSocketEvents.cpp
PR 6222 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6510 docs/dev/debt/libkernel.md
PR 6534 docs/dev/debt/libkernel.md
PR 6908 docs/dev/debt/libkernel.md
PR 6977 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7088 core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/Socket/src/Udp.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234629054 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6234629054). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T13:46:29Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6542](https://www.github.com/boykopovar/AnyPS5/pull/6542) | `docs/dev/debt/libkernel.md` [L127-128](https://github.com/boykopovar/AnyPS5/blob/0d078f75d31935b3c6f9d0b2539475e2f14369d4/docs/dev/debt/libkernel.md#L127-L128) | | | | [PR 7299](https://www.github.com/boykopovar/AnyPS5/pull/7299) | `docs/dev/debt/libkernel.md` [L127-128](https://github.com/boykopovar/AnyPS5/blob/0d078f75d31935b3c6f9d0b2539475e2f14369d4/docs/dev/debt/libkernel.md#L127-L128) | | | 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. | Pull request | Shared files not compared | |---|---| | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5918](https://www.github.com/boykopovar/AnyPS5/pull/5918) | `docs/dev/debt/libkernel.md` | | [PR 5999](https://www.github.com/boykopovar/AnyPS5/pull/5999) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestSocketEvents.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6534](https://www.github.com/boykopovar/AnyPS5/pull/6534) | `docs/dev/debt/libkernel.md` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `core/libs/prx/libkernel/Socket/src/Udp.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/Socket/src/Udp.cpp` |
MarcZX10 commented 2026-10-17 14:05:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T14:05:48Z.


The checklist still has the literal Depends on: #<socket write-space PR number>. The first two commits in this branch are the same socket write-space change and test carried by open #7076, so please name #7076 there. That will also make the dependency clear to the intake/overlap checks.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234853678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6234853678). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T14:05:48Z. --- The checklist still has the literal `Depends on: #<socket write-space PR number>`. The first two commits in this branch are the same socket write-space change and test carried by open #7076, so please name `#7076` there. That will also make the dependency clear to the intake/overlap checks.
MarcZX10 commented 2026-10-17 14:08:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T14:08:21Z.


Follow-up: the latest conventions run confirms the blocker is exactly the dependency placeholder (Fill in the pull request template: fill Depends on with #N or none). The first two commits match the socket write-space implementation in #7076, so please replace the placeholder with #7076; that should clear this failure and accurately state the stack dependency.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234878723 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6234878723). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T14:08:21Z. --- Follow-up: the latest conventions run confirms the blocker is exactly the dependency placeholder (`Fill in the pull request template: fill Depends on with #N or none`). The first two commits match the socket write-space implementation in #7076, so please replace the placeholder with `#7076`; that should clear this failure and accurately state the stack dependency.
MarcZX10 commented 2026-10-17 23:29:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:29:45Z.


The latest conventions check fails on the dependency placeholder: Depends on: #<socket write-space PR number>. Could you replace it with the actual PR number, or none if the write-space commits included on this branch make it self-contained? The check is currently red for this field.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243083391 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6243083391). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T23:29:45Z. --- The latest conventions check fails on the dependency placeholder: `Depends on: #<socket write-space PR number>`. Could you replace it with the actual PR number, or `none` if the write-space commits included on this branch make it self-contained? The check is currently red for this field.
oneandonlydean commented 2026-10-18 11:51:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T11:51:58Z.


Thanks for the rebase onto #7076. One thing left before merge: the PR body still has the placeholder Depends on: #<socket write-space PR number>, and the conventions check is red on exactly that line. Could you change it to Depends on: #7076 (now merged), or none? Either one passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249581503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6249581503). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T11:51:58Z. --- Thanks for the rebase onto #7076. One thing left before merge: the PR body still has the placeholder `Depends on: #<socket write-space PR number>`, and the conventions check is red on exactly that line. Could you change it to `Depends on: #7076` (now merged), or `none`? Either one passes.
AlexOfTheForest commented 2026-10-18 12:02:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexOfTheForest on 2026-10-18T12:02:24Z.


Rebased onto current main: the two #7076 commits are gone now that it is merged, and "Depends on" is set to none. I also dropped my own SO_ACCEPTCONN helper in favour of the Listening(const Socket&) that main gained in the meantime, so the change is now only the accept-queue count. guest_socket_events, guest_kqueue, guest_poll and guest_select pass 5/5 on Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249675370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7140#issuecomment-6249675370). Originally posted by [AlexOfTheForest](https://github.com/AlexOfTheForest) on 2026-10-18T12:02:24Z. --- Rebased onto current main: the two #7076 commits are gone now that it is merged, and "Depends on" is set to none. I also dropped my own SO_ACCEPTCONN helper in favour of the `Listening(const Socket&)` that main gained in the meantime, so the change is now only the accept-queue count. guest_socket_events, guest_kqueue, guest_poll and guest_select pass 5/5 on Linux.
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!7140
No description provided.