root/src/eventer/eventer.h

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

more work... fleshing out the eventer

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