2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__MAIN_SELECT_H
|
|
|
|
#define EL__MAIN_SELECT_H
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
typedef void (*select_handler_T)(void *);
|
|
|
|
|
|
|
|
/* Start the select loop after calling the passed @init() function. */
|
|
|
|
void select_loop(void (*init)(void));
|
|
|
|
|
|
|
|
/* Get information about the number of descriptors being checked by the select
|
|
|
|
* loop. */
|
|
|
|
int get_file_handles_count(void);
|
|
|
|
|
|
|
|
/* Schedule work to be done when appropriate in the future. */
|
|
|
|
int register_bottom_half_do(select_handler_T work_handler, void *data);
|
|
|
|
|
|
|
|
/* Wrapper to remove a lot of casts from users of bottom halves. */
|
|
|
|
#define register_bottom_half(fn, data) \
|
|
|
|
register_bottom_half_do((select_handler_T) (fn), (void *) (data))
|
|
|
|
|
|
|
|
/* Check and run scheduled work. */
|
|
|
|
void check_bottom_halves(void);
|
|
|
|
|
|
|
|
enum select_handler_type {
|
|
|
|
SELECT_HANDLER_READ,
|
|
|
|
SELECT_HANDLER_WRITE,
|
|
|
|
SELECT_HANDLER_ERROR,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get a registered select handler. */
|
|
|
|
select_handler_T get_handler(int fd, enum select_handler_type type);
|
|
|
|
|
2022-02-21 13:03:54 -05:00
|
|
|
void *get_handler_data(int fd);
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
/* Set handlers and callback @data for the @fd descriptor. */
|
|
|
|
void set_handlers(int fd,
|
|
|
|
select_handler_T read_handler,
|
|
|
|
select_handler_T write_handler,
|
|
|
|
select_handler_T error_handler,
|
|
|
|
void *data);
|
|
|
|
|
|
|
|
/* Clear handlers associated with @fd. */
|
|
|
|
#define clear_handlers(fd) \
|
|
|
|
set_handlers(fd, NULL, NULL, NULL, NULL)
|
|
|
|
|
|
|
|
/* Checks which can be used for querying the read/write state of the @fd
|
|
|
|
* descriptor without blocking. The interlink code are the only users. */
|
|
|
|
int can_read(int fd);
|
|
|
|
int can_write(int fd);
|
|
|
|
|
2017-11-12 07:41:31 -05:00
|
|
|
void terminate_select(void);
|
2020-10-05 14:14:55 -04:00
|
|
|
|
2021-12-28 11:49:15 -05:00
|
|
|
const char *get_libevent_version(void);
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|