]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
net: Reduce indentation level in makesock_addrinfo().
authorAndre Noll <maan@systemlinux.org>
Sun, 8 Sep 2013 05:16:46 +0000 (05:16 +0000)
committerAndre Noll <maan@systemlinux.org>
Wed, 1 Jan 2014 17:40:16 +0000 (17:40 +0000)
Handle the active socket case of makesock_addrinfo() first, i.e.
transform

if (a)
lots_of_stuff;
else
short;
into

if (!a) {
short;
continue;
}
lots_of_stuff;

net.c

diff --git a/net.c b/net.c
index 28d11d664c937404e034d65760c00e5fa8cc1a3a..b7806a18e075f091c87611b0c64e43bdf711500b 100644 (file)
--- a/net.c
+++ b/net.c
@@ -430,31 +430,30 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                        continue;
                sockfd = ret;
                flowopt_setopts(sockfd, fo);
                        continue;
                sockfd = ret;
                flowopt_setopts(sockfd, fo);
-               if (passive) {
-                       /*
-                        * Reuse the address on passive sockets to avoid
-                        * failure on restart (protocols using listen()) and
-                        * when creating multiple listener instances (UDP
-                        * multicast).
-                        */
-                       if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on,
-                                       sizeof(on)) == -1) {
-                               ret = -ERRNO_TO_PARA_ERROR(errno);
-                               close(sockfd);
-                               PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
-                                       para_strerror(-ret));
-                               return ret;
-                       }
-                       if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
-                               close(sockfd);
-                               continue;
-                       }
-                       return sockfd;
-               } else {
+               if (!passive) {
                        if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
                                return sockfd;
                        close(sockfd);
                        if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
                                return sockfd;
                        close(sockfd);
+                       continue;
+               }
+               /*
+                * Reuse the address on passive sockets to avoid failure on
+                * restart (protocols using listen()) and when creating
+                * multiple listener instances (UDP multicast).
+                */
+               if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on,
+                               sizeof(on)) == -1) {
+                       ret = -ERRNO_TO_PARA_ERROR(errno);
+                       close(sockfd);
+                       PARA_ERROR_LOG("can not set SO_REUSEADDR: %s\n",
+                               para_strerror(-ret));
+                       return ret;
+               }
+               if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
+                       close(sockfd);
+                       continue;
                }
                }
+               return sockfd;
        }
        return -E_MAKESOCK;
 }
        }
        return -E_MAKESOCK;
 }