My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
epollops.h File Reference

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...
 

Detailed Description

Wrapper functions for epoll to manage event-based communication.

Definition in file epollops.h.

Function Documentation

int add_to_epoll ( int  epoll_fd,
int  new_fd,
uint32_t  events,
bool  oneshot 
)

Adds a file descriptor to an epoll instance.

Parameters
epoll_fdEpoll file descriptor
new_fdFile descriptor to add to the epoll instance
eventsEPOLLIN &/| EPOLLOUT
oneshotWhether to enable EPOLLONESHOT on the added fd
Returns
0 on success, -1 on error

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

Parameters
epoll_fdEpoll file descriptor
new_fdFile descriptor to enable in the epoll instance
eventsEPOLLIN &/| EPOLLOUT
Returns
0 on success, -1 on error

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.

Parameters
socket_fdSocket on which to accept new connections, or -1 if no accept is necessary
epoll_fdFd of epoll instance
batch_sizeNumber of connections to process in a row before exiting the loop or -1 for NA
timeoutEpoll timeout. -1 for no timeout.
connection_handlerCalls this function with args (int fd, void *data) on fd activity
accept_handlerCalls this function with args (int fd, void *data) on new connection NULL for no callback or N/A
dataData to be passed through to handler functions
Returns
0 on success, -1 on error

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.

Parameters
socket_fdSocket on which to listen for new connections. -1 if creating epoll without socket.
Returns
epoll file descriptor

Definition at line 182 of file epollops.c.