root/src/eventer/eventer.h

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

prep for asynchronous events

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