1#ifndef KEEL_EVENT_CTX_H
2#define KEEL_EVENT_CTX_H
115 uintptr_t tag = (uintptr_t)event->
udata;
KlError
Diagnostic error codes for Keel public functions.
Definition error.h:11
KlEventMask
Definition event.h:6
int kl_event_ctx_init(KlEventCtx *ctx, KlAllocator *alloc)
Initialize an event context with the given allocator.
void(* KlWatcherFn)(int fd, KlEventMask ready, void *user_data)
Callback invoked when a watched FD becomes ready.
Definition event_ctx.h:17
void kl_watcher_del(KlEventCtx *ctx, int fd)
Remove a watcher and deregister its FD from the event loop.
void kl_event_ctx_free(KlEventCtx *ctx)
Free all watchers and close the event loop.
static int kl_event_dispatch(KlEventCtx *ctx, const KlEvent *event)
Dispatch a single event if it is a watcher (tagged pointer).
Definition event_ctx.h:114
int kl_watcher_mod(KlEventCtx *ctx, int fd, KlEventMask mask)
Change the event interest mask for a registered watcher.
int kl_watcher_rearm(KlEventCtx *ctx, int fd)
Re-arm a watcher after its callback fires.
int kl_watcher_add(KlEventCtx *ctx, int fd, KlEventMask mask, KlWatcherFn on_ready, void *user_data)
Register a file descriptor with the event loop.
int kl_event_ctx_run(KlEventCtx *ctx, int max_events, int timeout_ms)
Run one tick of the event loop, dispatching all watcher events.
Bring-your-own allocator vtable.
Definition allocator.h:12
Composable event loop context.
Definition event_ctx.h:42
KlAllocator * alloc
Definition event_ctx.h:44
int64_t timer_next_id
Definition event_ctx.h:52
KlError last_error
Definition event_ctx.h:47
KlTimerEntry * timers
Definition event_ctx.h:49
int timer_count
Definition event_ctx.h:50
int dispatch_dirty
Definition event_ctx.h:46
int timer_cap
Definition event_ctx.h:51
KlWatcher * watchers
Definition event_ctx.h:45
KlEventLoop loop
Definition event_ctx.h:43
void * udata
Definition event.h:12
KlEventMask ready
Definition event.h:13
Timer heap entry (stored in KlEventCtx.timers array).
Definition timer.h:16
A registered FD watcher (heap-allocated, ctx-owned list).
Definition event_ctx.h:22
struct KlWatcher * next
Definition event_ctx.h:27
void * user_data
Definition event_ctx.h:26
KlWatcherFn on_ready
Definition event_ctx.h:25
KlEventMask mask
Definition event_ctx.h:24
int fd
Definition event_ctx.h:23