root/src/eventer/eventer.h

Revision 04aaf954817d7e85e9daf2feb52c9411d1acb30f, 3.8 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

Add trigger support, compiles on Mac OS X and Solaris, changes made to Linux, but untested (even compile), refs #65

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _EVENTER_EVENTER_H
7 #define _EVENTER_EVENTER_H
8
9 #include "noit_defines.h"
10 #include "utils/noit_log.h"
11 #include <sys/time.h>
12 #include <sys/socket.h>
13
14 #define EVENTER_READ             0x01
15 #define EVENTER_WRITE            0x02
16 #define EVENTER_EXCEPTION        0x04
17 #define EVENTER_TIMER            0x08
18 #define EVENTER_ASYNCH_WORK      0x10
19 #define EVENTER_ASYNCH_CLEANUP   0x20
20 #define EVENTER_ASYNCH           (EVENTER_ASYNCH_WORK | EVENTER_ASYNCH_CLEANUP)
21 #define EVENTER_RECURRENT        0x80
22
23 /* All of these functions act like their POSIX couterparts with two
24  * additional arguments.  The first is the mask they require to be active
25  * to make progress in the event of an EAGAIN.  The second is a closure
26  * which is the event itself.
27  */
28 typedef int (*eventer_fd_accept_t)
29             (int, struct sockaddr *, socklen_t *, int *mask, void *closure);
30 typedef int (*eventer_fd_read_t)
31             (int, void *, size_t, int *mask, void *closure);
32 typedef int (*eventer_fd_write_t)
33             (int, const void *, size_t, int *mask, void *closure);
34 typedef int (*eventer_fd_close_t)
35             (int, int *mask, void *closure);
36
37 typedef struct _fd_opset {
38   eventer_fd_accept_t accept;
39   eventer_fd_read_t   read;
40   eventer_fd_write_t  write;
41   eventer_fd_close_t  close;
42 } *eventer_fd_opset_t;
43
44 typedef struct _event *eventer_t;
45
46 #include "eventer/eventer_POSIX_fd_opset.h"
47 #include "eventer/eventer_SSL_fd_opset.h"
48
49 typedef int (*eventer_func_t)
50             (eventer_t e, int mask, void *closure, struct timeval *tv);
51
52 struct _event {
53   eventer_func_t      callback;
54   struct timeval      whence;
55   int                 fd;
56   int                 mask;
57   eventer_fd_opset_t  opset;
58   void               *opset_ctx;
59   void *closure;
60 };
61
62 API_EXPORT(eventer_t) eventer_alloc();
63 API_EXPORT(void)      eventer_free(eventer_t);
64 API_EXPORT(int)       eventer_timecompare(const void *a, const void *b);
65 API_EXPORT(int)       eventer_name_callback(const char *name, eventer_func_t f);
66 API_EXPORT(const char *)
67                       eventer_name_for_callback(eventer_func_t f);
68 API_EXPORT(eventer_func_t)
69                       eventer_callback_for_name(const char *name);
70
71 typedef struct _eventer_impl {
72   const char         *name;
73   int               (*init)();
74   int               (*propset)(const char *key, const char *value);
75   void              (*add)(eventer_t e);
76   eventer_t         (*remove)(eventer_t e);
77   void              (*update)(eventer_t e, int newmask);
78   eventer_t         (*remove_fd)(int fd);
79   eventer_t         (*find_fd)(int fd);
80   void              (*trigger)(eventer_t e, int mask);
81   int               (*loop)();
82 } *eventer_impl_t;
83
84 /* This is the "chosen one" */
85 #ifndef _EVENTER_C
86 extern
87 #endif
88 eventer_impl_t __eventer;
89 noit_log_stream_t eventer_err;
90 noit_log_stream_t eventer_deb;
91
92 API_EXPORT(int) eventer_choose(const char *name);
93
94 #define eventer_propset       __eventer->propset
95 #define eventer_init          __eventer->init
96 #define eventer_add           __eventer->add
97 #define eventer_remove        __eventer->remove
98 #define eventer_update        __eventer->update
99 #define eventer_remove_fd     __eventer->remove_fd
100 #define eventer_find_fd       __eventer->find_fd
101 #define eventer_loop          __eventer->loop
102 #define eventer_trigger       __eventer->trigger
103
104 extern eventer_impl_t registered_eventers[];
105
106 #include "eventer/eventer_jobq.h"
107
108 API_EXPORT(eventer_jobq_t *) eventer_default_backq();
109 API_EXPORT(int) eventer_impl_propset(const char *key, const char *value);
110 API_EXPORT(int) eventer_impl_init();
111 API_EXPORT(void) eventer_add_asynch(eventer_jobq_t *q, eventer_t e);
112 API_EXPORT(void) eventer_dispatch_recurrent(struct timeval *now);
113 API_EXPORT(eventer_t) eventer_remove_recurrent(eventer_t e);
114 API_EXPORT(void) eventer_add_recurrent(eventer_t e);
115
116 #endif
Note: See TracBrowser for help on using the browser.