Hello,
I needed the ability to set a defined timeout period for modbus_connect() on a TCP connection. This is for periodically trying to (re-)connect to a device which may be switched off or unplugged. The default linux kernel socket connect() timeout period of about 20s is much too long for me.
The appended patch adds a new method modbus_connect_with_timeout(modbus_t *ctx, unsigned long timeout_ms) for this issue. The "old" method modbus_connect(modbus_t *ctx) internally sets the timeout to 20000ms. It's only for Linux and only for TCP connections at the moment, but it's a starting point for a further release implementation.
Cheers,
Felix