Permalink
Browse files

Return value of _modbus_tcp_pi_connect() on failure (closes #61)

  • Loading branch information...
1 parent be4b215 commit 2dca04230e21987586aacd280d97fc8026e82447 @stephane committed May 29, 2012
Showing with 9 additions and 4 deletions.
  1. +8 −2 src/modbus-tcp.c
  2. +1 −2 tests/unit-test-client.c
View
@@ -349,8 +349,9 @@ static int _modbus_tcp_pi_connect(modbus_t *ctx)
&ai_hints, &ai_list);
if (rc != 0) {
if (ctx->debug) {
- printf("Error returned by getaddrinfo: %d\n", rc);
+ fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
}
+ errno = ECONNREFUSED;
return -1;
}
@@ -518,8 +519,13 @@ int modbus_tcp_pi_listen(modbus_t *ctx, int nb_connection)
ai_list = NULL;
rc = getaddrinfo(node, service, &ai_hints, &ai_list);
- if (rc != 0)
+ if (rc != 0) {
+ if (ctx->debug) {
+ fprintf(stderr, "Error returned by getaddrinfo: %s\n", gai_strerror(rc));
+ }
+ errno = ECONNREFUSED;
return -1;
+ }
new_socket = -1;
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) {
View
@@ -82,8 +82,7 @@ int main(int argc, char *argv[])
}
if (modbus_connect(ctx) == -1) {
- fprintf(stderr, "Connection failed: %s\n",
- modbus_strerror(errno));
+ fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}

0 comments on commit 2dca042

Please sign in to comment.