From 038db8fd80c54a71bd777514d38ea0e63289d75a Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Mon, 4 May 2015 09:30:23 +0200 Subject: [PATCH] common: corrected select loops --- src/common.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/common.c b/src/common.c index d8559dc8..7f8d1e01 100644 --- a/src/common.c +++ b/src/common.c @@ -144,19 +144,18 @@ uint8_t * p = buf; struct timeval tv; fd_set set; - if (sec > 0) { - tv.tv_sec = sec; - tv.tv_usec = 0; - - FD_ZERO(&set); - FD_SET(sockfd, &set); - } - while(left > 0) { if (sec > 0) { - ret = select(sockfd + 1, &set, NULL, NULL, &tv); - if (ret == -1 && errno == EINTR) - continue; + tv.tv_sec = sec; + tv.tv_usec = 0; + + FD_ZERO(&set); + FD_SET(sockfd, &set); + + do { + ret = select(sockfd + 1, &set, NULL, NULL, &tv); + } while (ret == -1 && errno == EINTR); + if (ret == -1 || ret == 0) { errno = ETIMEDOUT; return -1;