summaryrefslogtreecommitdiff
path: root/src/ot_event.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ot_event.h')
-rw-r--r--src/ot_event.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/ot_event.h b/src/ot_event.h
new file mode 100644
index 0000000..cb84ca8
--- /dev/null
+++ b/src/ot_event.h
@@ -0,0 +1,47 @@
1/* This software was written by Dirk Engling <erdgeist@erdgeist.org>
2 It is considered beerware. Prost. Skol. Cheers or whatever. */
3
4#ifndef OT_EVENT_H__
5#define OT_EVENT_H__
6
7#include <stdint.h>
8
9/* Which descriptors have become readable or writable, asked of whichever
10 mechanism the kernel offers. The generation a descriptor was registered
11 with is handed back with every event, so a caller can tell an event for
12 the connection it is holding from one for a connection that has since been
13 closed and had its number reused. */
14
15enum { EVENT_IN = 1, EVENT_OUT = 2 };
16
17typedef struct {
18 int fd;
19 uint32_t generation;
20 int what;
21} ot_event;
22
23int event_init(void);
24void event_deinit(void);
25
26int event_add(int fd, int what, uint32_t generation);
27int event_modify(int fd, int what, uint32_t generation);
28int event_del(int fd);
29
30/* Stop watching a descriptor and close it. Where the kernel drops a closed
31 descriptor from its set by itself, this is one system call where doing the
32 two separately would be two. */
33int event_close(int fd);
34
35/* Waits at most timeout_ms, or indefinitely when that is negative, and fills
36 out with up to max ready descriptors. Returns how many, or -1. */
37int event_wait(ot_event *out, int max, int timeout_ms);
38
39/* Whether the registered set may be changed from another thread while this
40 one is waiting on it. True where the kernel keeps the set, false where
41 this module keeps it in memory of its own. */
42int event_can_share(void);
43
44/* Which mechanism was compiled in, for the version string */
45const char *event_mechanism(void);
46
47#endif