From: Sebastian Harl Date: Tue, 17 Dec 2013 19:13:16 +0000 (+0100) Subject: frontend: Let listen_and_serve() return early if do_loop == 0. X-Git-Tag: sysdb-0.1.0~309 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6fe41d22ff823189762bc369b7bee412d333dd0f;p=sysdb.git frontend: Let listen_and_serve() return early if do_loop == 0. That is, do not (re-)open any sockets. --- diff --git a/src/frontend/sock.c b/src/frontend/sock.c index 65884ea..27aa1c5 100644 --- a/src/frontend/sock.c +++ b/src/frontend/sock.c @@ -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; diff --git a/t/frontend/sock_test.c b/t/frontend/sock_test.c index 4ac8196..5579e36 100644 --- a/t/frontend/sock_test.c +++ b/t/frontend/sock_test.c @@ -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