1 /***********************************************************************
5 * Abstraction of select call into "event-handling" to make programming
8 * Copyright (C) 2001 Roaring Penguin Software Inc.
10 * This program may be distributed according to the terms of the GNU
11 * General Public License, version 2 or (at your option) any later version.
13 * $Id: event.h,v 1.1.48.1 2005/08/08 12:05:25 honor Exp $
17 ***********************************************************************/
21 #ifndef INCLUDE_EVENT_H
22 #define INCLUDE_EVENT_H 1
24 /* Solaris moans if we don't do this... */
26 #define __EXTENSIONS__ 1
29 struct EventSelector_t
;
31 /* Callback function */
32 typedef void (*EventCallbackFunc
)(struct EventSelector_t
*es
,
33 int fd
, unsigned int flags
,
36 #include "eventpriv.h"
38 /* Create an event selector */
39 extern EventSelector
*Event_CreateSelector(void);
41 /* Destroy the event selector */
42 extern void Event_DestroySelector(EventSelector
*es
);
44 /* Handle one event */
45 extern int Event_HandleEvent(EventSelector
*es
);
47 /* Add a handler for a ready file descriptor */
48 extern EventHandler
*Event_AddHandler(EventSelector
*es
,
51 EventCallbackFunc fn
, void *data
);
53 /* Add a handler for a ready file descriptor with associated timeout*/
54 extern EventHandler
*Event_AddHandlerWithTimeout(EventSelector
*es
,
62 /* Add a timer handler */
63 extern EventHandler
*Event_AddTimerHandler(EventSelector
*es
,
68 /* Change the timeout of a timer handler */
69 void Event_ChangeTimeout(EventHandler
*handler
, struct timeval t
);
71 /* Delete a handler */
72 extern int Event_DelHandler(EventSelector
*es
,
75 /* Retrieve callback function from a handler */
76 extern EventCallbackFunc
Event_GetCallback(EventHandler
*eh
);
78 /* Retrieve data field from a handler */
79 extern void *Event_GetData(EventHandler
*eh
);
81 /* Set callback and data to new values */
82 extern void Event_SetCallbackAndData(EventHandler
*eh
,
86 /* Handle a signal synchronously in event loop */
87 int Event_HandleSignal(EventSelector
*es
, int sig
, void (*handler
)(int sig
));
89 /* Reap children synchronously in event loop */
90 int Event_HandleChildExit(EventSelector
*es
, pid_t pid
,
91 void (*handler
)(pid_t
, int, void *), void *data
);
93 extern int Event_EnableDebugging(char const *fname
);
96 extern void Event_DebugMsg(char const *fmt
, ...);
97 #define EVENT_DEBUG(x) Event_DebugMsg x
99 #define EVENT_DEBUG(x) ((void) 0)
103 #define EVENT_FLAG_READABLE 1
104 #define EVENT_FLAG_WRITEABLE 2
105 #define EVENT_FLAG_WRITABLE EVENT_FLAG_WRITEABLE
107 /* This is strictly a timer event */
108 #define EVENT_FLAG_TIMER 4
110 /* This is a read or write event with an associated timeout */
111 #define EVENT_FLAG_TIMEOUT 8
113 #define EVENT_TIMER_BITS (EVENT_FLAG_TIMER | EVENT_FLAG_TIMEOUT)