fix(libkernel): report a stream whose peer closed as readable in poll on Windows #5403

Closed
EagleBearerYS wants to merge 3 commits from upstream-pr/5403 into main
EagleBearerYS commented 2026-10-13 18:56:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T18:56:37Z.


What

When the peer of a stream socket closes, Winsock's WSAPoll reports POLLHUP without POLLRDNORM, whether or not the socket's own sending side is shut down. poll passed that on, so on Windows a guest socket whose peer had closed came back as POLLHUP alone and never as POLLIN.

FreeBSD's sopoll_generic reports a socket that can receive no more as readable, and adds POLLHUP only once it can send no more either. Linux's poll does the same, so the Linux path already behaved this way.

On Windows, a stream socket's POLLHUP without POLLERR now reports POLLRDNORM when reading was asked for. It keeps POLLHUP only after shutdown has shut the socket's own sending side. #5376 makes the same change in sceNetEpollWait.

This depends on #4903, which records that state in Socket::sendShut. The branch contains #4903's commit (2cbec36e5); the changes here are the last two commits:

  • 0804937eb is the fix and its test;
  • ed2b2e5aa updates the socketpair note in docs/dev/debt/libkernel.md. Its stream ends are loopback TCP connections, so after the peer's shutdown(SHUT_WR) they now report POLLIN, as the console does. After the peer's close the console also reports POLLHUP, which the loopback connection cannot tell apart from a shutdown.

poll looks the socket up by descriptor, and only when it reports a hang-up without an error. So the change does not rely on poll's held list, which #4933 changes to cover libSceNet sockets. Under #4933, libSceNet sockets keep the flags WSAPoll reports.

Unchanged:

  • A reset or refused connection (POLLHUP with POLLERR) keeps WSAPoll's flags.
  • select already counts a hang-up as readable.

No title is claimed.

Tested

On GitHub's runners from my fork (run), comparing #4903's head (2cbec36e5) with this change on top:

  • Linux: Ubuntu 24.04.5, GCC 13.3.0, Release with CI's configure flags and -DANYPS5_ENABLE_SPIRV_TOOLS=ON.
  • Windows: Windows Server 2025, WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release with CI's configure flags.

guest_poll gains three checks:

  • after a client shuts its own sending side while the server stays open, a POLLIN poll of the client reports nothing;
  • after the client closes and the server reads the end of the stream, the server's socket reports exactly POLLIN | POLLOUT;
  • after the server shuts its sending side too, a POLLIN poll reports POLLIN | POLLHUP.

Results:

  • Windows: with #4903's Udp.cpp the test aborts. With the change, guest_poll passes 20 runs in a row, and every test registered under core/libs/prx/libc (87) and core/libs/prx/libkernel (124) passes, guest_socket_pair included.
  • Linux: guest_poll passes with #4903's code and, 20 runs in a row, with the change. The libkernel suite (121) passes. In libc (68), guest_math fails with and without the change on #4903's base (14036cb0e).
  • tools/check_conventions.py passes for the three commits.
  • Not tested: macOS, any 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: #4903
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4848012611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5403). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T18:56:37Z. --- ### What When the peer of a stream socket closes, Winsock's `WSAPoll` reports `POLLHUP` without `POLLRDNORM`, whether or not the socket's own sending side is shut down. `poll` passed that on, so on Windows a guest socket whose peer had closed came back as `POLLHUP` alone and never as `POLLIN`. FreeBSD's [`sopoll_generic`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_socket.c#L3080-L3086) reports a socket that can receive no more as readable, and adds `POLLHUP` only once it can send no more either. Linux's `poll` does the same, so the Linux path already behaved this way. On Windows, a stream socket's `POLLHUP` without `POLLERR` now reports `POLLRDNORM` when reading was asked for. It keeps `POLLHUP` only after `shutdown` has shut the socket's own sending side. #5376 makes the same change in `sceNetEpollWait`. This depends on #4903, which records that state in `Socket::sendShut`. The branch contains #4903's commit (2cbec36e5); the changes here are the last two commits: - 0804937eb is the fix and its test; - ed2b2e5aa updates the `socketpair` note in `docs/dev/debt/libkernel.md`. Its stream ends are loopback TCP connections, so after the peer's `shutdown(SHUT_WR)` they now report `POLLIN`, as the console does. After the peer's `close` the console also reports `POLLHUP`, which the loopback connection cannot tell apart from a shutdown. `poll` looks the socket up by descriptor, and only when it reports a hang-up without an error. So the change does not rely on `poll`'s `held` list, which #4933 changes to cover libSceNet sockets. Under #4933, libSceNet sockets keep the flags `WSAPoll` reports. Unchanged: - A reset or refused connection (`POLLHUP` with `POLLERR`) keeps `WSAPoll`'s flags. - `select` already counts a hang-up as readable. No title is claimed. ### Tested On GitHub's runners from my fork ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38449393228)), comparing #4903's head (2cbec36e5) with this change on top: - Linux: Ubuntu 24.04.5, GCC 13.3.0, Release with CI's configure flags and `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`. - Windows: Windows Server 2025, WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release with CI's configure flags. `guest_poll` gains three checks: - after a client shuts its own sending side while the server stays open, a `POLLIN` poll of the client reports nothing; - after the client closes and the server reads the end of the stream, the server's socket reports exactly `POLLIN | POLLOUT`; - after the server shuts its sending side too, a `POLLIN` poll reports `POLLIN | POLLHUP`. Results: - Windows: with #4903's `Udp.cpp` the test aborts. With the change, `guest_poll` passes 20 runs in a row, and every test registered under `core/libs/prx/libc` (87) and `core/libs/prx/libkernel` (124) passes, `guest_socket_pair` included. - Linux: `guest_poll` passes with #4903's code and, 20 runs in a row, with the change. The libkernel suite (121) passes. In libc (68), `guest_math` fails with and without the change on #4903's base (14036cb0e). - `tools/check_conventions.py` passes for the three commits. - Not tested: macOS, any 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: #4903 - [x] Unblocks: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 19:10:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:10:37Z.


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
#5510 docs/dev/debt/libkernel.md L148
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153143770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5403#issuecomment-6153143770). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T19:10:37Z. --- <!-- 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 | |---|---|---|---| | #5510 | `docs/dev/debt/libkernel.md` [L148](https://github.com/boykopovar/AnyPS5/blob/71c71f50b7a42ad1a62b78d9cd24f5a356965557/docs/dev/debt/libkernel.md#L148) | | |
oneandonlydean commented 2026-10-14 02:27:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:27:23Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159523420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5403#issuecomment-6159523420). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:27:23Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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