Electroneum
Loading...
Searching...
No Matches
mini_event.h
Go to the documentation of this file.
1/*
2 * mini-event.h - micro implementation of libevent api, using select() only.
3 *
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
5 *
6 * This software is open source.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * Neither the name of the NLNET LABS nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
51
52#ifndef MINI_EVENT_H
53#define MINI_EVENT_H
54
55#if defined(USE_MINI_EVENT) && !defined(USE_WINSOCK)
56
57#ifndef HAVE_EVENT_BASE_FREE
58#define HAVE_EVENT_BASE_FREE
59#endif
60
61/* redefine to use our own namespace so that on platforms where
62 * linkers crosslink library-private symbols with other symbols, it works */
63#define event_init minievent_init
64#define event_get_version minievent_get_version
65#define event_get_method minievent_get_method
66#define event_base_dispatch minievent_base_dispatch
67#define event_base_loopexit minievent_base_loopexit
68#define event_base_free minievent_base_free
69#define event_set minievent_set
70#define event_base_set minievent_base_set
71#define event_add minievent_add
72#define event_del minievent_del
73#define signal_add minisignal_add
74#define signal_del minisignal_del
75
77#define EV_TIMEOUT 0x01
79#define EV_READ 0x02
81#define EV_WRITE 0x04
83#define EV_SIGNAL 0x08
85#define EV_PERSIST 0x10
86
87/* needs our redblack tree */
88#include "rbtree.h"
89
91#define MAX_FDS 1024
93#define MAX_SIG 32
94
96struct event_base
97{
99 rbtree_type* times;
101 struct event** fds;
103 int maxfd;
105 int capfd;
106 /* fdset for read write, for fds ready, and added */
107 fd_set
109 reads,
111 writes,
113 ready,
115 content;
117 struct event** signals;
119 int need_to_exit;
121 time_t* time_secs;
123 struct timeval* time_tv;
124};
125
129struct event {
131 rbnode_type node;
133 int added;
134
136 struct event_base *ev_base;
138 int ev_fd;
140 short ev_events;
142 struct timeval ev_timeout;
143
145 void (*ev_callback)(int, short, void *arg);
147 void *ev_arg;
148};
149
150/* function prototypes (some are as they appear in event.h) */
152void *event_init(time_t* time_secs, struct timeval* time_tv);
154const char *event_get_version(void);
156const char *event_get_method(void);
158int event_base_dispatch(struct event_base *);
160int event_base_loopexit(struct event_base *, struct timeval *);
162void event_base_free(struct event_base *);
164void event_set(struct event *, int, short, void (*)(int, short, void *), void *);
166int event_base_set(struct event_base *, struct event *);
168int event_add(struct event *, struct timeval *);
170int event_del(struct event *);
171
173#define evtimer_add(ev, tv) event_add(ev, tv)
175#define evtimer_del(ev) event_del(ev)
176
177/* uses different implementation. Cannot mix fd/timeouts and signals inside
178 * the same struct event. create several event structs for that. */
180int signal_add(struct event *, struct timeval *);
182#define signal_set(ev, x, cb, arg) \
183 event_set(ev, x, EV_SIGNAL|EV_PERSIST, cb, arg)
185int signal_del(struct event *);
186
187#endif /* USE_MINI_EVENT and not USE_WINSOCK */
188
190int mini_ev_cmp(const void* a, const void* b);
191
192#endif /* MINI_EVENT_H */
int mini_ev_cmp(const void *a, const void *b)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1124
struct rbnode_type rbnode_type
Definition rbtree.h:51
struct rbtree_type rbtree_type
Definition rbtree.h:74