libmodbus
libmodbus copied to clipboard
With TCP, `modbus_connect()` returns -1 on timeout but does not set `errno`
libmodbus version
3f9f17e228f70ce2fcdc1988cf7563fc1bf78eec (current master)
OS and/or distribution
Windows (but I believe the problem also exists on *NIX)
Environment
N/A
Description
With TCP, modbus_connect() returns -1 on timeout, but does not set errno.
The reason seems to be that the timeout is implemented via select(), where a timeout is not considered an error. The offending code is in lines 295–299 of modbus-tcp.c, which look like this:
rc = select(sockfd + 1, NULL, &wset, NULL, &tv);
if (rc <= 0) {
/* Timeout or fail */
return -1;
}
Expected behavior or suggestion
errno == ETIMEDOUT