Main Page | Class List | File List | Class Members | File Members | Related Pages

event.h File Reference

Main select event loop. More...

#include <sys/types.h>

Go to the source code of this file.

Defines

#define MSEC   (1)
#define SECONDS   (1000*MSEC)
#define MINUTES   (60*SECONDS)
#define ESECONDS   (1)
#define EMINUTES   (60*ESECONDS)
#define EHOURS   (60*EMINUTES)
#define EDAYS   (24*EHOURS)
#define TIMEOUT_DEF   (60*SECONDS)

Typedefs

typedef unsigned int input_id
typedef unsigned int timer_id
typedef void(* InputCallback )(int fd, input_id id, void *udata)
typedef BOOL(* TimerCallback )(void *udata)

Enumerations

enum  InputState { INPUT_READ = 0x01, INPUT_WRITE = 0x02, INPUT_ERROR = 0x04 }

Functions

EXTERN_C_BEGIN LIBGIFT_EXPORT
void 
event_init (void)
LIBGIFT_EXPORT void event_quit (int sig)
LIBGIFT_EXPORT void event_poll_once (void)
LIBGIFT_EXPORT void event_loop (void)
LIBGIFT_EXPORT input_id input_add (int fd, void *udata, InputState state, InputCallback callback, time_t timeout)
LIBGIFT_EXPORT void input_remove (input_id id)
LIBGIFT_EXPORT void input_remove_all (int fd)
LIBGIFT_EXPORT void input_suspend_all (int fd)
LIBGIFT_EXPORT void input_resume_all (int fd)
LIBGIFT_EXPORT timer_id timer_add (time_t interval, TimerCallback callback, void *udata)
LIBGIFT_EXPORT void timer_reset (timer_id id)
LIBGIFT_EXPORT void timer_remove (timer_id id)
LIBGIFT_EXPORT void timer_remove_zero (timer_id *id)


Detailed Description

Main select event loop.

Provides the low-level framework for giFT file descriptor (yes, that includes sockets) handling.


Typedef Documentation

typedef unsigned int input_id
 

Input handle

typedef void(* InputCallback)(int fd, input_id id, void *udata)
 

Callback used to indicate that the connection has changed state according to the input_add state.

typedef unsigned int timer_id
 

Timer handle

typedef BOOL(* TimerCallback)(void *udata)
 

Timer has reached zero.

Parameters:
udata Arbitrary user data.
Return values:
FALSE Clear and remove from event loop.
TRUE Reset this timer.


Enumeration Type Documentation

enum InputState
 

Available select sets.


Function Documentation

EXTERN_C_BEGIN LIBGIFT_EXPORT void event_init void   ) 
 

Initialize the event subsystem. This is mandatory and must be called prior to any events being scheduled into the main loop.

LIBGIFT_EXPORT void event_loop void   ) 
 

Begin the main event loop. This will block until there are no fds or timers remaining or until event_quit has been called.

LIBGIFT_EXPORT void event_poll_once void   ) 
 

Execute a single blocking poll and handle exactly one event.

LIBGIFT_EXPORT void event_quit int  sig  ) 
 

Clear all events and return from the main loop. This will not exit your program, merely break out of event_loop, which should be the core blocking entity.

Parameters:
sig Signal delivered that caused this interruption. This value is currently unused and may disappear entirely.

LIBGIFT_EXPORT input_id input_add int  fd,
void *  udata,
InputState  state,
InputCallback  callback,
time_t  timeout
 

Add a new fd input.

Parameters:
fd 
udata Arbitrary user data to pass along to callback.
state Set to examine.
callback Function to raise when the examined set detects a change.
timeout If non-zero, the fd will be checked for input. If the callback is not raised in the specified time interval, the socket will be closed and the callback raised with a closed socket.
Returns:
Unique input handle. You may use this to remove a specific input or use the file descriptor to remove a group of inputs.

LIBGIFT_EXPORT void input_remove input_id  id  ) 
 

Remove a single input by it's unique identifier.

LIBGIFT_EXPORT void input_remove_all int  fd  ) 
 

Remove all inputs registered from a single file descriptor. This is useful when you want to lazily clean up all your slop, as giFT certainly desires. The usage of this function is highly discouraged unless you know that the socket is no longer connected as it will interfere with queue systems.

LIBGIFT_EXPORT void input_resume_all int  fd  ) 
 

Move the inputs back into the select loop. See input_suspend_all.

LIBGIFT_EXPORT void input_suspend_all int  fd  ) 
 

Suspend all inputs registered to this connection from the select loop. This is useful for bandwidth throttling in user space and some other evil things.

LIBGIFT_EXPORT timer_id timer_add time_t  interval,
TimerCallback  callback,
void *  udata
 

Install a new timer event.

Parameters:
interval Time to wait. Expressed in milliseconds. See ::SECONDS and ::MINUTES for helpers.
callback Function to be called when the interval is satisfied.
udata Arbitrary user data.
Returns:
Unique timer identifier on success, otherwise zero.

LIBGIFT_EXPORT void timer_remove timer_id  id  ) 
 

Remove a timer. This clears all data associated with the timer. The callback will not be raised.

LIBGIFT_EXPORT void timer_remove_zero timer_id id  ) 
 

Wrapper for timer_remove which assigns the value at id to zero after removal to invalidate the identifier.

LIBGIFT_EXPORT void timer_reset timer_id  id  ) 
 

Reset a timer. That is, reset the expiration time to now + interval as if the timer was registered for the first time.


Generated on Sun Aug 22 08:07:10 2004 by doxygen 1.3.7