root/src/eventer/eventer.h

Revision 88a71780101cbf23034aa0cb840f9f0368fda2dd, 5.4 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

fixes #126

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _EVENTER_EVENTER_H
34 #define _EVENTER_EVENTER_H
35
36 #include "noit_defines.h"
37 #include "utils/noit_log.h"
38 #include <sys/time.h>
39 #include <sys/socket.h>
40
41 #define EVENTER_READ             0x01
42 #define EVENTER_WRITE            0x02
43 #define EVENTER_EXCEPTION        0x04
44 #define EVENTER_TIMER            0x08
45 #define EVENTER_ASYNCH_WORK      0x10
46 #define EVENTER_ASYNCH_CLEANUP   0x20
47 #define EVENTER_ASYNCH           (EVENTER_ASYNCH_WORK | EVENTER_ASYNCH_CLEANUP)
48 #define EVENTER_RECURRENT        0x80
49
50 /* All of these functions act like their POSIX couterparts with two
51  * additional arguments.  The first is the mask they require to be active
52  * to make progress in the event of an EAGAIN.  The second is a closure
53  * which is the event itself.
54  */
55 typedef int (*eventer_fd_accept_t)
56             (int, struct sockaddr *, socklen_t *, int *mask, void *closure);
57 typedef int (*eventer_fd_read_t)
58             (int, void *, size_t, int *mask, void *closure);
59 typedef int (*eventer_fd_write_t)
60             (int, const void *, size_t, int *mask, void *closure);
61 typedef int (*eventer_fd_close_t)
62             (int, int *mask, void *closure);
63
64 typedef struct _fd_opset {
65   eventer_fd_accept_t accept;
66   eventer_fd_read_t   read;
67   eventer_fd_write_t  write;
68   eventer_fd_close_t  close;
69 } *eventer_fd_opset_t;
70
71 typedef struct _event *eventer_t;
72
73 #include "eventer/eventer_POSIX_fd_opset.h"
74 #include "eventer/eventer_SSL_fd_opset.h"
75
76 typedef int (*eventer_func_t)
77             (eventer_t e, int mask, void *closure, struct timeval *tv);
78
79 struct _event {
80   eventer_func_t      callback;
81   struct timeval      whence;
82   int                 fd;
83   int                 mask;
84   eventer_fd_opset_t  opset;
85   void               *opset_ctx;
86   void *closure;
87 };
88
89 API_EXPORT(eventer_t) eventer_alloc();
90 API_EXPORT(void)      eventer_free(eventer_t);
91 API_EXPORT(int)       eventer_timecompare(const void *a, const void *b);
92 API_EXPORT(int)       eventer_name_callback(const char *name, eventer_func_t f);
93 API_EXPORT(const char *)
94                       eventer_name_for_callback(eventer_func_t f);
95 API_EXPORT(eventer_func_t)
96                       eventer_callback_for_name(const char *name);
97
98 typedef struct _eventer_impl {
99   const char         *name;
100   int               (*init)();
101   int               (*propset)(const char *key, const char *value);
102   void              (*add)(eventer_t e);
103   eventer_t         (*remove)(eventer_t e);
104   void              (*update)(eventer_t e, int newmask);
105   eventer_t         (*remove_fd)(int fd);
106   eventer_t         (*find_fd)(int fd);
107   void              (*trigger)(eventer_t e, int mask);
108   int               (*loop)();
109 } *eventer_impl_t;
110
111 /* This is the "chosen one" */
112 #ifndef _EVENTER_C
113 extern
114 #endif
115 eventer_impl_t __eventer;
116 noit_log_stream_t eventer_err;
117 noit_log_stream_t eventer_deb;
118
119 API_EXPORT(int) eventer_choose(const char *name);
120
121 #define eventer_propset       __eventer->propset
122 #define eventer_init          __eventer->init
123 #define eventer_add           __eventer->add
124 #define eventer_remove        __eventer->remove
125 #define eventer_update        __eventer->update
126 #define eventer_remove_fd     __eventer->remove_fd
127 #define eventer_find_fd       __eventer->find_fd
128 #define eventer_loop          __eventer->loop
129 #define eventer_trigger       __eventer->trigger
130
131 extern eventer_impl_t registered_eventers[];
132
133 #include "eventer/eventer_jobq.h"
134
135 API_EXPORT(eventer_jobq_t *) eventer_default_backq();
136 API_EXPORT(int) eventer_impl_propset(const char *key, const char *value);
137 API_EXPORT(int) eventer_impl_init();
138 API_EXPORT(void) eventer_add_asynch(eventer_jobq_t *q, eventer_t e);
139 API_EXPORT(void) eventer_dispatch_recurrent(struct timeval *now);
140 API_EXPORT(eventer_t) eventer_remove_recurrent(eventer_t e);
141 API_EXPORT(void) eventer_add_recurrent(eventer_t e);
142 API_EXPORT(int) eventer_get_epoch(struct timeval *epoch);
143
144 #endif
Note: See TracBrowser for help on using the browser.