Wrapper functions for epoll to manage event-based communication. More...
#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
Functions | |
int | enable_epoll (int epoll_fd, int new_fd, uint32_t events) |
Enables a file descriptor which has already been aded to an epoll instance. More... | |
int | add_to_epoll (int epoll_fd, int new_fd, uint32_t events, bool oneshot) |
Adds a file descriptor to an epoll instance. More... | |
int | epoll_loop (int socket_fd, int epoll_fd, int batch_size, int timeout, bool oneshot, int(*connection_handler)(int, void *), int(*accept_handler)(int, void *), void *data) |
The event-based loop for epoll_wait. More... | |
int | init_epoll (int socket_fd) |
Initializes a new instance of an epoll file descriptor and adds a socket to it, listening for input on that socket. More... | |
Wrapper functions for epoll to manage event-based communication.
Definition in file epollops.h.
int add_to_epoll | ( | int | epoll_fd, |
int | new_fd, | ||
uint32_t | events, | ||
bool | oneshot | ||
) |
Adds a file descriptor to an epoll instance.
epoll_fd | Epoll file descriptor |
new_fd | File descriptor to add to the epoll instance |
events | EPOLLIN &/| EPOLLOUT |
oneshot | Whether to enable EPOLLONESHOT on the added fd |
Definition at line 59 of file epollops.c.
int enable_epoll | ( | int | epoll_fd, |
int | new_fd, | ||
uint32_t | events | ||
) |
Enables a file descriptor which has already been aded to an epoll instance.
Or's EPOLLONESHOT with events so the event will only be responded to once
epoll_fd | Epoll file descriptor |
new_fd | File descriptor to enable in the epoll instance |
events | EPOLLIN &/| EPOLLOUT |
Definition at line 42 of file epollops.c.
int epoll_loop | ( | int | socket_fd, |
int | epoll_fd, | ||
int | batch_size, | ||
int | timeout, | ||
bool | oneshot, | ||
int(*)(int, void *) | connection_handler, | ||
int(*)(int, void *) | accept_handler, | ||
void * | data | ||
) |
The event-based loop for epoll_wait.
Loops (epolling), and accepts new connections when they are available on socket_fd. Calls the provided functions on socket activity (connection_handler), and on new connections (accept_handler). NOTE: On first connect, only calls connection_handler
on EPOLLIN activity.
socket_fd | Socket on which to accept new connections, or -1 if no accept is necessary |
epoll_fd | Fd of epoll instance |
batch_size | Number of connections to process in a row before exiting the loop or -1 for NA |
timeout | Epoll timeout. -1 for no timeout. |
connection_handler | Calls this function with args (int fd, void *data) on fd activity |
accept_handler | Calls this function with args (int fd, void *data) on new connection NULL for no callback or N/A |
data | Data to be passed through to handler functions |
Definition at line 132 of file epollops.c.
int init_epoll | ( | int | socket_fd | ) |
Initializes a new instance of an epoll file descriptor and adds a socket to it, listening for input on that socket.
socket_fd | Socket on which to listen for new connections. -1 if creating epoll without socket. |
Definition at line 182 of file epollops.c.