net: Further simplify makesock_addrinfo().
authorAndre Noll <maan@systemlinux.org>
Sun, 8 Sep 2013 05:10:29 +0000 (05:10 +0000)
committerAndre Noll <maan@systemlinux.org>
Wed, 1 Jan 2014 17:40:16 +0000 (17:40 +0000)
Instead of breaking out of the loop, we may as well return the
appropriate value directly.

net.c

diff --git a/net.c b/net.c
index 94610a8..28d11d6 100644 (file)
--- 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;
 }
 
 /**