minissdpd: use upnp_gettimeofday()
This commit is contained in:
parent
e94a724ae5
commit
4e4edf244d
|
@ -1,7 +1,7 @@
|
|||
/* $Id: asyncsendto.c,v 1.8 2017/05/24 22:51:57 nanard Exp $ */
|
||||
/* $Id: asyncsendto.c,v 1.10 2018/07/06 11:44:59 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2017 Thomas Bernard
|
||||
* (c) 2006-2018 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -345,4 +345,3 @@ void finalize_sendto(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: upnputils.c,v 1.2 2014/11/28 16:20:58 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2014 Thomas Bernard
|
||||
* (c) 2006-2019 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
|
@ -170,3 +170,24 @@ get_lan_for_peer(const struct sockaddr * peer)
|
|||
return lan_addr;
|
||||
}
|
||||
|
||||
#if defined(CLOCK_MONOTONIC_FAST)
|
||||
#define UPNP_CLOCKID CLOCK_MONOTONIC_FAST
|
||||
#elif defined(CLOCK_MONOTONIC)
|
||||
#define UPNP_CLOCKID CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: upnputils.h,v 1.2 2014/11/28 16:20:07 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2011-2016 Thomas Bernard
|
||||
* (c) 2011-2019 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
|
@ -29,6 +29,12 @@ set_non_blocking(int fd);
|
|||
struct lan_addr_s *
|
||||
get_lan_for_peer(const struct sockaddr * peer);
|
||||
|
||||
/**
|
||||
* get the time for upnp
|
||||
* Similar to a monotonic gettimeofday(tv, NULL)
|
||||
*/
|
||||
int upnp_gettimeofday(struct timeval * tv);
|
||||
|
||||
/**
|
||||
* define portability macros
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue