root/src/eventer/eventer.h

Revision 4b96846179a35015ac0b22d5fe9e9f92480f06a5, 3.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

check code consolidation. allow modules to be more terse and add convenience functions to make writing completely asynch checkers much easier. (add a postgres proof-of-concept asynch checker

  • 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);
78   eventer_t         (*remove_fd)(int fd);
79   eventer_t         (*find_fd)(int fd);
80   int               (*loop)();
81 } *eventer_impl_t;
82
83 /* This is the "chosen one" */
84 #ifndef _EVENTER_C
85 extern
86 #endif
87 eventer_impl_t __eventer;
88 noit_log_stream_t eventer_err;
89 noit_log_stream_t eventer_deb;
90
91 API_EXPORT(int) eventer_choose(const char *name);
92
93 #define eventer_propset       __eventer->propset
94 #define eventer_init          __eventer->init
95 #define eventer_add           __eventer->add
96 #define eventer_remove        __eventer->remove
97 #define eventer_update        __eventer->update
98 #define eventer_remove_fd     __eventer->remove_fd
99 #define eventer_find_fd       __eventer->find_fd
100 #define eventer_loop          __eventer->loop
101
102 extern eventer_impl_t registered_eventers[];
103
104 #include "eventer/eventer_jobq.h"
105
106 API_EXPORT(eventer_jobq_t *) eventer_default_backq();
107 API_EXPORT(int) eventer_impl_propset(const char *key, const char *value);
108 API_EXPORT(int) eventer_impl_init();
109 API_EXPORT(void) eventer_add_asynch(eventer_jobq_t *q, eventer_t e);
110 API_EXPORT(void) eventer_dispatch_recurrent(struct timeval *now);
111 API_EXPORT(eventer_t) eventer_remove_recurrent(eventer_t e);
112 API_EXPORT(void) eventer_add_recurrent(eventer_t e);
113
114 #endif
Note: See TracBrowser for help on using the browser.