diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-29 16:23:18 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-07-29 16:23:18 (EDT) |
commit | 91acf0a3e0839dbc0ef558a43c86c75bfcbcb491 (patch) | |
tree | a85cc322545cfe484daedec7fa90bf7521e2d8cb | |
parent | dc6f59b5185ade4e36d95a46380ca40a67161a55 (diff) |
s_client: Slightly refactor socket connection func
-rw-r--r-- | src/s_client.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/s_client.c b/src/s_client.c index 863dd12..ba1238f 100644 --- a/src/s_client.c +++ b/src/s_client.c @@ -83,15 +83,15 @@ connect_socket(const char *host, const char *port) if (sfd == -1) { continue; } - if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) { - break; + if (connect(sfd, rp->ai_addr, rp->ai_addrlen) == -1) { + close(sfd); + continue; } - close(sfd); + break; } if (rp == NULL) { fputs("Failed to connect\n", stderr); - freeaddrinfo(result); - return -1; + sfd = -1; } freeaddrinfo(result); |