Commit d708ef67 authored by Yang Tse's avatar Yang Tse
Browse files

Use monotonic time source if available.

parent d1238bae
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
  Changelog for the c-ares project

* May 9 2008 (Yang Tse)

- Use monotonic time source if available, for private function ares__tvnow()

* May 7 2008 (Daniel Stenberg)

- Sebastian made c-ares able to return all PTR-records when doing reverse
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ ares_timeout.c ares_destroy.c ares_mkquery.c ares_version.c \
ares_expand_name.c ares_parse_a_reply.c windows_port.c			\
ares_expand_string.c ares_parse_ptr_reply.c ares_parse_aaaa_reply.c	\
ares_getnameinfo.c inet_net_pton.c bitncmp.c inet_ntop.c		\
ares_parse_ns_reply.c ares_llist.c
ares_parse_ns_reply.c ares_llist.c ares__timeval.c

HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h          \
           nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h      \
+4 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ OBJECTS = $(OBJ_DIR)\ares_fds.obj \
          $(OBJ_DIR)\ares_init.obj             \
          $(OBJ_DIR)\ares_llist.obj            \
          $(OBJ_DIR)\ares_timeout.obj          \
          $(OBJ_DIR)\ares__timeval.obj         \
          $(OBJ_DIR)\ares_destroy.obj          \
          $(OBJ_DIR)\ares_mkquery.obj          \
          $(OBJ_DIR)\ares_version.obj          \
@@ -122,7 +123,6 @@ $(DEF_FILE): $(OBJECTS) Makefile.VC6
       @echo   ares_inet_pton         >> $@
       @echo   ares_writev            >> $@
       @echo   ares_getnameinfo       >> $@
       @echo   ares_gettimeofday      >> $@
       @echo   ares_parse_aaaa_reply  >> $@

ahost.exe: $(OBJ_DIR) $(OBJ_DIR)\ahost.obj $(OBJ_DIR)\ares_getopt.obj cares_imp.lib
@@ -193,6 +193,9 @@ $(OBJ_DIR)\ares_init.obj: ares_init.c setup.h setup_once.h nameser.h ares.h \
$(OBJ_DIR)\ares_timeout.obj: ares_timeout.c setup.h setup_once.h ares.h        \
  ares_private.h ares_ipv6.h

$(OBJ_DIR)\ares__timeval.obj: ares__timeval.c setup.h setup_once.h ares.h      \
  ares_private.h ares_ipv6.h

$(OBJ_DIR)\ares_destroy.obj: ares_destroy.c setup.h setup_once.h ares.h        \
  ares_private.h ares_ipv6.h

+1 −0
Original line number Diff line number Diff line
This is what's new and changed in the c-ares 1.5.2 release:

 o improved parsing of resolver configuration files
 o use monotonic time source if available

Thanks go to these friendly people for their efforts and contributions:

ares/ares__timeval.c

0 → 100644
+95 −0
Original line number Diff line number Diff line
/* $Id$ */

/* Copyright (C) 2008 by Daniel Stenberg et al
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of M.I.T. not be used in advertising or
 * publicity pertaining to distribution of the software without specific,
 * written prior permission.  M.I.T. makes no representations about the
 * suitability of this software for any purpose.  It is provided "as is"
 * without express or implied warranty.
 */

#include "setup.h"
#include "ares.h"
#include "ares_private.h"

#if defined(WIN32) && !defined(MSDOS)

struct timeval ares__tvnow(void)
{
  /*
  ** GetTickCount() is available on _all_ Windows versions from W95 up
  ** to nowadays. Returns milliseconds elapsed since last system boot,
  ** increases monotonically and wraps once 49.7 days have elapsed.
  */
  struct timeval now;
  DWORD milliseconds = GetTickCount();
  now.tv_sec = milliseconds / 1000;
  now.tv_usec = (milliseconds % 1000) * 1000;
  return now;
}

#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)

struct timeval ares__tvnow(void)
{
  /*
  ** clock_gettime() is granted to be increased monotonically when the
  ** monotonic clock is queried. Time starting point is unspecified, it
  ** could be the system start-up time, the Epoch, or something else,
  ** in any case the time starting point does not change once that the
  ** system has started up.
  */
  struct timeval now;
  struct timespec tsnow;
  (void)clock_gettime(CLOCK_MONOTONIC, &tsnow)
  now.tv_sec = tsnow.tv_sec;
  now.tv_usec = tsnow.tv_nsec / 1000;
  return now;
}

#elif defined(HAVE_GETTIMEOFDAY)

struct timeval ares__tvnow(void)
{
  /*
  ** gettimeofday() is not granted to be increased monotonically, due to
  ** clock drifting and external source time synchronization it can jump
  ** forward or backward in time.
  */
  struct timeval now;
  (void)gettimeofday(&now, NULL);
  return now;
}

#else

struct timeval ares__tvnow(void)
{
  /*
  ** time() returns the value of time in seconds since the Epoch.
  */
  struct timeval now;
  now.tv_sec = (long)time(NULL);
  now.tv_usec = 0;
  return now;
}

#endif

/*
 * Make sure that the first argument is the more recent time, as otherwise
 * we'll get a weird negative time-diff back...
 *
 * Returns: the time difference in number of milliseconds.
 */
long ares__tvdiff(struct timeval newer, struct timeval older)
{
  return (newer.tv_sec-older.tv_sec)*1000+
    (newer.tv_usec-older.tv_usec)/1000;
}
Loading