From d6f8bffb3bc57ad47dea4736b85bd4300d664548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ka=C4=9Fan=20Can=20=C5=9Eit?= Date: Sun, 8 Mar 2026 21:53:49 +0300 Subject: [PATCH] Simplify connect_to_host logic --- src/cli/tls_client.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/cli/tls_client.cpp b/src/cli/tls_client.cpp index 45ffa31098f..fbf3fb16b51 100644 --- a/src/cli/tls_client.cpp +++ b/src/cli/tls_client.cpp @@ -397,12 +397,8 @@ class TLS_Client final : public Command { throw CLI_Error("getaddrinfo failed for " + host); } - socket_type fd = 0; - bool success = false; - for(const addrinfo* rp = res.get(); rp != nullptr; rp = rp->ai_next) { - fd = ::socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - + const socket_type fd = ::socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if(fd == invalid_socket()) { continue; } @@ -416,17 +412,11 @@ class TLS_Client final : public Command { ::close(fd); continue; } - - success = true; - break; - } - - if(!success) { - // no address succeeded - throw CLI_Error("Connecting to host failed"); + return fd; } - return fd; + // no address succeeded + throw CLI_Error("Connecting to host failed"); } static void dgram_socket_write(int sockfd, const uint8_t buf[], size_t length) {