Browse Source

[master]Merge branch 'trac1526'

Jeremy C. Reed 13 years ago
parent
commit
235a2af717
3 changed files with 36 additions and 1 deletions
  1. 4 0
      configure.ac
  2. 2 1
      tests/tools/perfdhcp/Makefile.am
  3. 30 0
      tests/tools/perfdhcp/perfdhcp.c

+ 4 - 0
configure.ac

@@ -831,6 +831,10 @@ EV_SET(NULL, 0, 0, 0, 0, 0, udata);],
 	])
 fi
 
+CLOCK_GETTIME_LDFLAGS=
+AC_CHECK_LIB([rt], [clock_gettime], [CLOCK_GETTIME_LDFLAGS=-lrt], [])
+AC_SUBST([CLOCK_GETTIME_LDFLAGS])
+
 # /dev/poll issue: ASIO uses /dev/poll by default if it's available (generally
 # the case with Solaris).  Unfortunately its /dev/poll specific code would
 # trigger the gcc's "missing-field-initializers" warning, which would

+ 2 - 1
tests/tools/perfdhcp/Makefile.am

@@ -2,7 +2,8 @@ SUBDIRS = .
 
 AM_CXXFLAGS = $(B10_CXXFLAGS)
 
-AM_LDFLAGS = -lrt -lm
+AM_LDFLAGS = $(CLOCK_GETTIME_LDFLAGS)
+AM_LDFLAGS += -lm
 if USE_STATIC_LINK
 AM_LDFLAGS += -static
 endif

+ 30 - 0
tests/tools/perfdhcp/perfdhcp.c

@@ -362,6 +362,36 @@ size_t random_request6;
 size_t serverid_request6;
 size_t reqaddr_request6;
 
+
+// use definition of CLOCK_REALTIME (or lack of thereof) as an indicator
+// if the code is being compiled or Linux (or somewhere else)
+// Perhaps this should be based on OS_LINUX define?
+
+#if !defined (CLOCK_REALTIME)
+#define CLOCK_REALTIME 0
+
+/// @brief clock_gettime implementation for non-Linux systems
+///
+/// This implementation lacks nanosecond resolution. It is intended
+/// to be used on non-Linux systems that does not provide clock_gettime
+/// implementation.
+///
+/// @param clockid ignored (kept for Linux prototype compatibility)
+/// @param tp timespec structure
+///
+/// @return always zero (kept for compatibility reasons)
+int clock_gettime(int clockid, struct timespec *tp) {
+
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    tp->tv_sec = tv.tv_sec;
+    tp->tv_nsec = tv.tv_usec*1000;
+
+    return (0);
+}
+
+#endif
+
 /*
  * initialize data structures handling exchanges
  */