watcher: Add a method to query the watcher state
This allows a user to check if the watcher is actually running, and potentially perform read operations directly instead of relying on watcher.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
typedef struct watcher_t watcher_t;
|
||||
typedef enum watcher_event_t watcher_event_t;
|
||||
typedef enum watcher_state_t watcher_state_t;
|
||||
|
||||
#include <library.h>
|
||||
|
||||
@@ -56,6 +57,18 @@ enum watcher_event_t {
|
||||
WATCHER_EXCEPT = (1<<2),
|
||||
};
|
||||
|
||||
/**
|
||||
* State the watcher currently is in
|
||||
*/
|
||||
enum watcher_state_t {
|
||||
/** no watcher thread running or queued */
|
||||
WATCHER_STOPPED = 0,
|
||||
/** a job has been queued for watching, but not yet started */
|
||||
WATCHER_QUEUED,
|
||||
/** a watcher thread is active, dispatching socket events */
|
||||
WATCHER_RUNNING,
|
||||
};
|
||||
|
||||
/**
|
||||
* Watch multiple file descriptors using select().
|
||||
*/
|
||||
@@ -85,6 +98,13 @@ struct watcher_t {
|
||||
*/
|
||||
void (*remove)(watcher_t *this, int fd);
|
||||
|
||||
/**
|
||||
* Get the current watcher state
|
||||
*
|
||||
* @reutrn currently active watcher state
|
||||
*/
|
||||
watcher_state_t (*get_state)(watcher_t *this);
|
||||
|
||||
/**
|
||||
* Destroy a watcher_t.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user