Event loop based on select() loop. More...
#include "includes.h"
#include "common.h"
#include "eloop.h"
Go to the source code of this file.
Data Structures | |
struct | eloop_sock |
struct | eloop_timeout |
struct | eloop_signal |
struct | eloop_sock_table |
struct | eloop_data |
Functions | |
int | eloop_init (void *user_data) |
Initialize global event loop data. | |
int | eloop_register_read_sock (int sock, eloop_sock_handler handler, void *eloop_data, void *user_data) |
Register handler for read events. | |
void | eloop_unregister_read_sock (int sock) |
Unregister handler for read events. | |
int | eloop_register_sock (int sock, eloop_event_type type, eloop_sock_handler handler, void *eloop_data, void *user_data) |
Register handler for socket events. | |
void | eloop_unregister_sock (int sock, eloop_event_type type) |
Unregister handler for socket events. | |
int | eloop_register_timeout (unsigned int secs, unsigned int usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data) |
Register timeout. | |
int | eloop_cancel_timeout (eloop_timeout_handler handler, void *eloop_data, void *user_data) |
Cancel timeouts. | |
int | eloop_is_timeout_registered (eloop_timeout_handler handler, void *eloop_data, void *user_data) |
Check if a timeout is already registered. | |
int | eloop_register_signal (int sig, eloop_signal_handler handler, void *user_data) |
Register handler for signals. | |
int | eloop_register_signal_terminate (eloop_signal_handler handler, void *user_data) |
Register handler for terminate signals. | |
int | eloop_register_signal_reconfig (eloop_signal_handler handler, void *user_data) |
Register handler for reconfig signals. | |
void | eloop_run (void) |
Start the event loop. | |
void | eloop_terminate (void) |
Terminate event loop. | |
void | eloop_destroy (void) |
Free any resources allocated for the event loop. | |
int | eloop_terminated (void) |
Check whether event loop has been terminated. | |
void | eloop_wait_for_read_sock (int sock) |
Wait for a single reader. | |
void * | eloop_get_user_data (void) |
Get global user data. |
Event loop based on select() loop.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
Alternatively, this software may be distributed under the terms of BSD license.
See README and COPYING for more details.
Definition in file eloop.c.
int eloop_cancel_timeout | ( | eloop_timeout_handler | handler, | |
void * | eloop_data, | |||
void * | user_data | |||
) |
Cancel timeouts.
handler | Matching callback function | |
eloop_data | Matching eloop_data or ELOOP_ALL_CTX to match all | |
user_data | Matching user_data or ELOOP_ALL_CTX to match all |
Cancel matching <handler,eloop_data,user_data> timeouts registered with eloop_register_timeout(). ELOOP_ALL_CTX can be used as a wildcard for cancelling all timeouts regardless of eloop_data/user_data.
void eloop_destroy | ( | void | ) |
Free any resources allocated for the event loop.
After calling eloop_destroy(), other eloop_* functions must not be called before re-running eloop_init().
void* eloop_get_user_data | ( | void | ) |
Get global user data.
int eloop_init | ( | void * | user_data | ) |
Initialize global event loop data.
user_data | Pointer to global data passed as eloop_ctx to signal handlers |
This function must be called before any other eloop_* function. user_data can be used to configure a global (to the process) pointer that will be passed as eloop_ctx parameter to signal handlers.
int eloop_is_timeout_registered | ( | eloop_timeout_handler | handler, | |
void * | eloop_data, | |||
void * | user_data | |||
) |
Check if a timeout is already registered.
handler | Matching callback function | |
eloop_data | Matching eloop_data | |
user_data | Matching user_data |
Determine if a matching <handler,eloop_data,user_data> timeout is registered with eloop_register_timeout().
int eloop_register_read_sock | ( | int | sock, | |
eloop_sock_handler | handler, | |||
void * | eloop_data, | |||
void * | user_data | |||
) |
Register handler for read events.
sock | File descriptor number for the socket | |
handler | Callback function to be called when data is available for reading | |
eloop_data | Callback context data (eloop_ctx) | |
user_data | Callback context data (sock_ctx) |
Register a read socket notifier for the given file descriptor. The handler function will be called whenever data is available for reading from the socket. The handler function is responsible for clearing the event after having processed it in order to avoid eloop from calling the handler again for the same event.
int eloop_register_signal | ( | int | sig, | |
eloop_signal_handler | handler, | |||
void * | user_data | |||
) |
Register handler for signals.
sig | Signal number (e.g., SIGHUP) | |
handler | Callback function to be called when the signal is received | |
user_data | Callback context data (signal_ctx) |
Register a callback function that will be called when a signal is received. The callback function is actually called only after the system signal handler has returned. This means that the normal limits for sighandlers (i.e., only "safe functions" allowed) do not apply for the registered callback.
Signals are 'global' events and there is no local eloop_data pointer like with other handlers. The global user_data pointer registered with eloop_init() will be used as eloop_ctx for signal handlers.
int eloop_register_signal_reconfig | ( | eloop_signal_handler | handler, | |
void * | user_data | |||
) |
Register handler for reconfig signals.
handler | Callback function to be called when the signal is received | |
user_data | Callback context data (signal_ctx) |
Register a callback function that will be called when a reconfiguration / hangup signal is received. The callback function is actually called only after the system signal handler has returned. This means that the normal limits for sighandlers (i.e., only "safe functions" allowed) do not apply for the registered callback.
Signals are 'global' events and there is no local eloop_data pointer like with other handlers. The global user_data pointer registered with eloop_init() will be used as eloop_ctx for signal handlers.
This function is a more portable version of eloop_register_signal() since the knowledge of exact details of the signals is hidden in eloop implementation. In case of operating systems using signal(), this function registers a handler for SIGHUP.
int eloop_register_signal_terminate | ( | eloop_signal_handler | handler, | |
void * | user_data | |||
) |
Register handler for terminate signals.
handler | Callback function to be called when the signal is received | |
user_data | Callback context data (signal_ctx) |
Register a callback function that will be called when a process termination signal is received. The callback function is actually called only after the system signal handler has returned. This means that the normal limits for sighandlers (i.e., only "safe functions" allowed) do not apply for the registered callback.
Signals are 'global' events and there is no local eloop_data pointer like with other handlers. The global user_data pointer registered with eloop_init() will be used as eloop_ctx for signal handlers.
This function is a more portable version of eloop_register_signal() since the knowledge of exact details of the signals is hidden in eloop implementation. In case of operating systems using signal(), this function registers handlers for SIGINT and SIGTERM.
int eloop_register_sock | ( | int | sock, | |
eloop_event_type | type, | |||
eloop_sock_handler | handler, | |||
void * | eloop_data, | |||
void * | user_data | |||
) |
Register handler for socket events.
sock | File descriptor number for the socket | |
type | Type of event to wait for | |
handler | Callback function to be called when the event is triggered | |
eloop_data | Callback context data (eloop_ctx) | |
user_data | Callback context data (sock_ctx) |
Register an event notifier for the given socket's file descriptor. The handler function will be called whenever the that event is triggered for the socket. The handler function is responsible for clearing the event after having processed it in order to avoid eloop from calling the handler again for the same event.
int eloop_register_timeout | ( | unsigned int | secs, | |
unsigned int | usecs, | |||
eloop_timeout_handler | handler, | |||
void * | eloop_data, | |||
void * | user_data | |||
) |
Register timeout.
secs | Number of seconds to the timeout | |
usecs | Number of microseconds to the timeout | |
handler | Callback function to be called when timeout occurs | |
eloop_data | Callback context data (eloop_ctx) | |
user_data | Callback context data (sock_ctx) |
Register a timeout that will cause the handler function to be called after given time.
void eloop_run | ( | void | ) |
void eloop_terminate | ( | void | ) |
int eloop_terminated | ( | void | ) |
Check whether event loop has been terminated.
This function can be used to check whether eloop_terminate() has been called to request termination of the event loop. This is normally used to abort operations that may still be queued to be run when eloop_terminate() was called.
void eloop_unregister_read_sock | ( | int | sock | ) |
Unregister handler for read events.
sock | File descriptor number for the socket |
Unregister a read socket notifier that was previously registered with eloop_register_read_sock().
void eloop_unregister_sock | ( | int | sock, | |
eloop_event_type | type | |||
) |
Unregister handler for socket events.
sock | File descriptor number for the socket | |
type | Type of event for which sock was registered |
Unregister a socket event notifier that was previously registered with eloop_register_sock().