miniupnpd: introduce upnp_gettimeofday() which is monotonic :)

fixes #288
This commit is contained in:
Thomas Bernard 2018-04-12 10:07:11 +02:00
parent 0d0b4d2372
commit eaaf4f10ae
4 changed files with 26 additions and 4 deletions

View File

@ -120,7 +120,7 @@ sendto_schedule2(int sockfd, const void *buf, size_t len, int flags,
}
/* schedule */
if(gettimeofday(&tv, 0) < 0) {
if(upnp_gettimeofday(&tv) < 0) {
return -1;
}
/* allocate enough space for structure + buffers */
@ -283,7 +283,7 @@ void finalize_sendto(void)
struct timeval timeout;
int max_fd;
if(gettimeofday(&deadline, NULL) < 0) {
if(upnp_gettimeofday(&deadline) < 0) {
syslog(LOG_ERR, "gettimeofday: %m");
return;
}
@ -317,7 +317,7 @@ void finalize_sendto(void)
free(elt);
}
/* check deadline */
if(gettimeofday(&now, NULL) < 0) {
if(upnp_gettimeofday(&now) < 0) {
syslog(LOG_ERR, "gettimeofday: %m");
return;
}

View File

@ -2094,7 +2094,7 @@ main(int argc, char * * argv)
}
/* Check if we need to send SSDP NOTIFY messages and do it if
* needed */
if(gettimeofday(&timeofday, 0) < 0)
if(upnp_gettimeofday(&timeofday) < 0)
{
syslog(LOG_ERR, "gettimeofday(): %m");
timeout.tv_sec = v.notify_interval;

View File

@ -220,3 +220,19 @@ time_t upnp_get_uptime(void)
#endif
return upnp_time() - startup_time;
}
int upnp_gettimeofday(struct timeval * tv)
{
#if defined(CLOCK_MONOTONIC_FAST) || defined(CLOCK_MONOTONIC)
struct timespec ts;
int ret_code = clock_gettime(UPNP_CLOCKID, &ts);
if (ret_code == 0)
{
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}
return ret_code;
#else
return gettimeofday(tv, NULL);
#endif
}

View File

@ -40,6 +40,12 @@ time_t upnp_time(void);
*/
time_t upnp_get_uptime(void);
/**
* get the time for upnp
* Similar to a monotonic gettimeofday(tv, NULL)
*/
int upnp_gettimeofday(struct timeval * tv);
/**
* define portability macros
*/