From c9a917fe5862bb042e36de84685b5c0fafa7f0eb Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 8 Sep 2013 05:10:29 +0000 Subject: [PATCH] net: Further simplify makesock_addrinfo(). Instead of breaking out of the loop, we may as well return the appropriate value directly. --- net.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/net.c b/net.c index 94610a84..28d11d66 100644 --- a/net.c +++ b/net.c @@ -443,23 +443,20 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai, close(sockfd); PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n", para_strerror(-ret)); - break; + return ret; } if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) { close(sockfd); continue; } - /* bind completed successfully */ - break; + return sockfd; } else { if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0) - break; /* connection completed successfully */ + return sockfd; + close(sockfd); } - close(sockfd); } - if (!ai) - return ret < 0? ret : -E_MAKESOCK; - return sockfd; + return -E_MAKESOCK; } /** -- 2.39.5