summaryrefslogtreecommitdiff
path: root/ot_timeout.h
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2026-10-25 22:56:34 +0100
committerDirk Engling <erdgeist@erdgeist.org>2026-10-25 22:56:34 +0100
commit2e5b19945eb03fe4e3fa47562888401c7cbae71d (patch)
tree45daefea693c483a943f3f205405b1019fe9e426 /ot_timeout.h
parent0e3a2189f65354962fc71af41f5aa52261a782e8 (diff)
Factor out the timeout setter, will probably go later once we do the io loop ourselfHEADmaster
Diffstat (limited to 'ot_timeout.h')
-rw-r--r--ot_timeout.h39
1 files changed, 39 insertions, 0 deletions
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 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever.
3
4 $id$ */
5
6#ifndef OT_TIMEOUT_H__
7#define OT_TIMEOUT_H__
8
9#include <stdint.h>
10#include <string.h>
11
12/* Libowfat */
13#include "io.h"
14
15#include "trackerlogic.h"
16
17/* io_timeout wants an absolute TAI64 deadline and io_timeouted skips any
18 socket whose deadline is zero, so that is how a socket is told to wait
19 indefinitely.
20
21 The deadline is taken from the cached clock rather than from
22 gettimeofday, which is too expensive to call at this rate on FreeBSD. */
23
24static inline void timeout_never(int64_t sock) {
25 tai6464 t;
26
27 memset(&t, 0, sizeof(t));
28 io_timeout(sock, t);
29}
30
31static inline void timeout_in(int64_t sock, unsigned int seconds) {
32 tai6464 t;
33
34 memset(&t, 0, sizeof(t));
35 tai_unix(&t.sec, g_now_seconds + seconds);
36 io_timeout(sock, t);
37}
38
39#endif