libonion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Enumerations | Functions
Poller. Queues files until ready to read/write and call a handler.

Data Structures

struct  onion_poller_t
 Manages the polling on a set of file descriptors. More...

Enumerations

enum  onion_poller_slot_type_e { O_POLL_READ = 1, O_POLL_WRITE = 2, O_POLL_OTHER = 4, O_POLL_ALL = 7 }

Functions

void onion_poller_slot_set_type (onion_poller_slot *el, onion_poller_slot_type_e type)
 Sets the polling type: read/write/other. O_POLL_READ | O_POLL_WRITE | O_POLL_OTHER.
onion_poller_slotonion_poller_get (onion_poller *poller, int fd)
 Gets the poller slotThis might be used for long polling, removing the default deleter.
void onion_poller_set_queue_size_per_thread (onion_poller *poller, size_t count)
 Sets the max events per thread queue size.This fine tune allows to change the queue of events per thread.
onion_poller_slotonion_poller_slot_t::onion_poller_slot_new (int fd, int(*f)(void *), void *data)
 Creates a new slot for the poller, for input data to be ready.
void onion_poller_slot_t::onion_poller_slot_free (onion_poller_slot *el)
 Free the data for the given slot, calling shutdown if any.
void onion_poller_slot_t::onion_poller_slot_set_shutdown (onion_poller_slot *el, void(*sd)(void *), void *data)
 Sets a function to be called when the slot is removed, for example because the file is closed.
void onion_poller_slot_t::onion_poller_slot_set_timeout (onion_poller_slot *el, int timeout)
 Sets the timeout for the slotThe timeout is passed in ms, but due to current implementation it is rounded to seconds. The interface stays, and hopefully in the future the behaviour will change.
onion_polleronion_poller_t::onion_poller_new (int n)
 Returns a poller object that helps polling on sockets and files.
int onion_poller_t::onion_poller_add (onion_poller *poller, onion_poller_slot *el)
 Adds a file descriptor to poll.
int onion_poller_t::onion_poller_remove (onion_poller *poller, int fd)
 Removes a file descriptor, and all related callbacks from the listening queue.
void onion_poller_t::onion_poller_poll (onion_poller *p)
 Do the event polling.
void onion_poller_t::onion_poller_stop (onion_poller *p)
 Marks the poller to stop ASAP.

Detailed Description

Enumeration Type Documentation

Enumerator:
O_POLL_READ 
O_POLL_WRITE 
O_POLL_OTHER 
O_POLL_ALL 

Function Documentation

int onion_poller_add ( onion_poller poller,
onion_poller_slot el 
)

Adds a file descriptor to poll.

When new data is available (read/write/event) the given function is called with that data.

Once the slot is added is not safe anymore to set data on it, unless its detached from the epoll. (see EPOLLONESHOT)

References onion_poller_t::fd, onion_poller_t::head, onion_poller_t::n, ONION_DEBUG0, ONION_ERROR, pthread_mutex_lock, and pthread_mutex_unlock.

Referenced by onion_listen(), onion_listen_point_t::onion_listen_point_accept(), and onion_poller_t::onion_poller_new().

onion_poller_slot* onion_poller_get ( onion_poller poller,
int  fd 
)

Gets the poller slotThis might be used for long polling, removing the default deleter.

Gets the poller to do some modifications as change shutdown.

Referenced by onion_request_process().

onion_poller * onion_poller_new ( int  n)

Returns a poller object that helps polling on sockets and files.

This poller is implemented through epoll, but other implementations are possible

References EFD_CLOEXEC, onion_poller_t::eventfd, onion_poller_t::fd, onion_poller_t::head, onion_poller_t::n, ONION_DEBUG, ONION_ERROR, onion_low_calloc(), onion_low_free(), onion_poller_t::onion_poller_add(), onion_poller_slot_t::onion_poller_slot_new(), pthread_mutex_init, onion_poller_t::stop, and onion_poller_t::timerfd.

Referenced by onion_new().

void onion_poller_poll ( onion_poller p)
int onion_poller_remove ( onion_poller poller,
int  fd 
)
void onion_poller_set_queue_size_per_thread ( onion_poller poller,
size_t  count 
)

Sets the max events per thread queue size.This fine tune allows to change the queue of events per thread.

Sets the max events per thread queue size.

In case of data contention a call to epoll_wait can return several ready descriptors, which this value decides.

If the value is high and some request processing is slow, the requests after that one will have to wait until processed, which increases latency. On the other hand, it requests are fast, using the queue is faster than another call to epoll_wait.

In non contention cases, where onion is mostly waiting for requests, it makes no difference.

WARNING! Just now there apears to be a bug on timeout management, and changing this level increases the probability of hitting it.

Default: 1.

void onion_poller_slot_free ( onion_poller_slot el)

Free the data for the given slot, calling shutdown if any.

Referenced by onion_poller_t::onion_poller_remove().

onion_poller_slot * onion_poller_slot_new ( int  fd,
int(*)(void *)  f,
void *  data 
)

Creates a new slot for the poller, for input data to be ready.

Parameters
fdFile descriptor to watch
fFunction to call when data is ready. If function returns <0, the slot will be removed.
dataData to pass to the function.
Returns
A new poller slot, ready to be added (onion_poller_add) or modified (onion_poller_slot_set_shutdown, onion_poller_slot_set_timeout).

References ONION_ERROR.

Referenced by onion_listen(), onion_listen_point_t::onion_listen_point_accept(), and onion_poller_t::onion_poller_new().

void onion_poller_slot_set_shutdown ( onion_poller_slot el,
void(*)(void *)  sd,
void *  data 
)

Sets a function to be called when the slot is removed, for example because the file is closed.

Parameters
elslot
sdFunction to call
dataParameter for the function

Referenced by onion_listen_point_t::onion_listen_point_accept(), and onion_request_process().

void onion_poller_slot_set_timeout ( onion_poller_slot el,
int  timeout 
)

Sets the timeout for the slotThe timeout is passed in ms, but due to current implementation it is rounded to seconds. The interface stays, and hopefully in the future the behaviour will change.

Parameters
elSlot to modify
timeoutTime in milliseconds that this file can be waiting.

References ONION_DEBUG0.

Referenced by onion_listen_point_t::onion_listen_point_accept().

void onion_poller_slot_set_type ( onion_poller_slot el,
onion_poller_slot_type_e  type 
)

Sets the polling type: read/write/other. O_POLL_READ | O_POLL_WRITE | O_POLL_OTHER.

Sets the type of the poller

References O_POLL_OTHER, O_POLL_READ, O_POLL_WRITE, and ONION_DEBUG0.

Referenced by onion_listen().

void onion_poller_stop ( onion_poller p)