]> git.tue.mpg.de Git - paraslash.git/commitdiff
net: makesock(): Combine code for passive sockets.
authorAndre Noll <maan@systemlinux.org>
Sun, 8 Sep 2013 04:37:30 +0000 (04:37 +0000)
committerAndre Noll <maan@systemlinux.org>
Wed, 1 Jan 2014 17:40:15 +0000 (17:40 +0000)
Make use of  the fact that

if (a && b)
foo;
if (a)
bar;
else
baz;

is equivalent to

if (a) {
if (b)
foo;
bar;
} else
baz;

but the second form is easier to read, IMHO.

net.c

diff --git a/net.c b/net.c
index a95f145a78ac111416201aebe4b1f628e2a73544..dfbbc1ee6b6135d74eb72fda7857f21843cdda81 100644 (file)
--- a/net.c
+++ b/net.c
@@ -441,21 +441,21 @@ static int makesock_addrinfo(unsigned l4type, bool passive, struct addrinfo *ai,
                        goto get_next_dst;
                sockfd = ret;
                flowopt_setopts(sockfd, fo);
-               /*
-                * Reuse the address on passive sockets to avoid failure on
-                * restart (protocols using listen()) and when creating
-                * multiple listener instances (UDP multicast).
-                */
-               if (passive && 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));
-                       break;
-               }
-
                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));
+                               break;
+                       }
                        if (bind(sockfd, src->ai_addr, src->ai_addrlen) < 0) {
                                close(sockfd);
                                goto get_next_src;