diff options
-rw-r--r-- | include/poller.h | 74 | ||||
-rw-r--r-- | seatd/poller.c | 24 |
2 files changed, 47 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. diff --git a/seatd/poller.c b/seatd/poller.c index f786d47..0631f4b 100644 --- a/seatd/poller.c +++ b/seatd/poller.c @@ -10,6 +10,30 @@ #include "list.h" #include "poller.h" +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; +}; + +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; +}; + /* Used for signal handling */ struct poller *global_poller = NULL; |