From 2e5b19945eb03fe4e3fa47562888401c7cbae71d Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sun, 25 Oct 2026 22:56:34 +0100 Subject: Factor out the timeout setter, will probably go later once we do the io loop ourself --- ot_timeout.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ot_timeout.h (limited to 'ot_timeout.h') diff --git a/ot_timeout.h b/ot_timeout.h new file mode 100644 index 0000000..1027c2e --- /dev/null +++ b/ot_timeout.h @@ -0,0 +1,39 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +#ifndef OT_TIMEOUT_H__ +#define OT_TIMEOUT_H__ + +#include +#include + +/* Libowfat */ +#include "io.h" + +#include "trackerlogic.h" + +/* io_timeout wants an absolute TAI64 deadline and io_timeouted skips any + socket whose deadline is zero, so that is how a socket is told to wait + indefinitely. + + The deadline is taken from the cached clock rather than from + gettimeofday, which is too expensive to call at this rate on FreeBSD. */ + +static inline void timeout_never(int64_t sock) { + tai6464 t; + + memset(&t, 0, sizeof(t)); + io_timeout(sock, t); +} + +static inline void timeout_in(int64_t sock, unsigned int seconds) { + tai6464 t; + + memset(&t, 0, sizeof(t)); + tai_unix(&t.sec, g_now_seconds + seconds); + io_timeout(sock, t); +} + +#endif -- cgit v1.3