From 0d19bdca32c60908a8637482c6782898d52015cb Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 26 Apr 2019 10:44:22 +0200 Subject: Sleep less Only sleep after failed try_connect(), because it might fail quickly. The read should be blocking for 1s (SO_RCVTIMEO). --- wg-dynamic-client.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wg-dynamic-client.c b/wg-dynamic-client.c index 4e3ea24..fe0b6b5 100644 --- a/wg-dynamic-client.c +++ b/wg-dynamic-client.c @@ -431,15 +431,17 @@ int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) } while (1) { - sleep(MAX(1, time_until_refresh(current_time(), &our_lease))); + sleep(time_until_refresh(current_time(), &our_lease)); - if (*fd == -1 && try_connect(fd)) + if (*fd == -1 && try_connect(fd)) { + sleep(1); continue; + } request_ip(*fd, &our_lease); while (!read_response(*fd, &req, handle_response, handle_error)) - sleep(1); + ; close_connection(fd, &req); } -- cgit v1.2.3-59-g8ed1b