1 #ifndef RH_EVENT_H
 2 #define RH_EVENT_H
 3 
 4 #include <sys/types.h>
 5 #include <sys/epoll.h>
 6 #include <sys/time.h>
 7 #include "queue.h"
 8 
 9 #define RH_EVENT_READ           1
10 #define RH_EVENT_WRITE          2
11 #define RH_EVENT_ERROR          4
12 #define RH_EVENT_TIMEOUT        8
13 #define RH_EVENT_SIGNAL         16
14 #define RH_EVENT_ET             32
15 
16 #define RH_EVENT_DISPATCH       512
17 
18 #define RH_EVENT_ALL    (RH_EVENT_READ | RH_EVENT_WRITE | RH_EVENT_ERROR)
19 
20 TAILQ_HEAD(rh_event_list, rh_event);
21 
22 typedef struct rh_event         rh_event_t;
23 typedef struct rh_event_base    rh_event_base_t;
24 
25 struct rh_event {
26         void                    (*cb)(int, short, void *);
27         void                    *arg;
28         short                   rh_events;
29         int                     fd;
30         struct rh_event_base    *base;
31         struct rh_event_node    *node;
32 
33         time_t                  timeout_time;
34         TAILQ_ENTRY(rh_event)   list;
35 };
36 
37 
38 struct rh_event_node {
39         struct epoll_event      ep_event;
40         
41         struct rh_event         *read;
42         struct rh_event         *write;
43 };
44 
45 struct rh_event_base {
46         time_t                  time;
47         int                     exit;
48         int                     fd;
49         size_t                  nodes_count;
50         int                     timeout;
51         struct rh_event_node    **nodes;
52         struct rh_event_list    timeout_list;
53 };
54 
55 int rh_event_dispatch (struct rh_event_base *base);
56 
57 int  rh_event_base_init    (struct rh_event_base *, int timeout);
58 void rh_event_base_destroy (struct rh_event_base *);
59 void rh_event_base_exit    (struct rh_event_base *);
60 
61 int rh_event_set (struct rh_event *event,
62                   struct rh_event_base *base,
63                   int fd,
64                   short events,
65                   void (*cb)(int, short, void *),
66                   void *arg);
67 
68 int rh_event_signal_set (struct rh_event *event,
69                   struct rh_event_base *base,
70                   int sig,
71                   void (*cb)(int, short, void *),
72                   void *arg);
73 
74 #define RH_EVENT_ISSET(_event)  ((_event)->rh_events & RH_EVENT_DISPATCH)
75 
76 int rh_event_del (struct rh_event *event);
77 
78 int rh_event_add (struct rh_event *event);
79 
80 #endif /* RH_EVENT_H */


syntax highlighted by Code2HTML, v. 0.9.1