root/src/eventer/eventer.h

Revision 3b3b432b41dd3bfb80c144aa7ba28e75daa2337f, 3.0 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

asynchronous job queues

  • 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 o 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 typedef int (*eventer_func_t)
45             (eventer_t e, int mask, void *closure, struct timeval *tv);
46
47 struct _event {
48   eventer_func_t      callback;
49   struct timeval      whence;
50   int                 fd;
51   int                 mask;
52   eventer_fd_opset_t  opset;
53   void *closure;
54 };
55
56 API_EXPORT(eventer_t) eventer_alloc();
57 API_EXPORT(void)      eventer_free(eventer_t);
58 API_EXPORT(int)       eventer_timecompare(void *a, void *b);
59 API_EXPORT(int)       eventer_name_callback(const char *name, eventer_func_t f);
60 API_EXPORT(const char *)
61                       eventer_name_for_callback(eventer_func_t f);
62 API_EXPORT(eventer_func_t)
63                       eventer_callback_for_name(const char *name);
64
65 typedef struct _eventer_impl {
66   const char         *name;
67   int               (*init)();
68   int               (*propset)(const char *key, const char *value);
69   void              (*add)(eventer_t e);
70   eventer_t         (*remove)(eventer_t e);
71   void              (*update)(eventer_t e);
72   eventer_t         (*remove_fd)(int fd);
73   eventer_t         (*find_fd)(int fd);
74   int               (*loop)();
75 } *eventer_impl_t;
76
77 /* This is the "chosen one" */
78 #ifndef _EVENTER_C
79 extern
80 #endif
81 eventer_impl_t __eventer;
82
83 API_EXPORT(int) eventer_choose(const char *name);
84
85 #define eventer_propset       __eventer->propset
86 #define eventer_init          __eventer->init
87 #define eventer_add           __eventer->add
88 #define eventer_remove        __eventer->remove
89 #define eventer_update        __eventer->update
90 #define eventer_remove_fd     __eventer->remove_fd
91 #define eventer_find_fd       __eventer->find_fd
92 #define eventer_loop          __eventer->loop
93
94 #endif
Note: See TracBrowser for help on using the browser.