From 91acf0a3e0839dbc0ef558a43c86c75bfcbcb491 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 29 Jul 2019 16:23:18 -0400 Subject: s_client: Slightly refactor socket connection func --- (limited to 'src') 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); -- cgit v0.9.1