Don't apply the FD_SETSIZE check to Windows sockets#866
Open
StalderT wants to merge 1 commit into
Open
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: TStal.
|
On Windows a SOCKET is an opaque handle, not a small index, and an fd_set is a counted array of sockets rather than a bitmask. libmodbus only ever puts a single socket in a set, so it can't overflow it. The fd >= FD_SETSIZE checks added in 7b13341 therefore don't apply on Windows, where they instead reject any socket whose handle value reaches FD_SETSIZE (64 by default) - which happens after a few dozen open handles and breaks Modbus TCP with EINVAL / "exceeds FD_SETSIZE". Wrap the check in a macro that keeps it on POSIX and disables it on Windows. POSIX behaviour is unchanged. Fixes stephane#842
StalderT
force-pushed
the
fix-fdsetsize-windows
branch
from
July 23, 2026 16:31
fde8276 to
24f6be6
Compare
|
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows a SOCKET is an opaque handle, not a small index, and an fd_set is a counted array of sockets rather than a bitmask. libmodbus only ever puts a single socket in a set, so it can't overflow it.
The fd >= FD_SETSIZE checks added in 7b13341 therefore don't apply on Windows, where they instead reject any socket whose handle value reaches FD_SETSIZE (64 by default) - which happens after a few dozen open handles and breaks Modbus TCP with EINVAL / "exceeds FD_SETSIZE".
Wrap the check in a macro that keeps it on POSIX and disables it on Windows. POSIX behaviour is unchanged.
Fixes #842