net: Further simplify makesock_addrinfo().
[paraslash.git] / 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;
 }
 
 /**