root/src/eventer/eventer.h

Revision b7ec8071a69b07dca745fa521b287c9f4ffec06e, 3.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 10 years ago)

SSL support that doesn't quite work -- so so so close.

  • 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 <sys/time.h>
11 #include <sys/socket.h>
12
13 #define EVENTER_READ             0x01
14 #define EVENTER_WRITE            0x02
15 #define EVENTER_EXCEPTION        0x04
16 #define EVENTER_TIMER            0x08
17 #define EVENTER_ASYNCH_WORK      0x10
18 #define EVENTER_ASYNCH_CLEANUP   0x20
19 #define EVENTER_ASYNCH           (EVENTER_ASYNCH_WORK | EVENTER_ASYNCH_CLEANUP)
20 #define EVENTER_RECURRENT        0x80
21
22 /* All of these functions act like their POSIX couterparts with two
23  * additional arguments.  The first is the mask they require to be active
24  * to make progress in the event of an EAGAIN.  The second is a closure
25  * which is the event itself.
26  */
27 typedef int (*eventer_fd_accept_t)
28             (int, struct sockaddr *, socklen_t *, int *mask, void *closure);
29 typedef int (*eventer_fd_read_t)
30             (int, void *, size_t, int *mask, void *closure);
31 typedef int (*eventer_fd_write_t)
32             (int, const void *, size_t, int *mask, void *closure);
33 typedef int (*eventer_fd_close_t)
34             (int, int *mask, void *closure);
35
36 typedef struct _fd_opset {
37   eventer_fd_accept_t accept;
38   eventer_fd_read_t   read;
39   eventer_fd_write_t  write;
40   eventer_fd_close_t  close;
41 } *eventer_fd_opset_t;
42
43 typedef struct _event *eventer_t;
44
45 #include "eventer/eventer_POSIX_fd_opset.h"
46 #include "eventer/eventer_SSL_fd_opset.h"
47
48 typedef int (*eventer_func_t)
49             (eventer_t e, int mask, void *closure, struct timeval *tv);
50
51 struct _event {
52   eventer_func_t      callback;
53   struct timeval      whence;
54   int                 fd;
55   int                 mask;
56   eventer_fd_opset_t  opset;
57   void               *opset_ctx;
58   void *closure;
59 };
60
61 API_EXPORT(eventer_t) eventer_alloc();
62 API_EXPORT(void)      eventer_free(eventer_t);
63 API_EXPORT(int)       eventer_timecompare(void *a, void *b);
64 API_EXPORT(int)       eventer_name_callback(const char *name, eventer_func_t f);
65 API_EXPORT(const char *)
66                       eventer_name_for_callback(eventer_func_t f);
67 API_EXPORT(eventer_func_t)
68                       eventer_callback_for_name(const char *name);
69
70 typedef struct _eventer_impl {
71   const char         *name;
72   int               (*init)();
73   int               (*propset)(const char *key, const char *value);
74   void              (*add)(eventer_t e);
75   eventer_t         (*remove)(eventer_t e);
76   void              (*update)(eventer_t e);
77   eventer_t         (*remove_fd)(int fd);
78   eventer_t         (*find_fd)(int fd);
79   int               (*loop)();
80 } *eventer_impl_t;
81
82 /* This is the "chosen one" */
83 #ifndef _EVENTER_C
84 extern
85 #endif
86 eventer_impl_t __eventer;
87
88 API_EXPORT(int) eventer_choose(const char *name);
89
90 #define eventer_propset       __eventer->propset
91 #define eventer_init          __eventer->init
92 #define eventer_add           __eventer->add
93 #define eventer_remove        __eventer->remove
94 #define eventer_update        __eventer->update
95 #define eventer_remove_fd     __eventer->remove_fd
96 #define eventer_find_fd       __eventer->find_fd
97 #define eventer_loop          __eventer->loop
98
99 #endif
Note: See TracBrowser for help on using the browser.