From bf55733700d946f678947a6caaa782b56669a3f1 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 29 Mar 2020 15:39:01 +0200 Subject: [PATCH] Add utcp_set_clock_granularity(). This overrides the value gotten from clock_getres(), and is intended for use by an application that knows it might not call utcp_timeout() exactly on time. --- utcp.c | 8 ++++++-- utcp.h | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/utcp.c b/utcp.c index cc17b0f..0b36de1 100644 --- a/utcp.c +++ b/utcp.c @@ -73,7 +73,7 @@ static bool timespec_isset(const struct timespec *a) { return a->tv_sec; } -static long CLOCK_GRANULARITY; +static long CLOCK_GRANULARITY; // usec static inline size_t min(size_t a, size_t b) { return a < b ? a : b; @@ -2056,7 +2056,7 @@ struct utcp *utcp_init(utcp_accept_t accept, utcp_pre_accept_t pre_accept, utcp_ if(!CLOCK_GRANULARITY) { struct timespec res; clock_getres(UTCP_CLOCK, &res); - CLOCK_GRANULARITY = res.tv_sec * NSEC_PER_SEC + res.tv_nsec; + CLOCK_GRANULARITY = res.tv_sec * USEC_PER_SEC + res.tv_nsec / 1000; } utcp->accept = accept; @@ -2331,3 +2331,7 @@ void utcp_offline(struct utcp *utcp, bool offline) { utcp->rto = START_RTO; } } + +void utcp_set_clock_granularity(long granularity) { + CLOCK_GRANULARITY = granularity; +} diff --git a/utcp.h b/utcp.h index 40cfef6..aed177c 100644 --- a/utcp.h +++ b/utcp.h @@ -116,4 +116,8 @@ extern size_t utcp_get_outq(struct utcp_connection *connection); extern void utcp_expect_data(struct utcp_connection *connection, bool expect); +// Completely global options + +extern void utcp_set_clock_granularity(long granularity); + #endif -- 2.39.2