fix(libkernel): accept MSG_DONTWAIT in the socket send and receive calls #4676

Merged
milescoviello merged 1 commit from upstream-pr/4676 into main 2026-10-14 17:13:54 +00:00
milescoviello commented 2026-10-12 18:34:43 +00:00 (Migrated from github.com)

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


What

libkernel's send, sendto, sendmsg, recv, recvfrom and recvmsg failed with EOPNOTSUPP for MSG_DONTWAIT (0x80), so code that polls a blocking socket with it, as POSIX networking code and the libraries homebrew ports bring along commonly do, 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;

On Linux and macOS the flag now maps to the host's MSG_DONTWAIT, next to MSG_PEEK on a receive and MSG_NOSIGNAL on a send, 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. #4673 is the same change for libSceNet.

Tested

Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on main 5d933db0. guest_udp gained CheckDontWait on a blocking UDP socket: with nothing queued, recv, recvfrom, recvmsg and MSG_DONTWAIT | MSG_PEEK fail with EAGAIN, all within one second; a datagram sent with sendto(..., MSG_DONTWAIT) is peeked with MSG_DONTWAIT | MSG_PEEK and then read with MSG_DONTWAIT; send(..., MSG_DONTWAIT | MSG_NOSIGNAL) on a connected socket delivers; MSG_OOB still fails with EOPNOTSUPP. On Windows the test expects EOPNOTSUPP for the flag.

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

Windows: @johnmaia ran it on Windows 11 with WinLibs GCC 15.2.0, merged into main 3faa9cb40. guest_udp passes, with CheckDontWait's Windows branch getting EOPNOTSUPP for the flag, and the full suite passes 1074 of 1074. Merges cleanly with #4351, #4391, #4498, #4658, #4669 and #4673.

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:4833509505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4676). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-12T18:34:43Z. --- ### What libkernel's `send`, `sendto`, `sendmsg`, `recv`, `recvfrom` and `recvmsg` failed with `EOPNOTSUPP` for `MSG_DONTWAIT` (`0x80`), so code that polls a blocking socket with it, as POSIX networking code and the libraries homebrew ports bring along commonly do, 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; ``` On Linux and macOS the flag now maps to the host's `MSG_DONTWAIT`, next to `MSG_PEEK` on a receive and `MSG_NOSIGNAL` on a send, 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`. #4673 is the same change for libSceNet. ### Tested Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on `main` 5d933db0. `guest_udp` gained `CheckDontWait` on a blocking UDP socket: with nothing queued, `recv`, `recvfrom`, `recvmsg` and `MSG_DONTWAIT | MSG_PEEK` fail with `EAGAIN`, all within one second; a datagram sent with `sendto(..., MSG_DONTWAIT)` is peeked with `MSG_DONTWAIT | MSG_PEEK` and then read with `MSG_DONTWAIT`; `send(..., MSG_DONTWAIT | MSG_NOSIGNAL)` on a connected socket delivers; `MSG_OOB` still fails with `EOPNOTSUPP`. On Windows the test expects `EOPNOTSUPP` for the flag. - Red: with `main`'s `Udp.cpp` the test aborts (`EOPNOTSUPP` instead of `EAGAIN`). - Green: `guest_udp` passes, also in 30 repeated runs; all `guest_*` tests except `guest_video_out_*` pass (310/310). Windows: @johnmaia [ran it](https://github.com/boykopovar/AnyPS5/pull/4676#issuecomment-6146815038) on Windows 11 with WinLibs GCC 15.2.0, merged into `main` 3faa9cb40. `guest_udp` passes, with `CheckDontWait`'s Windows branch getting `EOPNOTSUPP` for the flag, and the full suite passes 1074 of 1074. Merges cleanly with #4351, #4391, #4498, #4658, #4669 and #4673. ### 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:58 +00:00 (Migrated from github.com)

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


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 7afd88926 merged into main 3faa9cb40.

  • guest_udp passes. The _WIN32 branch of CheckDontWait runs here, so recv, recvfrom, recvmsg and sendto with flag 0x80 fail with errno 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:6146815038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4676#issuecomment-6146815038). Originally posted by [johnmaia](https://github.com/johnmaia) on 2026-10-13T13:36:58Z. --- 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 7afd88926 merged into `main` 3faa9cb40. - `guest_udp` passes. The `_WIN32` branch of `CheckDontWait` runs here, so `recv`, `recvfrom`, `recvmsg` and `sendto` with flag `0x80` fail with errno 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:57:53 +00:00 (Migrated from github.com)

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


Checked MSG_DONTWAIT against FreeBSD's soreceive_generic, built and ran guest_udp plus the libkernel/libs ctest scope (147/147), and confirmed CheckDontWait fails without the Udp.cpp change. Windows confirmed by @johnmaia (1074/1074). Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148460764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4676#issuecomment-6148460764). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:57:53Z. --- Checked `MSG_DONTWAIT` against FreeBSD's `soreceive_generic`, built and ran `guest_udp` plus the libkernel/libs ctest scope (147/147), and confirmed `CheckDontWait` fails without the `Udp.cpp` change. Windows confirmed by @johnmaia (1074/1074). Merging.
adriadam10 commented 2026-10-14 16:54:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T16:54:58Z.


The earlier full Build failed only in guest_math, which was red on main at the time and is unrelated to this diff (fixed by #5256, merged after that run). Windows was green, guest_udp passes locally on the current head. Merging once a fresh full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6173650020 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4676#issuecomment-6173650020). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T16:54:58Z. --- The earlier full Build failed only in `guest_math`, which was red on `main` at the time and is unrelated to this diff (fixed by #5256, merged after that run). Windows was green, `guest_udp` passes locally on the current head. Merging once a fresh full Build is green.
adriadam10 commented 2026-10-14 16:59:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T16:59:04Z.


Re-ran the full Build on the current main (the previous run predated #5256, which fixed the guest_math failure). The diff is unchanged and unrelated to libc/math; merging once that run is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6173735216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4676#issuecomment-6173735216). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T16:59:04Z. --- Re-ran the full Build on the current `main` (the previous run predated #5256, which fixed the `guest_math` failure). The diff is unchanged and unrelated to libc/math; merging once that run 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!4676
No description provided.