aboutsummaryrefslogtreecommitdiff
path: root/include/poller.h
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-31 01:33:41 +0200
committerKenny Levinsen <kl@kl.wtf>2020-08-31 01:33:41 +0200
commit7d88315fea1448fc3f0e33c7a8a00ec12458b473 (patch)
tree94c579f7021251e079d8e6b7ecdecb9fce2029b6 /include/poller.h
parent8e1bf10d9decab347455b3036143b21d7f90d390 (diff)
poller: Make event sources opaque
Diffstat (limited to 'include/poller.h')
-rw-r--r--include/poller.h74
1 files changed, 23 insertions, 51 deletions
diff --git a/include/poller.h b/include/poller.h
index 6b727c4..0142add 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -6,10 +6,6 @@
#include "list.h"
-struct poller;
-struct event_source_fd;
-struct event_source_signal;
-
/*
* These are the event types available from the poller.
*/
@@ -19,6 +15,16 @@ struct event_source_signal;
#define EVENT_HANGUP 0x10
/**
+ * The fd poller class. This must be created by poller_add_fd.
+ */
+struct event_source_fd;
+
+/*
+ * The signal poller class. This must be created by poller_add_signal.
+ */
+struct event_source_signal;
+
+/**
* The callback type used by event_source_fd, passed to poller_add_fd.
*/
typedef int (*event_source_fd_func_t)(int fd, uint32_t mask, void *data);
@@ -32,21 +38,6 @@ struct event_source_fd_impl {
};
/**
- * The fd poller class. This must be created by poller_add_fd.
- */
-struct event_source_fd {
- const struct event_source_fd_impl *impl;
- event_source_fd_func_t func;
-
- int fd;
- uint32_t mask;
- void *data;
-
- struct poller *poller;
- bool killed;
-};
-
-/**
* Removes the event_source_fd from the poller and frees the structure.
*/
int event_source_fd_destroy(struct event_source_fd *event_source);
@@ -68,42 +59,12 @@ struct event_source_signal_impl {
int (*destroy)(struct event_source_signal *event_source);
};
-/*
- * The signal poller class. This must be created by poller_add_signal.
- */
-struct event_source_signal {
- const struct event_source_signal_impl *impl;
- event_source_signal_func_t func;
-
- int signal;
- void *data;
-
- struct poller *poller;
- bool raised;
- bool killed;
-};
-
/**
* Removes the event_source_siganl from the poller and frees the structure.
*/
int event_source_signal_destroy(struct event_source_signal *event_source);
/**
- * The interface that a poll backend must implement.
- */
-struct poll_impl {
- struct poller *(*create)(void);
- int (*destroy)(struct poller *);
-
- struct event_source_fd *(*add_fd)(struct poller *, int fd, uint32_t mask,
- event_source_fd_func_t func, void *data);
- struct event_source_signal *(*add_signal)(struct poller *, int signal,
- event_source_signal_func_t func, void *data);
-
- int (*poll)(struct poller *);
-};
-
-/**
* The poller base class. This must be created by poller_create.
*/
struct poller {
@@ -119,9 +80,20 @@ struct poller {
};
/**
- * Creates a poller with the best available polling backend. This poller must
- * be torn down with poller_destroy when it is no longer needed.
+ * The interface that a poll backend must implement.
*/
+struct poll_impl {
+ struct poller *(*create)(void);
+ int (*destroy)(struct poller *);
+
+ struct event_source_fd *(*add_fd)(struct poller *, int fd, uint32_t mask,
+ event_source_fd_func_t func, void *data);
+ struct event_source_signal *(*add_signal)(struct poller *, int signal,
+ event_source_signal_func_t func, void *data);
+
+ int (*poll)(struct poller *);
+};
+
/**
* Initializes the poller. The poller must be torn down with poller_finish when
* it is no longer needed.