fix(net): implement SO_ERROR for connection completion #2182

Closed
RockYou-cmd wants to merge 1 commit from upstream-pr/2182 into main
RockYou-cmd commented 2026-10-09 10:48:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by RockYou-cmd on 2026-10-09T10:48:59Z.


What

sceNetGetsockopt rejects SO_ERROR, so a caller waiting for a nonblocking connection cannot query its completion result. Implement guest SO_ERROR (0x1007), translate the host socket error to guest errno, return the output size, and preserve thread errno on successful queries.

On Windows 10 build 19045.7417, Winsock returns WSAECONNREFUSED repeatedly after a failed asynchronous connection. Track the consumed completion error per native socket, serialize connect/error queries, and reset it when another connection attempt starts. Successful connections stop this tracking once getpeername confirms a peer. Established-socket and UDP errors continue to use host behaviour.

The regression covers successful and refused loopback connections, invalid query arguments, output bounds, errno preservation, receive EAGAIN, and Windows same-socket retries with concurrent readers. The pending-connect errno mapping is already provided by merged #1448 and is not reintroduced here. FreeBSD-derived guest behaviour and unverified console semantics are recorded in TechnicalDebt.

Overlap review: 456 open PR titles/bodies checked, with diffs inspected for the open libSceNet changes. #1786 extends the same host-error mapping and #1588 changes the global synchronization used by the same exports; neither implements SO_ERROR. Resolver and pool-statistics changes have since merged and are preserved in the final rebase. No dependency on an unmerged PR.

Tested

Candidate Windows validation and final rebase:

  • macOS arm64, isolated native-ABI diagnostic: current unmodified source fails the SO_ERROR query with guest EOPNOTSUPP (45); candidate passes successful connection, asynchronous refusal and read-and-clear checks. The diagnostic supplies an isolated poller-registration hook and is not a supported-platform integration build.
  • Windows 10 build 19045.7417, WinLibs GCC 15.2.0 r7, normal CMake/Ninja Release build on f145139676a48306681d3a4d5fabf83938759daf: both networking targets compiled and guest_sce_net plus guest_sce_net_connect each passed three CTest repetitions (six executions, 0 failures, 12.85 seconds). This uses the project guest ABI.
  • Final rebase onto 51f69aa2182f28ef3b91cdc20e57431d065e3e65 preserves the same SO_ERROR implementation and tests, incorporates upstream resolver/pool-statistics changes, and resolves the TechnicalDebt conflict while retaining upstream entries. The macOS isolated loopback regression passed after this rebase. Windows/Linux integration on this final base remains pending maintainer-triggered CI; the earlier Windows run is not presented as a final-head result. Upstream Build run 37919912528 is action_required with no jobs started. The conventions check passed.
  • Linux and PS5 title/hardware execution: not performed.
  • Final author commit: b7a6823f. Diff and repository conventions checks passed.

Earlier Windows validation on df16c4c256be3c44e03eb9149a6ce5f8e8a038b2, before narrowing the patch for current main:

  • Windows 10 build 19045.7417, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 6800 XT. Normal build and library build completed. Existing guest_sce_net and new guest_sce_net_connect passed three repetitions, including Windows refusal clearing, concurrent readers and successful same-socket retry.
  • Full CTest: 402/405 passed in 240.38 seconds. agc_driver_sdwa_float_selectors, agc_driver_sdwa_ldexp_f16, and guest_system_font failed. Temporarily removing the patch and rebuilding reproduced all three failures on the same upstream revision and machine. The two graphics mismatch values were identical; the font test ended at the same point in its output. Restoring the patch and rebuilding made both networking tests pass again.
  • These full-suite results belong to the earlier revision; they are not a claim of full-suite validation on the rebased candidate. No game compatibility improvement is claimed.

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 in TechnicalDebt
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799389531 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2182). Originally posted by [RockYou-cmd](https://github.com/RockYou-cmd) on 2026-10-09T10:48:59Z. --- ### What `sceNetGetsockopt` rejects SO_ERROR, so a caller waiting for a nonblocking connection cannot query its completion result. Implement guest SO_ERROR (0x1007), translate the host socket error to guest errno, return the output size, and preserve thread errno on successful queries. On Windows 10 build 19045.7417, Winsock returns WSAECONNREFUSED repeatedly after a failed asynchronous connection. Track the consumed completion error per native socket, serialize connect/error queries, and reset it when another connection attempt starts. Successful connections stop this tracking once getpeername confirms a peer. Established-socket and UDP errors continue to use host behaviour. The regression covers successful and refused loopback connections, invalid query arguments, output bounds, errno preservation, receive EAGAIN, and Windows same-socket retries with concurrent readers. The pending-connect errno mapping is already provided by merged #1448 and is not reintroduced here. FreeBSD-derived guest behaviour and unverified console semantics are recorded in TechnicalDebt. Overlap review: 456 open PR titles/bodies checked, with diffs inspected for the open libSceNet changes. #1786 extends the same host-error mapping and #1588 changes the global synchronization used by the same exports; neither implements SO_ERROR. Resolver and pool-statistics changes have since merged and are preserved in the final rebase. No dependency on an unmerged PR. ### Tested Candidate Windows validation and final rebase: - macOS arm64, isolated native-ABI diagnostic: current unmodified source fails the SO_ERROR query with guest EOPNOTSUPP (45); candidate passes successful connection, asynchronous refusal and read-and-clear checks. The diagnostic supplies an isolated poller-registration hook and is not a supported-platform integration build. - Windows 10 build 19045.7417, WinLibs GCC 15.2.0 r7, normal CMake/Ninja Release build on `f145139676a48306681d3a4d5fabf83938759daf`: both networking targets compiled and `guest_sce_net` plus `guest_sce_net_connect` each passed three CTest repetitions (six executions, 0 failures, 12.85 seconds). This uses the project guest ABI. - Final rebase onto `51f69aa2182f28ef3b91cdc20e57431d065e3e65` preserves the same SO_ERROR implementation and tests, incorporates upstream resolver/pool-statistics changes, and resolves the TechnicalDebt conflict while retaining upstream entries. The macOS isolated loopback regression passed after this rebase. Windows/Linux integration on this final base remains pending maintainer-triggered CI; the earlier Windows run is not presented as a final-head result. Upstream Build run 37919912528 is action_required with no jobs started. The conventions check passed. - Linux and PS5 title/hardware execution: not performed. - Final author commit: `b7a6823f`. Diff and repository conventions checks passed. Earlier Windows validation on `df16c4c256be3c44e03eb9149a6ce5f8e8a038b2`, before narrowing the patch for current main: - Windows 10 build 19045.7417, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 6800 XT. Normal build and library build completed. Existing `guest_sce_net` and new `guest_sce_net_connect` passed three repetitions, including Windows refusal clearing, concurrent readers and successful same-socket retry. - Full CTest: 402/405 passed in 240.38 seconds. `agc_driver_sdwa_float_selectors`, `agc_driver_sdwa_ldexp_f16`, and `guest_system_font` failed. Temporarily removing the patch and rebuilding reproduced all three failures on the same upstream revision and machine. The two graphics mismatch values were identical; the font test ended at the same point in its output. Restoring the patch and rebuilding made both networking tests pass again. - These full-suite results belong to the earlier revision; they are not a claim of full-suite validation on the rebased candidate. No game compatibility improvement is claimed. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 11:28:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T11:28:30Z.


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
#2142 docs/dev/TechnicalDebt.md L367
#2161 docs/dev/TechnicalDebt.md L367
#2281 docs/dev/TechnicalDebt.md L367
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079958104 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2182#issuecomment-6079958104). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T11:28:30Z. --- <!-- 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 | |---|---|---|---| | #2142 | `docs/dev/TechnicalDebt.md` [L367](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/docs/dev/TechnicalDebt.md#L367) | | | | #2161 | `docs/dev/TechnicalDebt.md` [L367](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/docs/dev/TechnicalDebt.md#L367) | | | | #2281 | `docs/dev/TechnicalDebt.md` [L367](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/docs/dev/TechnicalDebt.md#L367) | | |
oneandonlydean commented 2026-10-09 20:09:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:09:43Z.


Closing: no title is shown querying SO_ERROR through sceNetGetsockopt on main, and the Winsock error tracking is a lot to carry without one. If a title needs it, please reopen.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088437983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2182#issuecomment-6088437983). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:09:43Z. --- Closing: no title is shown querying `SO_ERROR` through `sceNetGetsockopt` on main, and the Winsock error tracking is a lot to carry without one. If a title needs it, please reopen.

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