60 lines
1.1 KiB
C
60 lines
1.1 KiB
C
#ifndef __EVENT_LOOP_H
|
|
#define __EVENT_LOOP_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/epoll.h>
|
|
#include <unistd.h>
|
|
|
|
/*
|
|
* Type definitions
|
|
*/
|
|
typedef void (*loop_cb_t)(int fd, uint32_t events);
|
|
|
|
/*
|
|
* Public API
|
|
*/
|
|
// Initialize the event loop.
|
|
// Parameters:
|
|
// - callback - callback to use in loop_wait
|
|
// Returns:
|
|
// - true on success
|
|
// - false on failure
|
|
// Remarks:
|
|
// - must be called before event loop is used
|
|
bool loop_init(loop_cb_t callback);
|
|
|
|
// Finalize the event loop.
|
|
// - must be called on app termination
|
|
void loop_deinit();
|
|
|
|
// Set callback for file descriptor event.
|
|
// Remarks:
|
|
// - this callback gets called in loop_wait
|
|
void loop_set_callback(loop_cb_t callback);
|
|
|
|
// Call epoll_ctl.
|
|
// Parameters:
|
|
// - op - op
|
|
// - fd - fd
|
|
// - event - event
|
|
// Returns:
|
|
// - true on success
|
|
// - false on failure
|
|
// Remarks:
|
|
// - just calls epoll_ctl
|
|
bool loop_ctl(int op, int fd, struct epoll_event *event);
|
|
|
|
// Call epoll_wait and process the events.
|
|
// Returns:
|
|
// - true on success
|
|
// - false on failure
|
|
// Remarks:
|
|
// - you should terminate the app if this function
|
|
// fails
|
|
bool loop_wait();
|
|
|
|
|
|
#endif
|