fix(libSceNet): report SO_ERROR from sceNetGetsockopt #4988

Merged
babyhuey merged 1 commit from upstream-pr/4988 into main 2026-10-14 02:53:49 +00:00
babyhuey commented 2026-10-13 07:23:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T07:23:33Z.


What

sceNetGetsockopt(s, SOL_SOCKET, SO_ERROR) (0x1007) used to fail with EOPNOTSUPP. It now returns the socket's pending error as a libSceNet errno, and 0 when there is none, as FreeBSD 11's sogetopt does. The read clears it.

  • The value is the host socket's SO_ERROR, mapped with the same table native_error() already uses for errno / WSAGetLastError() (now net_error(code)), so a refused connect reports 61 (ECONNREFUSED).
  • Winsock does not clear the pending error when it is read. So on Windows the library reports a pending error once, and again only after a new sceNetConnect, as #4796 does for libkernel sockets. That difference is recorded in docs/dev/debt/libSceNet.md.

curl checks a non-blocking connect this way: it waits for OUT, then reads SO_ERROR. So a curl request over libSceNet sockets fails with curl 7 even after the TCP handshake succeeds.

Tested

On the PR head 0daf1d5b, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release:

  • guest_sce_net passes 5/5 (--repeat until-fail:5) on both. The new check reads 0 from a connected socket. It reads 61 from a refused non-blocking loopback connect, then 0 on the next read. It fails on main.
  • No warnings in Export.cpp or GuestSceNet.cpp.

ProsperoLichess (PPSA99009, catalog release) on Windows 11 (RTX 3080), default flags:

  • On main every request fails after about 5.2 s (curl 7: Failed to connect to lichess.org port 443 after 5203 ms). DNS and the TCP handshake work, but sceNetEpollWait polls OUT as 4 instead of SCE's 2, which is #4611.
  • With #4611 alone, it fails at once (curl 7 ... after 112 ms): the OUT wait returns and sceNetGetsockopt(SO_ERROR) fails with EOPNOTSUPP.
  • With #4611 and this PR (fork test/verify-soerr-stack2), it connects. The next stop is TLS: the title loads the console's CA list from /<sandbox>/common/cert/CA_LIST.cer, which AnyPS5 doesn't provide (curl 77).
  • This PR alone leaves the 5.2 s failure, since OUT is never delivered.

On Linux the headless catalog run stops at the DisplayWindow throw before any request.

check_conventions.py passes.

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: #4611 (ProsperoLichess reaches SO_ERROR only once OUT is delivered)
  • Unblocks: PPSA99009 #4982
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839829257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4988). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-13T07:23:33Z. --- ### What `sceNetGetsockopt(s, SOL_SOCKET, SO_ERROR)` (0x1007) used to fail with `EOPNOTSUPP`. It now returns the socket's pending error as a libSceNet errno, and 0 when there is none, as FreeBSD 11's [`sogetopt`](https://github.com/freebsd/freebsd-src/blob/release/11.0.0/sys/kern/uipc_socket.c#L2785-L2790) does. The read clears it. - The value is the host socket's `SO_ERROR`, mapped with the same table `native_error()` already uses for `errno` / `WSAGetLastError()` (now `net_error(code)`), so a refused connect reports 61 (`ECONNREFUSED`). - Winsock does not clear the pending error when it is read. So on Windows the library reports a pending error once, and again only after a new `sceNetConnect`, as #4796 does for libkernel sockets. That difference is recorded in `docs/dev/debt/libSceNet.md`. curl checks a non-blocking connect this way: it waits for OUT, then reads `SO_ERROR`. So a curl request over libSceNet sockets fails with `curl 7` even after the TCP handshake succeeds. ### Tested On the PR head 0daf1d5b, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release: - `guest_sce_net` passes 5/5 (`--repeat until-fail:5`) on both. The new check reads 0 from a connected socket. It reads 61 from a refused non-blocking loopback connect, then 0 on the next read. It fails on `main`. - No warnings in `Export.cpp` or `GuestSceNet.cpp`. ProsperoLichess (PPSA99009, catalog release) on Windows 11 (RTX 3080), default flags: - On `main` every request fails after about 5.2 s (`curl 7: Failed to connect to lichess.org port 443 after 5203 ms`). DNS and the TCP handshake work, but `sceNetEpollWait` polls OUT as 4 instead of SCE's 2, which is #4611. - With #4611 alone, it fails at once (`curl 7 ... after 112 ms`): the OUT wait returns and `sceNetGetsockopt(SO_ERROR)` fails with `EOPNOTSUPP`. - With #4611 and this PR (fork `test/verify-soerr-stack2`), it connects. The next stop is TLS: the title loads the console's CA list from `/<sandbox>/common/cert/CA_LIST.cer`, which AnyPS5 doesn't provide (`curl 77`). - This PR alone leaves the 5.2 s failure, since OUT is never delivered. On Linux the headless catalog run stops at the `DisplayWindow` throw before any request. `check_conventions.py` passes. ### 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: #4611 (ProsperoLichess reaches `SO_ERROR` only once OUT is delivered) - [x] Unblocks: PPSA99009 #4982 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-13 07:31:19 +00:00 (Migrated from github.com)

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


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
#4669 core/libs/tests/GuestSceNet.cpp L636
#4924 core/libs/tests/GuestSceNet.cpp L671
#4933 core/libs/tests/GuestSceNet.cpp L671
#5536 core/libs/prx/libSceNet/Export.cpp L246, L1004
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140608496 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4988#issuecomment-6140608496). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T07:31:19Z. --- <!-- 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 | |---|---|---|---| | #4669 | `core/libs/tests/GuestSceNet.cpp` [L636](https://github.com/boykopovar/AnyPS5/blob/0a56aaaf47c6e99633c710a524e7834eed4b450e/core/libs/tests/GuestSceNet.cpp#L636) | | | | #4924 | `core/libs/tests/GuestSceNet.cpp` [L671](https://github.com/boykopovar/AnyPS5/blob/0a56aaaf47c6e99633c710a524e7834eed4b450e/core/libs/tests/GuestSceNet.cpp#L671) | | | | #4933 | `core/libs/tests/GuestSceNet.cpp` [L671](https://github.com/boykopovar/AnyPS5/blob/0a56aaaf47c6e99633c710a524e7834eed4b450e/core/libs/tests/GuestSceNet.cpp#L671) | | | | #5536 | `core/libs/prx/libSceNet/Export.cpp` [L246](https://github.com/boykopovar/AnyPS5/blob/0a56aaaf47c6e99633c710a524e7834eed4b450e/core/libs/prx/libSceNet/Export.cpp#L246), [L1004](https://github.com/boykopovar/AnyPS5/blob/0a56aaaf47c6e99633c710a524e7834eed4b450e/core/libs/prx/libSceNet/Export.cpp#L1004) | | |
Sevthered commented 2026-10-13 21:54:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Sevthered on 2026-10-13T21:54:46Z.


A second title for this fix, on Windows: OpenNOW PS5 0.1 (PPSA99082, catalog release, unwrapped and relinked with --windows). Windows 11, RTX 3080 Ti (NVIDIA 616.56), WinLibs GCC 15.2.0 r7, Release.

It needs #4924 and #4933 first, to get past poll on a libSceNet socket. With those two on main 665ad7da7 every request ends the same way:

curl=7 os_errno=45 Failed to connect to login.nvidia.com port 443 after 29 ms: Could not connect to server

With this PR cherry-picked on top, no request fails in a 60 s run and the title goes on to its decoder qualification.

The ProsperoLichess result with this PR on Windows is in #4982: it connects, and with a PEM certificate list in place it goes online.

One note for whoever merges second: this PR and #4924 conflict in core/libs/tests/GuestSceNet.cpp, where each adds a call after CheckKernelTimeouts(); (CheckSocketError(); and CheckKernelStatusFlags();). Keeping both lines resolves it.

AI-assisted: yes (Claude Code); the runs are from my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156012742 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4988#issuecomment-6156012742). Originally posted by [Sevthered](https://github.com/Sevthered) on 2026-10-13T21:54:46Z. --- A second title for this fix, on Windows: OpenNOW PS5 0.1 (PPSA99082, catalog release, unwrapped and relinked with `--windows`). Windows 11, RTX 3080 Ti (NVIDIA 616.56), WinLibs GCC 15.2.0 r7, Release. It needs #4924 and #4933 first, to get past `poll` on a libSceNet socket. With those two on `main` `665ad7da7` every request ends the same way: ``` curl=7 os_errno=45 Failed to connect to login.nvidia.com port 443 after 29 ms: Could not connect to server ``` With this PR cherry-picked on top, no request fails in a 60 s run and the title goes on to its decoder qualification. The ProsperoLichess result with this PR on Windows is in #4982: it connects, and with a PEM certificate list in place it goes online. One note for whoever merges second: this PR and #4924 conflict in `core/libs/tests/GuestSceNet.cpp`, where each adds a call after `CheckKernelTimeouts();` (`CheckSocketError();` and `CheckKernelStatusFlags();`). Keeping both lines resolves it. AI-assisted: yes (Claude Code); the runs are from 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!4988
No description provided.