stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.33k stars 1.71k forks source link

Wrong return value of _modbus_tcp_pi_connect() on failure #61

Closed oldfaber closed 12 years ago

oldfaber commented 12 years ago

If getaddrinfo() fails inside _modbus_tcp_pi_connect() "rc" is returned at line 305. This is not consistent with _modbus_tcp_connect that always return -1, and with the documentation of modbus_connect(). "return rc" should be "return (-1)".

Moreover errno is not set, but this is a bigger issue, as errno is not set for many errors.

Regards

Fabio

stephane commented 12 years ago

Fabio,

Thank you for the report, the problem has been fixed.

errno is set explicitely by libmodbus or by the system call on Unix/Linux systems, I know the situation isn't as good on Windows. Feel free to indicate the missing errno you've catched.