Skip to content

Commit

Permalink
Merge pull request #130 from polycube-network/pr/fix_netlink_busy_wait
Browse files Browse the repository at this point in the history
polycubed: fix busy wait in netlink socket
  • Loading branch information
frisso committed May 21, 2019
2 parents 743a2c0 + 5aa416f commit 8ad1b6c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/polycubed/src/netlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,19 @@ class Netlink::NetlinkNotification {
}

void execute_wait() {
int socket_fd, result;
int result;
fd_set readset;
struct timeval tv;

tv.tv_sec = NETLINK_TIMEOUT;
tv.tv_usec = 0;

while (running) {
do {
tv.tv_sec = NETLINK_TIMEOUT;
tv.tv_usec = 0;
FD_ZERO(&readset);
FD_SET(sock, &readset);
// The struct tv is decremented every time the select terminates.
// If the value is not updated, the next time select is called uses
// 0 as timeout value, behaving as a non-blocking socket.
result = select(sock + 1, &readset, NULL, NULL, &tv);
} while (result < 0 && errno == EINTR && running);

Expand Down

0 comments on commit 8ad1b6c

Please sign in to comment.