Use gettimeofday() instead of clock_gettime()
This commit is contained in:
@@ -9,8 +9,6 @@ AM_SILENT_RULES([yes])
|
||||
AC_CONFIG_SRCDIR([common.h])
|
||||
AC_PROG_CC_C99
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
AC_SEARCH_LIBS([clock_gettime], [rt],
|
||||
[AC_DEFINE(HAVE_CLOCK_GETTIME,[1],[define if you have clock_gettime()])])
|
||||
AC_SEARCH_LIBS([getaddrinfo], [resolv nsl])
|
||||
AC_SEARCH_LIBS([socket], [socket])
|
||||
PKG_CHECK_MODULES([libsodium], [libsodium >= 1.0.4])
|
||||
|
||||
20
main.c
20
main.c
@@ -6,8 +6,8 @@
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <poll.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -22,10 +22,6 @@
|
||||
|
||||
#include <sodium.h>
|
||||
|
||||
#if !defined(CLOCK_MONOTONIC_COARSE) && defined(CLOCK_MONOTONIC)
|
||||
# define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
|
||||
#endif
|
||||
|
||||
#define GT_BUFFER_SIZE (4*1024*1024)
|
||||
|
||||
struct netio {
|
||||
@@ -44,11 +40,11 @@ struct crypto_ctx {
|
||||
|
||||
volatile sig_atomic_t running;
|
||||
|
||||
static int64_t dt_ms (struct timespec *ta, struct timespec *tb)
|
||||
static int64_t dt_ms (struct timeval *ta, struct timeval *tb)
|
||||
{
|
||||
const int64_t s = ta->tv_sec-tb->tv_sec;
|
||||
const int64_t n = ta->tv_nsec-tb->tv_nsec;
|
||||
return s*1000LL+n/1000000LL;
|
||||
const int64_t n = ta->tv_usec-tb->tv_usec;
|
||||
return s*1000LL+n/1000LL;
|
||||
}
|
||||
|
||||
static void fd_set_nonblock (int fd)
|
||||
@@ -555,7 +551,7 @@ int main (int argc, char **argv)
|
||||
|
||||
#ifdef TCP_INFO
|
||||
struct {
|
||||
struct timespec time;
|
||||
struct timeval time;
|
||||
struct tcp_info info;
|
||||
} tcpinfo = {0};
|
||||
#endif
|
||||
@@ -656,9 +652,9 @@ int main (int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if defined(CLOCK_MONOTONIC_COARSE) && defined(TCP_INFO)
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &now);
|
||||
#ifdef TCP_INFO
|
||||
struct timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
if (dt_ms(&now, &tcpinfo.time)>1000LL) {
|
||||
tcpinfo.time = now;
|
||||
|
||||
Reference in New Issue
Block a user