eloop.c File Reference

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

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include "eloop.h"

Include dependency graph for eloop.c:

Go to the source code of this file.

Functions

void eloop_init (void *user_data)
 Initialize global event loop data.
int eloop_register_read_sock (int sock, void(*handler)(int sock, void *eloop_ctx, void *sock_ctx), 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_timeout (unsigned int secs, unsigned int usecs, void(*handler)(void *eloop_ctx, void *timeout_ctx), void *eloop_data, void *user_data)
 Register timeout.
int eloop_cancel_timeout (void(*handler)(void *eloop_ctx, void *sock_ctx), void *eloop_data, void *user_data)
 Cancel timeouts.
int eloop_register_signal (int sig, void(*handler)(int sig, void *eloop_ctx, void *signal_ctx), void *user_data)
 Register handler for 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.


Detailed Description

Event loop based on select() loop.

Copyright
Copyright (c) 2002-2005, Jouni Malinen <[email protected]>
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.


Function Documentation

int eloop_cancel_timeout void(*)(void *eloop_ctx, void *sock_ctx)  handler,
void *  eloop_data,
void *  user_data
 

Cancel timeouts.

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

Definition at line 178 of file eloop.c.

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

Definition at line 378 of file eloop.c.

void eloop_init void *  user_data  ) 
 

Initialize global event loop data.

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

Definition at line 74 of file eloop.c.

int eloop_register_read_sock int  sock,
void(*)(int sock, void *eloop_ctx, void *sock_ctx)  handler,
void *  eloop_data,
void *  user_data
 

Register handler for read events.

Parameters:
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)
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.

Definition at line 81 of file eloop.c.

int eloop_register_signal int  sig,
void(*)(int sig, void *eloop_ctx, void *signal_ctx)  handler,
void *  user_data
 

Register handler for signals.

Parameters:
sig Signal number (e.g., SIGHUP)
handler Callback function to be called when the signal is received
user_data Callback 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 calback 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.

Definition at line 273 of file eloop.c.

int eloop_register_timeout unsigned int  secs,
unsigned int  usecs,
void(*)(void *eloop_ctx, void *timeout_ctx)  handler,
void *  eloop_data,
void *  user_data
 

Register timeout.

Parameters:
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)
Returns:
0 on success, -1 on failure
Register a timeout that will cause the handler function to be called after given time.

Definition at line 131 of file eloop.c.

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.

Definition at line 299 of file eloop.c.

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.

Definition at line 372 of file eloop.c.

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.

Definition at line 393 of file eloop.c.

void eloop_unregister_read_sock int  sock  ) 
 

Unregister handler for read events.

Parameters:
sock File descriptor number for the socket
Unregister a read socket notifier that was previously registered with eloop_register_read_sock().

Definition at line 108 of file eloop.c.


Generated on Sat May 6 21:16:45 2006 for wpa_supplicant by  doxygen 1.4.2