mosquitto_loop_forever: use nanosleep instead of sleep

The advantage of nanosleep(2) is, that -according to POSIX spec- it does not
interact with signals as sleep(3) does. So it is not affected when used by a
program which is e.g. using alarm(3).

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
pull/589/head
Michael Heimpold 8 years ago
parent 2283585e39
commit 26a81747cd

@ -23,6 +23,7 @@ Contributors:
#include <sys/select.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#else
#include <winsock2.h>
#include <windows.h>
@ -983,6 +984,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
int rc;
unsigned int reconnects = 0;
unsigned long reconnect_delay;
#ifndef WIN32
struct timespec req, rem;
#endif
if(!mosq) return MOSQ_ERR_INVAL;
@ -1042,7 +1046,10 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
#ifdef WIN32
Sleep(reconnect_delay*1000);
#else
sleep(reconnect_delay);
req.tv_sec = reconnect_delay;
req.tv_nsec = 0;
while(nanosleep(&req, &rem) == -1 && errno == EINTR)
req = rem;
#endif
pthread_mutex_lock(&mosq->state_mutex);

Loading…
Cancel
Save