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