Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete commit revert? #711

Closed
martinwag opened this issue Aug 10, 2023 · 1 comment
Closed

Incomplete commit revert? #711

martinwag opened this issue Aug 10, 2023 · 1 comment

Comments

@martinwag
Copy link

martinwag commented Aug 10, 2023

libmodbus version

Git b25629b (Head as of 2023-08-10)

Description

commit db1cbc5 introduced some changes with commit description "windows only". However, this commit also changed linux behavior in three places. Commit 9b679b7 then reverts this, but misses one place.

@@ -409,7 +438,19 @@ int _modbus_receive_msg(modbus_t *ctx, uint8_t *msg, msg_type_t msg_type)
 
         if (rc == -1) {
             _error_print(ctx, "read");
+#ifdef _WIN32
+            wsa_err = WSAGetLastError();
             if ((ctx->error_recovery & MODBUS_ERROR_RECOVERY_LINK) &&
+                (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_TCP) &&
+                (wsa_err == WSAENOTCONN || wsa_err == WSAENETRESET || wsa_err == WSAENOTSOCK ||
+                wsa_err == WSAESHUTDOWN || wsa_err == WSAECONNABORTED || wsa_err == WSAETIMEDOUT ||
+                wsa_err == WSAECONNRESET)) {
+                modbus_close(ctx);
+                modbus_connect(ctx);
+            }
+#else
-->  +            if ((ctx->error_recovery & MODBUS_ERROR_RECOVERY_LINK) &&
-->  +                (ctx->backend->backend_type == _MODBUS_BACKEND_TYPE_TCP) &&
                 (errno == ECONNRESET || errno == ECONNREFUSED ||
                  errno == EBADF)) {
                 int saved_errno = errno;

I don't think this was intentionally left like this, but I also can't verify it. Please have a look if this is correct.

@stephane
Copy link
Owner

You're right and I think there is an issue on Windows with serial.
I'm sure we should revert the check on TCP for not Windows in third place and to have a behavior similar to previous version for Windows serial, I reverted the TCP check for Windows too.

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

No branches or pull requests

2 participants