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