fix(libSceNet): accept MSG_DONTWAIT in the send and receive calls #4673

Merged
milescoviello merged 1 commit from upstream-pr/4673 into main 2026-10-14 06:06:14 +00:00
milescoviello commented 2026-10-12 18:31:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-12T18:31:39Z.


What

sceNetSend, sceNetSendto, sceNetRecv, sceNetRecvfrom, sceNetRecvmsg and sceNetSendmsg failed with EOPNOTSUPP for every flag other than MSG_PEEK on a receive, so a game that polls a socket with MSG_DONTWAIT (0x80) got an error on every call instead of its data or EWOULDBLOCK.

FreeBSD 11.4 defines the flag in sys/sys/socket.h:

#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */

and soreceive_generic() (sys/kern/uipc_socket.c) treats it as a non-blocking socket for that one call:

		if ((so->so_state & SS_NBIO) ||
		    (flags & (MSG_DONTWAIT|MSG_NBIO))) {
			SOCKBUF_UNLOCK(&so->so_rcv);
			error = EWOULDBLOCK;
			goto release;

shadPS4's sceNet uses the same value (ORBIS_NET_MSG_DONTWAIT = 0x00000080).

On Linux and macOS the flag now maps to the host's MSG_DONTWAIT, alone or with MSG_PEEK on a receive, so the call returns at once with the data or EAGAIN and the socket itself stays blocking. Winsock has no per-call non-blocking flag, so on Windows these calls still fail with EOPNOTSUPP for it; a TechnicalDebt entry records that. Other flags still fail with EOPNOTSUPP.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main b9f194a8. guest_sce_net gained CheckDontWait on a blocking UDP socket with a 2 s receive timeout: with nothing queued, sceNetRecv, sceNetRecvfrom, sceNetRecvmsg and MSG_DONTWAIT | MSG_PEEK fail with EAGAIN, all within one second; a datagram sent with sceNetSendto(..., MSG_DONTWAIT) is peeked with MSG_DONTWAIT | MSG_PEEK and then read with MSG_DONTWAIT; sceNetSend(..., MSG_DONTWAIT) on a connected socket delivers; MSG_OOB and a send with MSG_PEEK still fail with EOPNOTSUPP. On Windows the test expects EOPNOTSUPP for the flag.

  • Red: with main's Export.cpp the test aborts (EOPNOTSUPP instead of EAGAIN).
  • Green: guest_sce_net passes, also in 30 repeated runs; all guest_* tests except guest_video_out_* pass (307/307).

Windows: @johnmaia ran it on Windows 11 with WinLibs GCC 15.2.0, merged into main 3faa9cb40. guest_sce_net passes, with CheckDontWait's Windows branch getting EOPNOTSUPP for the flag, and the full suite passes 1074 of 1074. Merges cleanly with #4669 and #4394, which touch the same files.

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
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4833477248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4673). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T18:31:39Z. --- ### What `sceNetSend`, `sceNetSendto`, `sceNetRecv`, `sceNetRecvfrom`, `sceNetRecvmsg` and `sceNetSendmsg` failed with `EOPNOTSUPP` for every flag other than `MSG_PEEK` on a receive, so a game that polls a socket with `MSG_DONTWAIT` (`0x80`) got an error on every call instead of its data or `EWOULDBLOCK`. FreeBSD 11.4 defines the flag in `sys/sys/socket.h`: ```c #define MSG_DONTWAIT 0x80 /* this message should be nonblocking */ ``` and `soreceive_generic()` (`sys/kern/uipc_socket.c`) treats it as a non-blocking socket for that one call: ```c if ((so->so_state & SS_NBIO) || (flags & (MSG_DONTWAIT|MSG_NBIO))) { SOCKBUF_UNLOCK(&so->so_rcv); error = EWOULDBLOCK; goto release; ``` shadPS4's sceNet uses the same value ([`ORBIS_NET_MSG_DONTWAIT = 0x00000080`](https://github.com/shadps4-emu/shadPS4/blob/e0a466753a1aacbc8db8253be685bf7ab4d9daae/src/core/libraries/net/net_types.h#L104)). On Linux and macOS the flag now maps to the host's `MSG_DONTWAIT`, alone or with `MSG_PEEK` on a receive, so the call returns at once with the data or `EAGAIN` and the socket itself stays blocking. Winsock has no per-call non-blocking flag, so on Windows these calls still fail with `EOPNOTSUPP` for it; a TechnicalDebt entry records that. Other flags still fail with `EOPNOTSUPP`. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` b9f194a8. `guest_sce_net` gained `CheckDontWait` on a blocking UDP socket with a 2 s receive timeout: with nothing queued, `sceNetRecv`, `sceNetRecvfrom`, `sceNetRecvmsg` and `MSG_DONTWAIT | MSG_PEEK` fail with `EAGAIN`, all within one second; a datagram sent with `sceNetSendto(..., MSG_DONTWAIT)` is peeked with `MSG_DONTWAIT | MSG_PEEK` and then read with `MSG_DONTWAIT`; `sceNetSend(..., MSG_DONTWAIT)` on a connected socket delivers; `MSG_OOB` and a send with `MSG_PEEK` still fail with `EOPNOTSUPP`. On Windows the test expects `EOPNOTSUPP` for the flag. - Red: with `main`'s `Export.cpp` the test aborts (`EOPNOTSUPP` instead of `EAGAIN`). - Green: `guest_sce_net` passes, also in 30 repeated runs; all `guest_*` tests except `guest_video_out_*` pass (307/307). Windows: @johnmaia [ran it](https://github.com/boykopovar/AnyPS5/pull/4673#issuecomment-6146814528) on Windows 11 with WinLibs GCC 15.2.0, merged into `main` 3faa9cb40. `guest_sce_net` passes, with `CheckDontWait`'s Windows branch getting `EOPNOTSUPP` for the flag, and the full suite passes 1074 of 1074. Merges cleanly with #4669 and #4394, which touch the same files. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
johnmaia commented 2026-10-13 13:36:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johnmaia on 2026-10-13T13:36:56Z.


Windows run, since the description says Windows is untested. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, ctest -j4 --timeout 300, RTX 4080. Head 44d46ee97 merged into main 3faa9cb40.

  • guest_sce_net passes. The _WIN32 branch of CheckDontWait runs here, so sceNetRecv, sceNetRecvfrom, sceNetRecvmsg and sceNetSendto with MSG_DONTWAIT fail with 45 on Windows, as the test expects.
  • The full suite passes 1074 of 1074.

Not tested: a title, and a negative control on Windows.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146814528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4673#issuecomment-6146814528). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-13T13:36:56Z. --- Windows run, since the description says Windows is untested. Setup: Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, `ctest -j4 --timeout 300`, RTX 4080. Head 44d46ee97 merged into `main` 3faa9cb40. - `guest_sce_net` passes. The `_WIN32` branch of `CheckDontWait` runs here, so `sceNetRecv`, `sceNetRecvfrom`, `sceNetRecvmsg` and `sceNetSendto` with `MSG_DONTWAIT` fail with 45 on Windows, as the test expects. - The full suite passes 1074 of 1074. Not tested: a title, and a negative control on Windows. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-13 14:56:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:56:20Z.


Checked on Linux merged onto current main: guest_sce_net and the 30 tests of core/libs pass, and the new CheckDontWait fails with main's Export.cpp (EOPNOTSUPP instead of EAGAIN). sceNetSendmsg goes through sceNetSendto, so it gets the flag too. The Windows branch is covered by @johnmaia's run; the TechnicalDebt entry is in place. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148429648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4673#issuecomment-6148429648). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:56:20Z. --- Checked on Linux merged onto current `main`: `guest_sce_net` and the 30 tests of core/libs pass, and the new `CheckDontWait` fails with `main`'s `Export.cpp` (EOPNOTSUPP instead of EAGAIN). `sceNetSendmsg` goes through `sceNetSendto`, so it gets the flag too. The Windows branch is covered by @johnmaia's run; the TechnicalDebt entry is in place. Merging once the full Build is green.
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!4673
No description provided.