Add to git.
[pthrlib.git] / src / pthr_reactor.h
1 /* A specialized Reactor.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  * $Id: pthr_reactor.h,v 1.3 2002/08/21 10:42:20 rich Exp $
19  */
20
21 #ifndef PTHR_REACTOR_H
22 #define PTHR_REACTOR_H
23
24 #include <sys/poll.h>
25
26 #include <pool.h>
27
28 /* A reactor handle. */
29 struct reactor_handle;
30 typedef int reactor_handle;     /* These are offsets into a private array
31                                  * of struct reactor_handle.
32                                  */
33
34 /* A timer. */
35 struct reactor_timer;
36 typedef struct reactor_timer *reactor_timer;
37
38 /* Pre-poll handlers. */
39 struct reactor_prepoll;
40 typedef struct reactor_prepoll *reactor_prepoll;
41
42 /* Reactor operations. */
43 #define REACTOR_READ  POLLIN
44 #define REACTOR_WRITE POLLOUT
45
46 /* Reactor time types. */
47 typedef unsigned long long reactor_time_t;
48 typedef signed long long reactor_timediff_t;
49
50 /* Reactor time in milliseconds from Unix epoch. */
51 extern reactor_time_t reactor_time;
52
53 /* Reactor functions. */
54 extern reactor_handle reactor_register (int socket, int operations,
55                                         void (*fn) (int socket, int events,
56                                                     void *data),
57                                         void *data);
58 extern void reactor_unregister (reactor_handle handle);
59 extern reactor_timer reactor_set_timer (pool, int timeout,
60                                         void (*fn) (void *data),
61                                         void *data);
62 extern void reactor_unset_timer_early (reactor_timer timer);
63 extern reactor_prepoll reactor_register_prepoll (pool, void (*fn) (void *data),
64                                                  void *data);
65 extern void reactor_unregister_prepoll (reactor_prepoll handle);
66 extern void reactor_invoke (void);
67
68 #endif /* PTHR_REACTOR_H */