fix(libSceNet): report a stream whose peer closed as readable on Windows #5376

Closed
EagleBearerYS wants to merge 0 commits from upstream-pr/5376 into main
EagleBearerYS commented 2026-10-13 18:20:07 +00:00 (Migrated from github.com)

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


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. sceNetEpollWait passed that on, so on Windows a socket whose peer had closed came back as SCE_NET_EPOLLHUP alone and never as readable. A loop that waits for SCE_NET_EPOLLIN to read the end of the stream never got it, while every wait returned at once.

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 sceNetEpollWait already reported it this way on Linux.

On Windows, a stream socket's POLLHUP without POLLERR now reports POLLRDNORM when reading was asked for. It keeps POLLHUP only after sceNetShutdown has shut the socket's own sending side, which libSceNet now records.

Unchanged:

  • A reset or refused connection (POLLHUP with POLLERR) keeps the flags WSAPoll reports.
  • sceNetSocketAbort shuts the host socket down without being recorded as a shutdown.
  • libkernel's poll reports its own stream sockets the same way on Windows. #4903 adds the shutdown state that fix needs, so it will follow once #4903 lands.
  • select already counts a hang-up as readable.

No title is claimed.

Tested

On GitHub's runners from my fork, on main at 18c438b10 (run):

  • 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.

The new CheckEpollClosedStream in guest_sce_net checks three states in order:

  • after the peer closes, sceNetEpollWait reports exactly SCE_NET_EPOLLIN;
  • once the end of the stream is read, it reports SCE_NET_EPOLLIN | SCE_NET_EPOLLOUT when both are asked for;
  • after sceNetShutdown of the sending side, it reports SCE_NET_EPOLLIN | SCE_NET_EPOLLHUP.

Results:

  • Windows: with main's Export.cpp the test aborts. With the change, guest_sce_net passes 20 runs in a row.
  • Linux: guest_sce_net passes with main's code and, 20 runs in a row, with the change.
  • On both, every test registered under core/libs/prx/libc and core/libs/prx/libkernel passes: 69 and 124 on Linux, 90 and 127 on Windows.
  • tools/check_conventions.py --base origin/main passes.
  • 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: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847580805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5376). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T18:20:07Z. --- ### 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. `sceNetEpollWait` passed that on, so on Windows a socket whose peer had closed came back as `SCE_NET_EPOLLHUP` alone and never as readable. A loop that waits for `SCE_NET_EPOLLIN` to read the end of the stream never got it, while every wait returned at once. 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 `sceNetEpollWait` already reported it this way on Linux. On Windows, a stream socket's `POLLHUP` without `POLLERR` now reports `POLLRDNORM` when reading was asked for. It keeps `POLLHUP` only after `sceNetShutdown` has shut the socket's own sending side, which libSceNet now records. Unchanged: - A reset or refused connection (`POLLHUP` with `POLLERR`) keeps the flags `WSAPoll` reports. - `sceNetSocketAbort` shuts the host socket down without being recorded as a shutdown. - libkernel's `poll` reports its own stream sockets the same way on Windows. #4903 adds the shutdown state that fix needs, so it will follow once #4903 lands. - `select` already counts a hang-up as readable. No title is claimed. ### Tested On GitHub's runners from my fork, on `main` at 18c438b10 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/38445030525)): - 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. The new `CheckEpollClosedStream` in `guest_sce_net` checks three states in order: - after the peer closes, `sceNetEpollWait` reports exactly `SCE_NET_EPOLLIN`; - once the end of the stream is read, it reports `SCE_NET_EPOLLIN | SCE_NET_EPOLLOUT` when both are asked for; - after `sceNetShutdown` of the sending side, it reports `SCE_NET_EPOLLIN | SCE_NET_EPOLLHUP`. Results: - Windows: with `main`'s `Export.cpp` the test aborts. With the change, `guest_sce_net` passes 20 runs in a row. - Linux: `guest_sce_net` passes with `main`'s code and, 20 runs in a row, with the change. - On both, every test registered under `core/libs/prx/libc` and `core/libs/prx/libkernel` passes: 69 and 124 on Linux, 90 and 127 on Windows. - `tools/check_conventions.py --base origin/main` passes. - 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: none - [x] Unblocks: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-14 02:27:59 +00:00 (Migrated from github.com)

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


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:6159530414 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5376#issuecomment-6159530414). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:27:59Z. --- 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!5376
No description provided.