From f2f5b0450d4b7269bafdfb1bd1788303f6d8ce7b Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 26 Oct 2026 19:05:22 +0100 Subject: Add poll/epoll/kqueue wrapper to wait for events --- ot_event.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ot_event.h (limited to 'ot_event.h') diff --git a/ot_event.h b/ot_event.h new file mode 100644 index 0000000..c1627ab --- /dev/null +++ b/ot_event.h @@ -0,0 +1,39 @@ +/* This software was written by Dirk Engling + It is considered beerware. Prost. Skol. Cheers or whatever. + + $id$ */ + +#ifndef OT_EVENT_H__ +#define OT_EVENT_H__ + +#include + +/* Which descriptors have become readable or writable, asked of whichever + mechanism the kernel offers. The generation a descriptor was registered + with is handed back with every event, so a caller can tell an event for + the connection it is holding from one for a connection that has since been + closed and had its number reused. */ + +enum { EVENT_READ = 1, EVENT_WRITE = 2 }; + +typedef struct { + int fd; + uint32_t generation; + int what; +} ot_event; + +int event_init(void); +void event_deinit(void); + +int event_add(int fd, int what, uint32_t generation); +int event_modify(int fd, int what, uint32_t generation); +int event_del(int fd); + +/* Waits at most timeout_ms, or indefinitely when that is negative, and fills + out with up to max ready descriptors. Returns how many, or -1. */ +int event_wait(ot_event *out, int max, int timeout_ms); + +/* Which mechanism was compiled in, for the version string */ +const char *event_mechanism(void); + +#endif -- cgit v1.3