wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Data Structures | Macros | Functions
eloop.c File Reference

Event loop based on select() loop. More...

#include "includes.h"
#include <assert.h>
#include "common.h"
#include "trace.h"
#include "list.h"
#include "eloop.h"

Data Structures

struct  eloop_sock
 
struct  eloop_timeout
 
struct  eloop_signal
 
struct  eloop_sock_table
 
struct  eloop_data
 

Macros

#define CONFIG_ELOOP_SELECT
 
#define eloop_trace_sock_add_ref(table)   do { } while (0)
 
#define eloop_trace_sock_remove_ref(table)   do { } while (0)
 

Functions

int eloop_init (void)
 Initialize global event loop data. More...
 
int eloop_register_read_sock (int sock, eloop_sock_handler handler, void *eloop_data, void *user_data)
 Register handler for read events. More...
 
void eloop_unregister_read_sock (int sock)
 Unregister handler for read events. More...
 
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. More...
 
void eloop_unregister_sock (int sock, eloop_event_type type)
 Unregister handler for socket events. More...
 
int eloop_register_timeout (unsigned int secs, unsigned int usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data)
 Register timeout. More...
 
int eloop_cancel_timeout (eloop_timeout_handler handler, void *eloop_data, void *user_data)
 Cancel timeouts. More...
 
int eloop_cancel_timeout_one (eloop_timeout_handler handler, void *eloop_data, void *user_data, struct os_reltime *remaining)
 Cancel a single timeout. More...
 
int eloop_is_timeout_registered (eloop_timeout_handler handler, void *eloop_data, void *user_data)
 Check if a timeout is already registered. More...
 
int eloop_deplete_timeout (unsigned int req_secs, unsigned int req_usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data)
 Deplete a timeout that is already registered. More...
 
int eloop_replenish_timeout (unsigned int req_secs, unsigned int req_usecs, eloop_timeout_handler handler, void *eloop_data, void *user_data)
 Replenish a timeout that is already registered. More...
 
int eloop_register_signal (int sig, eloop_signal_handler handler, void *user_data)
 Register handler for signals. More...
 
int eloop_register_signal_terminate (eloop_signal_handler handler, void *user_data)
 Register handler for terminate signals. More...
 
int eloop_register_signal_reconfig (eloop_signal_handler handler, void *user_data)
 Register handler for reconfig signals. More...
 
void eloop_run (void)
 Start the event loop. More...
 
void eloop_terminate (void)
 Terminate event loop. More...
 
void eloop_destroy (void)
 Free any resources allocated for the event loop. More...
 
int eloop_terminated (void)
 Check whether event loop has been terminated. More...
 
void eloop_wait_for_read_sock (int sock)
 Wait for a single reader. More...
 

Detailed Description

Event loop based on select() loop.

Function Documentation

int eloop_cancel_timeout ( eloop_timeout_handler  handler,
void *  eloop_data,
void *  user_data 
)

Cancel timeouts.

Parameters
handlerMatching callback function
eloop_dataMatching eloop_data or ELOOP_ALL_CTX to match all
user_dataMatching user_data or ELOOP_ALL_CTX to match all
Returns
Number of cancelled timeouts

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.

int eloop_cancel_timeout_one ( eloop_timeout_handler  handler,
void *  eloop_data,
void *  user_data,
struct os_reltime remaining 
)

Cancel a single timeout.

Parameters
handlerMatching callback function
eloop_dataMatching eloop_data
user_dataMatching user_data
remainingTime left on the cancelled timer
Returns
Number of cancelled timeouts

Cancel matching <handler,eloop_data,user_data> timeout registered with eloop_register_timeout() and return the remaining time left.

int eloop_deplete_timeout ( unsigned int  req_secs,
unsigned int  req_usecs,
eloop_timeout_handler  handler,
void *  eloop_data,
void *  user_data 
)

Deplete a timeout that is already registered.

Parameters
req_secsRequested number of seconds to the timeout
req_usecsRequested number of microseconds to the timeout
handlerMatching callback function
eloop_dataMatching eloop_data
user_dataMatching user_data
Returns
1 if the timeout is depleted, 0 if no change is made, -1 if no timeout matched

Find a registered matching <handler,eloop_data,user_data> timeout. If found, deplete the timeout if remaining time is more than the requested time.

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

int eloop_init ( void  )

Initialize global event loop data.

Returns
0 on success, -1 on failure

This function must be called before any other eloop_* function.

int eloop_is_timeout_registered ( eloop_timeout_handler  handler,
void *  eloop_data,
void *  user_data 
)

Check if a timeout is already registered.

Parameters
handlerMatching callback function
eloop_dataMatching eloop_data
user_dataMatching user_data
Returns
1 if the timeout is registered, 0 if the timeout is not registered

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.

Parameters
sockFile descriptor number for the socket
handlerCallback function to be called when data is available for reading
eloop_dataCallback context data (eloop_ctx)
user_dataCallback context data (sock_ctx)
Returns
0 on success, -1 on failure

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.

Parameters
sigSignal number (e.g., SIGHUP)
handlerCallback function to be called when the signal is received
user_dataCallback context data (signal_ctx)
Returns
0 on success, -1 on failure

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.

int eloop_register_signal_reconfig ( eloop_signal_handler  handler,
void *  user_data 
)

Register handler for reconfig signals.

Parameters
handlerCallback function to be called when the signal is received
user_dataCallback context data (signal_ctx)
Returns
0 on success, -1 on failure

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.

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.

Parameters
handlerCallback function to be called when the signal is received
user_dataCallback context data (signal_ctx)
Returns
0 on success, -1 on failure

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.

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.

Parameters
sockFile descriptor number for the socket
typeType of event to wait for
handlerCallback function to be called when the event is triggered
eloop_dataCallback context data (eloop_ctx)
user_dataCallback context data (sock_ctx)
Returns
0 on success, -1 on failure

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.

Parameters
secsNumber of seconds to the timeout
usecsNumber of microseconds to the timeout
handlerCallback function to be called when timeout occurs
eloop_dataCallback context data (eloop_ctx)
user_dataCallback context data (sock_ctx)
Returns
0 on success, -1 on failure

Register a timeout that will cause the handler function to be called after given time.

int eloop_replenish_timeout ( unsigned int  req_secs,
unsigned int  req_usecs,
eloop_timeout_handler  handler,
void *  eloop_data,
void *  user_data 
)

Replenish a timeout that is already registered.

Parameters
req_secsRequested number of seconds to the timeout
req_usecsRequested number of microseconds to the timeout
handlerMatching callback function
eloop_dataMatching eloop_data
user_dataMatching user_data
Returns
1 if the timeout is replenished, 0 if no change is made, -1 if no timeout matched

Find a registered matching <handler,eloop_data,user_data> timeout. If found, replenish the timeout if remaining time is less than the requested time.

void eloop_run ( void  )

Start the event loop.

Start the event loop and continue running as long as there are any registered event handlers. This function is run after event loop has been initialized with event_init() and one or more events have been registered.

void eloop_terminate ( void  )

Terminate event loop.

Terminate event loop even if there are registered events. This can be used to request the program to be terminated cleanly.

int eloop_terminated ( void  )

Check whether event loop has been terminated.

Returns
1 = event loop terminate, 0 = event loop still running

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.

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

Parameters
sockFile descriptor number for the socket
typeType of event for which sock was registered

Unregister a socket event notifier that was previously registered with eloop_register_sock().

void eloop_wait_for_read_sock ( int  sock)

Wait for a single reader.

Parameters
sockFile descriptor number for the socket

Do a blocking wait for a single read socket.