summaryrefslogtreecommitdiff
path: root/ot_timeout.h
blob: 1027c2e1a96ec81f91057a824ec01b38e26c665c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
   It is considered beerware. Prost. Skol. Cheers or whatever.

   $id$ */

#ifndef OT_TIMEOUT_H__
#define OT_TIMEOUT_H__

#include <stdint.h>
#include <string.h>

/* 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