Commit 4de0dabc authored by Marek Vavrusa's avatar Marek Vavrusa

Bugfixes for OS X.

parent f0fadee7
......@@ -111,7 +111,7 @@ AC_SEARCH_LIBS([pow], [m])
AC_SEARCH_LIBS([pthread_create], [pthread], [], [AC_MSG_ERROR([pthreads not found])])
AC_SEARCH_LIBS([rcu_set_pointer_sym], [urcu], [], [AC_MSG_ERROR([liburcu not found])])
AC_SEARCH_LIBS([dlopen], [dl])
AC_SEARCH_LIBS([clock_gettime], [rt], [], [AC_MSG_ERROR([librt not found])])
AC_SEARCH_LIBS([clock_gettime], [rt])
AC_SEARCH_LIBS([OpenSSL_add_all_digests], [crypto],[], [AC_MSG_ERROR([libcrypto not found])])
#AC_SEARCH_LIBS([ldns_rr_list_pop_rrset], [ldns], [], [AC_MSG_ERROR([libldns not found])])
......@@ -137,7 +137,7 @@ AC_DEFINE([DSFMT_MEXP], [521], [DSFMT parameters.])
# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MMAP
AC_CHECK_FUNCS([gethostbyname gettimeofday memmove memset munmap regcomp pselect select socket sqrt strcasecmp strchr strdup strerror strncasecmp strtol strtoul poll epoll_wait kqueue setgroups])
AC_CHECK_FUNCS([gethostbyname gettimeofday clock_gettime memalign memmove memset munmap regcomp pselect select socket sqrt strcasecmp strchr strdup strerror strncasecmp strtol strtoul poll epoll_wait kqueue setgroups])
AC_CONFIG_FILES([Makefile
samples/Makefile
......
......@@ -26,6 +26,17 @@
#include "common/fdset.h"
#include <config.h>
/* Workarounds for clock_gettime() not available on some platforms. */
#ifdef HAVE_CLOCK_GETTIME
#define time_now(x) clock_gettime(CLOCK_MONOTONIC, (x))
typedef struct timespec timev_t;
#elif HAVE_GETTIMEOFDAY
#define time_now(x) gettimeofday((x), NULL)
typedef struct timeval timev_t;
#else
#error Neither clock_gettime() nor gettimeofday() found. At least one is required.
#endif
struct fdset_backend_t _fdset_backend = {
};
......@@ -142,10 +153,10 @@ int fdset_set_watchdog(fdset_t* fdset, int fd, int interval)
}
/* Find if exists. */
struct timespec *ts = NULL;
ts = (struct timespec*)skip_find(base->atimes, (void*)((size_t)fd));
timev_t *ts = NULL;
ts = (timev_t*)skip_find(base->atimes, (void*)((size_t)fd));
if (ts == NULL) {
ts = malloc(sizeof(struct timespec));
ts = malloc(sizeof(timev_t));
if (ts == NULL) {
return -1;
}
......@@ -153,7 +164,7 @@ int fdset_set_watchdog(fdset_t* fdset, int fd, int interval)
}
/* Update clock. */
if (clock_gettime(CLOCK_MONOTONIC, ts) < 0) {
if (time_now(ts) < 0) {
return -1;
}
......@@ -169,8 +180,8 @@ int fdset_sweep(fdset_t* fdset, void(*cb)(fdset_t*, int))
}
/* Get time threshold. */
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) {
timev_t now;
if (time_now(&now) < 0) {
return -1;
}
......@@ -181,7 +192,7 @@ int fdset_sweep(fdset_t* fdset, void(*cb)(fdset_t*, int))
const skip_node_t* pnext = skip_next(n);
/* Evaluate */
struct timespec *ts = (struct timespec*)n->value;
timev_t *ts = (timev_t*)n->value;
if (ts->tv_sec <= now.tv_sec) {
cb(fdset, (int)(((ssize_t)n->key)));
++sweeped;
......
......@@ -20,7 +20,9 @@
#include <pthread.h>
#include <time.h>
#include <sys/time.h>
#ifdef HAVE_MEMALIGN
#include <malloc.h>
#endif
#include "prng.h"
#include "dSFMT.h"
......@@ -80,7 +82,7 @@ double tls_rand()
}
/* Initialize PRNG state. */
#ifdef __APPLE__
#ifndef HAVE_MEMALIGN
s = malloc(sizeof(dsfmt_t));
#else
s = memalign(16, sizeof(dsfmt_t));
......
......@@ -37,6 +37,18 @@
#include "knot/other/error.h"
#include "libknot/util/wire.h"
/* Workarounds for clock_gettime() not available on some platforms. */
#ifdef HAVE_CLOCK_GETTIME
#define time_now(x) clock_gettime(CLOCK_MONOTONIC, (x))
typedef struct timespec timev_t;
#elif HAVE_GETTIMEOFDAY
#define time_now(x) gettimeofday((x), NULL)
typedef struct timeval timev_t;
#else
#error Neither clock_gettime() nor gettimeofday() found. At least one is required.
#endif
/* Defines */
#define TCP_BUFFER_SIZE 65535 /*! Do not change, as it is used for maximum DNS/TCP packet size. */
......@@ -488,8 +500,8 @@ int tcp_loop_worker(dthread_t *thread)
}
/* Next sweep time. */
struct timespec next_sweep;
clock_gettime(CLOCK_MONOTONIC, &next_sweep);
timev_t next_sweep;
time_now(&next_sweep);
next_sweep.tv_sec += TCP_SWEEP_INTERVAL;
/* Accept clients. */
......@@ -550,8 +562,8 @@ int tcp_loop_worker(dthread_t *thread)
}
/* Sweep inactive. */
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) {
timev_t now;
if (time_now(&now) == 0) {
if (now.tv_sec >= next_sweep.tv_sec) {
fdset_sweep(w->fdset, &tcp_sweep);
memcpy(&next_sweep, &now, sizeof(next_sweep));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment