diff options
author | Linus Nordberg <linus@nordberg.se> | 2019-04-26 10:44:22 +0200 |
---|---|---|
committer | Thomas Gschwantner <tharre3@gmail.com> | 2019-05-26 01:07:46 +0200 |
commit | 0d19bdca32c60908a8637482c6782898d52015cb (patch) | |
tree | 3f1f6268f0f0794a7bf81d136e8dda1bbac19af5 | |
parent | Use blocking I/O in client (diff) | |
download | wg-dynamic-0d19bdca32c60908a8637482c6782898d52015cb.tar.xz wg-dynamic-0d19bdca32c60908a8637482c6782898d52015cb.zip |
Sleep less
Only sleep after failed try_connect(), because it might fail quickly.
The read should be blocking for 1s (SO_RCVTIMEO).
-rw-r--r-- | wg-dynamic-client.c | 8 |
1 files 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); } |