fix(libSceNet): report EAGAIN when a datagram receive times out on Windows #4092

Merged
EagleBearerYS merged 1 commit from upstream-pr/4092 into main 2026-10-12 08:39:41 +00:00
EagleBearerYS commented 2026-10-11 23:05:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-11T23:05:24Z.


What

With SO_RCVTIMEO set, a receive on a datagram socket that waits that long fails on Windows with ETIMEDOUT (0x8041013C, errno 60): Winsock reports WSAETIMEDOUT and native_error maps it to 60. FreeBSD returns EWOULDBLOCK (35): sbwait sleeps with the socket buffer's sb_timeo, msleep_sbt returns EWOULDBLOCK when it expires, soreceive passes that on and kern_recvit keeps it when nothing was received (uipc_sockbuf.c, uipc_syscalls.c). Linux returns EAGAIN, and POSIX (XSH section 2.10.16, SO_RCVTIMEO) requires EAGAIN or EWOULDBLOCK when no data was received.

A datagram socket has no connection that can time out (an ICMP port unreachable arrives as WSAECONNRESET), so on such a socket WSAETIMEDOUT only means that the receive timeout the guest set has expired. sceNetRecv, sceNetRecvfrom and sceNetRecvmsg now report EAGAIN in that case, and only when the socket has a receive timeout.

Stream sockets and SO_SNDTIMEO keep ETIMEDOUT; the new TechnicalDebt entry records them. On a connection WSAETIMEDOUT can also be a real connection timeout, Winsock documents the connection as indeterminate after SO_RCVTIMEO or SO_SNDTIMEO expire (SOL_SOCKET options), and a timed-out send reports no partial count (a blocking loopback TCP send with a 50 ms SO_SNDTIMEO fails after 59 ms with no count). FreeBSD's behaviour there needs the timeout waited for without the host option, which is a separate change.

Windows, 50 ms SO_RCVTIMEO, nothing queued:

Call main This branch
UDP sceNetRecv, sceNetRecvfrom, sceNetRecvmsg 0x8041013C, errno 60 0x80410123, errno 35, as on Linux
TCP sceNetRecv 0x8041013C, errno 60 unchanged

Tested

Windows 11 (10.0.26300), MinGW-w64 GCC 15.2.0 (WinLibs r7, UCRT), Release, BUILD_TESTING=ON, on main at 325e0a8b with #4021 applied locally, since main's Windows build stops in Socket.cpp without it:

  • guest_sce_net: the new CheckReceiveTimeout sets a 50 ms receive timeout on the UDP receiver; sceNetRecv, sceNetRecvfrom and sceNetRecvmsg with nothing queued fail with EAGAIN, and a datagram sent afterwards is still received. Aborts on main at the first receive (0x8041013C), passes with the change; 20 more runs pass. The whole test takes 0.3 s.
  • All 128 tests registered in core/libs/prx/libc/CMakeLists.txt and core/libs/prx/libkernel/CMakeLists.txt that build on Windows pass, as do guest_resolver and guest_posix_filesystem (libScePosixForWebKit, which links libSceNet).
  • tools/check_conventions.py --base origin/main passes.
  • Linux not tested. The mapping is inside #ifdef _WIN32; Linux already returns EAGAIN for an expired SO_RCVTIMEO, which the new checks expect.

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 (none added)
  • 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:4823068080 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4092). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-11T23:05:24Z. --- ### What With `SO_RCVTIMEO` set, a receive on a datagram socket that waits that long fails on Windows with `ETIMEDOUT` (`0x8041013C`, errno 60): Winsock reports [`WSAETIMEDOUT`](https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2) and `native_error` maps it to 60. FreeBSD returns `EWOULDBLOCK` (35): `sbwait` sleeps with the socket buffer's `sb_timeo`, `msleep_sbt` returns `EWOULDBLOCK` when it expires, `soreceive` passes that on and `kern_recvit` keeps it when nothing was received ([uipc_sockbuf.c](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_sockbuf.c), [uipc_syscalls.c](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_syscalls.c)). Linux returns `EAGAIN`, and POSIX ([XSH section 2.10.16](https://pubs.opengroup.org/onlinepubs/9799919799/functions/V2_chap02.html), `SO_RCVTIMEO`) requires `EAGAIN` or `EWOULDBLOCK` when no data was received. A datagram socket has no connection that can time out (an ICMP port unreachable arrives as `WSAECONNRESET`), so on such a socket `WSAETIMEDOUT` only means that the receive timeout the guest set has expired. `sceNetRecv`, `sceNetRecvfrom` and `sceNetRecvmsg` now report `EAGAIN` in that case, and only when the socket has a receive timeout. Stream sockets and `SO_SNDTIMEO` keep `ETIMEDOUT`; the new TechnicalDebt entry records them. On a connection `WSAETIMEDOUT` can also be a real connection timeout, Winsock documents the connection as indeterminate after `SO_RCVTIMEO` or `SO_SNDTIMEO` expire ([SOL_SOCKET options](https://learn.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options)), and a timed-out send reports no partial count (a blocking loopback TCP send with a 50 ms `SO_SNDTIMEO` fails after 59 ms with no count). FreeBSD's behaviour there needs the timeout waited for without the host option, which is a separate change. Windows, 50 ms `SO_RCVTIMEO`, nothing queued: | Call | `main` | This branch | |---|---|---| | UDP `sceNetRecv`, `sceNetRecvfrom`, `sceNetRecvmsg` | `0x8041013C`, errno 60 | `0x80410123`, errno 35, as on Linux | | TCP `sceNetRecv` | `0x8041013C`, errno 60 | unchanged | ### Tested Windows 11 (10.0.26300), MinGW-w64 GCC 15.2.0 (WinLibs r7, UCRT), Release, `BUILD_TESTING=ON`, on `main` at 325e0a8b with #4021 applied locally, since `main`'s Windows build stops in `Socket.cpp` without it: - `guest_sce_net`: the new `CheckReceiveTimeout` sets a 50 ms receive timeout on the UDP receiver; `sceNetRecv`, `sceNetRecvfrom` and `sceNetRecvmsg` with nothing queued fail with `EAGAIN`, and a datagram sent afterwards is still received. Aborts on `main` at the first receive (`0x8041013C`), passes with the change; 20 more runs pass. The whole test takes 0.3 s. - All 128 tests registered in `core/libs/prx/libc/CMakeLists.txt` and `core/libs/prx/libkernel/CMakeLists.txt` that build on Windows pass, as do `guest_resolver` and `guest_posix_filesystem` (libScePosixForWebKit, which links libSceNet). - `tools/check_conventions.py --base origin/main` passes. - Linux not tested. The mapping is inside `#ifdef _WIN32`; Linux already returns `EAGAIN` for an expired `SO_RCVTIMEO`, which the new checks expect. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) (none added) - [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
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!4092
No description provided.