Skip to content

_modbus_receive_msg: don't require a socket for the Windows RTU backend - #891

Open
StalderT wants to merge 1 commit into
stephane:masterfrom
StalderT:fix/win32-rtu-receive
Open

StalderT wants to merge 1 commit into
stephane:masterfrom
StalderT:fix/win32-rtu-receive

Conversation

@StalderT

@StalderT StalderT commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

On Windows the RTU backend waits on a serial HANDLE held in its own backend data and never sets ctx->s, which stays at -1. It also ignores the fd_set it is given: _modbus_rtu_select() only uses rset in its POSIX branch, and a mingw build reports the parameter as unused. Since 7b13341 _modbus_receive_msg() validates ctx->s before every FD_SET, so every receive on a Windows RTU context now fails at once with EINVAL instead of waiting for the timeout. v3.1.11 is not affected, v3.1.12 and v3.2.0 are.

Skip the check and the FD_SET for a backend that does not use the set, which on Windows means the RTU one. Nothing changes anywhere else: on POSIX the condition is the constant 1.

Fixes #890

On Windows the RTU backend waits on a serial HANDLE held in its own backend data and never sets ctx->s, which stays at -1. It also ignores the fd_set it is given: _modbus_rtu_select() only uses rset in its POSIX branch, and a mingw build reports the parameter as unused. Since 7b13341 _modbus_receive_msg() validates ctx->s before every FD_SET, so every receive on a Windows RTU context now fails at once with EINVAL instead of waiting for the timeout. v3.1.11 is not affected, v3.1.12 and v3.2.0 are.

Skip the check and the FD_SET for a backend that does not use the set, which on Windows means the RTU one. Nothing changes anywhere else: on POSIX the condition is the constant 1.

Fixes stephane#890
@cla-bot

cla-bot Bot commented Nov 5, 2026

Copy link
Copy Markdown

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...

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.

[Windows][RTU] 3.1.12/3.2.0: every receive fails with "Invalid socket descriptor -1" (EINVAL)

1 participant