Fix timeout conversion error.

This commit is contained in:
Roger A. Light 2020-10-30 21:31:13 +00:00
parent 0097a85ce0
commit 2e72d795a9
2 changed files with 12 additions and 10 deletions

View File

@ -139,7 +139,7 @@ ifeq ($(UNAME),SunOS)
CFLAGS?=-Wall -ggdb -O2 CFLAGS?=-Wall -ggdb -O2
endif endif
else else
CFLAGS?=-Wall -ggdb -O2 CFLAGS?=-Wall -ggdb -O2 -Wconversion
endif endif
STATIC_LIB_DEPS:= STATIC_LIB_DEPS:=

View File

@ -50,6 +50,7 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
#ifdef WITH_SRV #ifdef WITH_SRV
int state; int state;
#endif #endif
time_t timeout_ms;
if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL; if(!mosq || max_packets < 1) return MOSQ_ERR_INVAL;
#ifndef WIN32 #ifndef WIN32
@ -109,26 +110,27 @@ int mosquitto_loop(struct mosquitto *mosq, int timeout, int max_packets)
} }
} }
if(timeout < 0){ timeout_ms = timeout;
timeout = 1000; if(timeout_ms < 0){
timeout_ms = 1000;
} }
now = mosquitto_time(); now = mosquitto_time();
if(mosq->next_msg_out && now + timeout/1000 > mosq->next_msg_out){ if(mosq->next_msg_out && now + timeout_ms/1000 > mosq->next_msg_out){
timeout = (mosq->next_msg_out - now)*1000; timeout_ms = (mosq->next_msg_out - now)*1000;
} }
if(timeout < 0){ if(timeout_ms < 0){
/* There has been a delay somewhere which means we should have already /* There has been a delay somewhere which means we should have already
* sent a message. */ * sent a message. */
timeout = 0; timeout_ms = 0;
} }
local_timeout.tv_sec = timeout/1000; local_timeout.tv_sec = timeout_ms/1000;
#ifdef HAVE_PSELECT #ifdef HAVE_PSELECT
local_timeout.tv_nsec = (timeout-local_timeout.tv_sec*1000)*1000000; local_timeout.tv_nsec = (timeout_ms-local_timeout.tv_sec*1000)*1000000;
#else #else
local_timeout.tv_usec = (timeout-local_timeout.tv_sec*1000)*1000; local_timeout.tv_usec = (timeout_ms-local_timeout.tv_sec*1000)*1000;
#endif #endif
#ifdef HAVE_PSELECT #ifdef HAVE_PSELECT