Skip to content

Conversation

@dkosmari
Copy link
Contributor

@dkosmari dkosmari commented Oct 6, 2025

The main issue fixed here is the incompatible implementation of select() in nsysnet: for BSD select(), on timeout (zero return value) it's supposed to clear the fd_set arguments. As far as I could test, nsysnet select() leaves the arguments untouched on timeout; so the latter part of wutoscket select() will simply add the sockets back to the fd_sets. An early return, after the arguments are zeroed, is enough to ensure the correct result.

Also in select(), the check against FD_SETSIZE was removed, as it's a pointless restriction. If the user exceeded FD_SETSIZE in the arguments, we're already in undefined behavior territory, and the runtime stack was already overflown before even calling select().

The definition of FD_SETSIZE is now conditional, allowing it to be a custom limit, as it was always intended. The definition of fd_set in newlib is an array that uses FD_SETSIZE.

Both select() and poll() received a check against NSYSNET_FD_SETSIZE, to avoid calling NSYSNET_FD_SET with an invalid fd. Even though it's just setting a bit in a uint32_t (instead of writing to an array of incorrect size), bit-shifts larger than the type are undefined behavior.

Daniel K. O. (dkosmari) added 2 commits October 6, 2025 11:52
- Move the nfds argument restriction to the nsysnet side.
- Allow user-defined FD_SETSIZE, since newlib's fd_set allow custom sizes.
- Define __socklen_t_defined when socklen_t is typedefed.
@GaryOderNichts GaryOderNichts merged commit 1b412d2 into devkitPro:master Oct 10, 2025
2 checks passed
@GaryOderNichts
Copy link
Contributor

Thanks!

@dkosmari dkosmari deleted the wutsocket-fixes branch October 10, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants