From 4f239ff00d3e90744ac5721e701c8a1343107ce4 Mon Sep 17 00:00:00 2001 From: Fawzi Mohamed Date: Tue, 27 Mar 2012 19:32:03 +0200 Subject: [PATCH] mdnsd: cope better with large changes in time Large changes in time can happen due to sleep, or long uptime. Maybe calling the sleep hooks should be considered for a future fix. Change-Id: I746c2176a9b36cbafd5679ec1529ad59f8b691b5 Reviewed-by: Daniel Molkentin Reviewed-by: Fawzi Mohamed --- src/tools/mdnssd/mDNSPosix.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tools/mdnssd/mDNSPosix.c b/src/tools/mdnssd/mDNSPosix.c index a1868709dbe..682dc3a28c1 100755 --- a/src/tools/mdnssd/mDNSPosix.c +++ b/src/tools/mdnssd/mDNSPosix.c @@ -1441,6 +1441,12 @@ mDNSexport void mDNSPosixGetFDSet(mDNS *m, int *nfds, fd_set *readfds, struct ti if (timeout->tv_sec > interval.tv_sec || (timeout->tv_sec == interval.tv_sec && timeout->tv_usec > interval.tv_usec)) *timeout = interval; + // cope well with vey large changes in time (for example after sleep) + if (timeout->tv_sec > 1000) timeout->tv_sec = 1000; + if (timeout->tv_usec > 999999) timeout->tv_usec = 999999; + // should not happen, but let's be paranoid... + if (timeout->tv_sec < 0) timeout->tv_sec = 0; + if (timeout->tv_usec < 0) timeout->tv_usec = 1000; } mDNSexport void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds)