Code

frontend: Let listen_and_serve() return early if do_loop == 0.
authorSebastian Harl <sh@tokkee.org>
Tue, 17 Dec 2013 19:13:16 +0000 (20:13 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 17 Dec 2013 19:13:16 +0000 (20:13 +0100)
That is, do not (re-)open any sockets.

src/frontend/sock.c
t/frontend/sock_test.c

index 65884ea945bf61fe935b48fe60ab819b453b1eb8..27aa1c5653086a8c073b5c8dbb71c441b268e0be 100644 (file)
@@ -443,6 +443,9 @@ sdb_fe_sock_listen_and_serve(sdb_fe_socket_t *sock, sdb_fe_loop_t *loop)
        if ((! sock) || (! sock->listeners_num) || (! loop) || sock->chan)
                return -1;
 
+       if (! loop->do_loop)
+               return 0;
+
        FD_ZERO(&sockets);
        for (i = 0; i < sock->listeners_num; ++i) {
                listener_t *listener = sock->listeners + i;
index 4ac8196d9dba07ac89de64d28002242793601511..5579e3647b5f19d36990e4f56a81a9fd3d8f1780 100644 (file)
@@ -129,6 +129,15 @@ START_TEST(test_listen_and_serve)
        pthread_join(thr, NULL);
 
        unlink(tmp_file);
+
+       /* should do nothing and not report errors */
+       check = sdb_fe_sock_listen_and_serve(sock, &loop);
+       fail_unless(check == 0,
+                       "sdb_fe_sock_listen_and_serve() = %i; "
+                       "expected: <0 (do_loop == 0)", check);
+       fail_unless(access(tmp_file, F_OK),
+                       "sdb_fe_sock_listen_and_serve() recreated socket "
+                       "(do_loop == 0)");
 }
 END_TEST