Skip to content

Commit 8ad1b6c

Browse files
authored
Merge pull request #130 from polycube-network/pr/fix_netlink_busy_wait
polycubed: fix busy wait in netlink socket
2 parents 743a2c0 + 5aa416f commit 8ad1b6c

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/polycubed/src/netlink.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,19 @@ class Netlink::NetlinkNotification {
6262
}
6363

6464
void execute_wait() {
65-
int socket_fd, result;
65+
int result;
6666
fd_set readset;
6767
struct timeval tv;
6868

69-
tv.tv_sec = NETLINK_TIMEOUT;
70-
tv.tv_usec = 0;
71-
7269
while (running) {
7370
do {
71+
tv.tv_sec = NETLINK_TIMEOUT;
72+
tv.tv_usec = 0;
7473
FD_ZERO(&readset);
7574
FD_SET(sock, &readset);
75+
// The struct tv is decremented every time the select terminates.
76+
// If the value is not updated, the next time select is called uses
77+
// 0 as timeout value, behaving as a non-blocking socket.
7678
result = select(sock + 1, &readset, NULL, NULL, &tv);
7779
} while (result < 0 && errno == EINTR && running);
7880

0 commit comments

Comments
 (0)