libonion
|
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_slot * | onion_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_slot * | onion_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_poller * | onion_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. |
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 | ) |
Do the event polling.
It loops over polling. To exit polling call onion_poller_stop().
If no fd to poll, returns.
References onion_poller_t::fd, onion_poller_t::head, onion_poller_t::n, ONION_DEBUG, ONION_DEBUG0, ONION_ERROR, onion_low_free(), onion_poller_t::onion_poller_remove(), pthread_mutex_lock, pthread_mutex_unlock, and onion_poller_t::stop.
Referenced by onion_listen().
int onion_poller_remove | ( | onion_poller * | poller, |
int | fd | ||
) |
Removes a file descriptor, and all related callbacks from the listening queue.
References onion_poller_t::fd, onion_poller_t::head, onion_poller_t::n, ONION_DEBUG0, ONION_ERROR, onion_poller_slot_t::onion_poller_slot_free(), onion_poller_t::onion_poller_stop(), ONION_WARNING, pthread_mutex_lock, and pthread_mutex_unlock.
Referenced by onion_listen(), and onion_poller_t::onion_poller_poll().
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.
fd | File descriptor to watch |
f | Function to call when data is ready. If function returns <0, the slot will be removed. |
data | Data to pass to the function. |
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.
el | slot |
sd | Function to call |
data | Parameter 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.
el | Slot to modify |
timeout | Time 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 | ) |
Marks the poller to stop ASAP.
References onion_poller_t::eventfd, ONION_DEBUG, ONION_ERROR, pthread_mutex_lock, pthread_mutex_unlock, and onion_poller_t::stop.
Referenced by onion_listen_stop(), and onion_poller_t::onion_poller_remove().