poller: Make event sources opaque
This commit is contained in:
parent
8e1bf10d9d
commit
7d88315fea
2 changed files with 47 additions and 51 deletions
|
@ -6,10 +6,6 @@
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
struct poller;
|
|
||||||
struct event_source_fd;
|
|
||||||
struct event_source_signal;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* These are the event types available from the poller.
|
* These are the event types available from the poller.
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +14,16 @@ struct event_source_signal;
|
||||||
#define EVENT_ERROR 0x8
|
#define EVENT_ERROR 0x8
|
||||||
#define EVENT_HANGUP 0x10
|
#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.
|
* The callback type used by event_source_fd, passed to poller_add_fd.
|
||||||
*/
|
*/
|
||||||
|
@ -31,21 +37,6 @@ struct event_source_fd_impl {
|
||||||
int (*destroy)(struct event_source_fd *event_source);
|
int (*destroy)(struct event_source_fd *event_source);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Removes the event_source_fd from the poller and frees the structure.
|
||||||
*/
|
*/
|
||||||
|
@ -68,41 +59,11 @@ struct event_source_signal_impl {
|
||||||
int (*destroy)(struct event_source_signal *event_source);
|
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.
|
* Removes the event_source_siganl from the poller and frees the structure.
|
||||||
*/
|
*/
|
||||||
int event_source_signal_destroy(struct event_source_signal *event_source);
|
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.
|
* The poller base class. This must be created by poller_create.
|
||||||
*/
|
*/
|
||||||
|
@ -119,9 +80,20 @@ struct poller {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a poller with the best available polling backend. This poller must
|
* The interface that a poll backend must implement.
|
||||||
* be torn down with poller_destroy when it is no longer needed.
|
|
||||||
*/
|
*/
|
||||||
|
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
|
* Initializes the poller. The poller must be torn down with poller_finish when
|
||||||
* it is no longer needed.
|
* it is no longer needed.
|
||||||
|
|
|
@ -10,6 +10,30 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "poller.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 */
|
/* Used for signal handling */
|
||||||
struct poller *global_poller = NULL;
|
struct poller *global_poller = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue