xref: /netbsd-src/external/bsd/ntp/dist/sntp/libevent/evmap-internal.h (revision cdfa2a7ef92791ba9db70a584a1d904730e6fb46)
1 /*	$NetBSD: evmap-internal.h,v 1.5 2020/05/25 20:47:33 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef EVMAP_INTERNAL_H_INCLUDED_
29 #define EVMAP_INTERNAL_H_INCLUDED_
30 
31 /** @file evmap-internal.h
32  *
33  * An event_map is a utility structure to map each fd or signal to zero or
34  * more events.  Functions to manipulate event_maps should only be used from
35  * inside libevent.  They generally need to hold the lock on the corresponding
36  * event_base.
37  **/
38 
39 struct event_base;
40 struct event;
41 
42 /** Initialize an event_map for use.
43  */
44 void evmap_io_initmap_(struct event_io_map* ctx);
45 void evmap_signal_initmap_(struct event_signal_map* ctx);
46 
47 /** Remove all entries from an event_map.
48 
49 	@param ctx the map to clear.
50  */
51 void evmap_io_clear_(struct event_io_map* ctx);
52 void evmap_signal_clear_(struct event_signal_map* ctx);
53 
54 /** Add an IO event (some combination of EV_READ or EV_WRITE) to an
55     event_base's list of events on a given file descriptor, and tell the
56     underlying eventops about the fd if its state has changed.
57 
58     Requires that ev is not already added.
59 
60     @param base the event_base to operate on.
61     @param fd the file descriptor corresponding to ev.
62     @param ev the event to add.
63 */
64 int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev);
65 /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an
66     event_base's list of events on a given file descriptor, and tell the
67     underlying eventops about the fd if its state has changed.
68 
69     @param base the event_base to operate on.
70     @param fd the file descriptor corresponding to ev.
71     @param ev the event to remove.
72  */
73 int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev);
74 /** Active the set of events waiting on an event_base for a given fd.
75 
76     @param base the event_base to operate on.
77     @param fd the file descriptor that has become active.
78     @param events a bitmask of EV_READ|EV_WRITE|EV_ET.
79 */
80 void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events);
81 
82 
83 /* These functions behave in the same way as evmap_io_*, except they work on
84  * signals rather than fds.  signals use a linear map everywhere; fds use
85  * either a linear map or a hashtable. */
86 int evmap_signal_add_(struct event_base *base, int signum, struct event *ev);
87 int evmap_signal_del_(struct event_base *base, int signum, struct event *ev);
88 void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls);
89 
90 /* Return the fdinfo object associated with a given fd.  If the fd has no
91  * events associated with it, the result may be NULL.
92  */
93 void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd);
94 
95 /* Helper for event_reinit(): Tell the backend to re-add every fd and signal
96  * for which we have a pending event.
97  */
98 int evmap_reinit_(struct event_base *base);
99 
100 /* Helper for event_base_free(): Call event_del() on every pending fd and
101  * signal event.
102  */
103 void evmap_delete_all_(struct event_base *base);
104 
105 /* Helper for event_base_assert_ok_(): Check referential integrity of the
106  * evmaps.
107  */
108 void evmap_check_integrity_(struct event_base *base);
109 
110 /* Helper: Call fn on every fd or signal event, passing as its arguments the
111  * provided event_base, the event, and arg.  If fn returns 0, process the next
112  * event.  If it returns any other value, return that value and process no
113  * more events.
114  */
115 int evmap_foreach_event_(struct event_base *base,
116     event_base_foreach_event_cb fn,
117     void *arg);
118 
119 #endif /* EVMAP_INTERNAL_H_INCLUDED_ */
120