Skip to content

Commit

Permalink
llmnrd: Don't busy wait in receive loop
Browse files Browse the repository at this point in the history
There is no need to have a timeout for select(2) to check llmnr_running
periodically. It can just block until a packet is received and will be
interrupted by any terminating signal.

Closes #19

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Jan 7, 2017
1 parent 5fc94b0 commit e3d021b
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions llmnr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2016 Tobias Klauser <tklauser@distanz.ch>
* Copyright (C) 2014-2017 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of llmnrd.
*
Expand Down Expand Up @@ -304,7 +304,6 @@ int llmnr_run(void)

while (llmnr_running) {
fd_set rfds;
struct timeval tv;
int nfds, ret;

FD_ZERO(&rfds);
Expand All @@ -315,10 +314,7 @@ int llmnr_run(void)
} else
nfds = llmnr_sock_ipv4 + 1;

tv.tv_sec = 0;
tv.tv_usec = 50000;

ret = select(nfds, &rfds, NULL, NULL, &tv);
ret = select(nfds, &rfds, NULL, NULL, NULL);
if (ret < 0) {
if (errno != EINTR)
log_err("Failed to select() on socket: %s\n", strerror(errno));
Expand Down

0 comments on commit e3d021b

Please sign in to comment.