xref: /libevent-2.1.12/evmap-internal.h (revision 8ac3c4c2)
1169321c9SNick Mathewson /*
2e49e2891SNick Mathewson  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
3169321c9SNick Mathewson  *
4169321c9SNick Mathewson  * Redistribution and use in source and binary forms, with or without
5169321c9SNick Mathewson  * modification, are permitted provided that the following conditions
6169321c9SNick Mathewson  * are met:
7169321c9SNick Mathewson  * 1. Redistributions of source code must retain the above copyright
8169321c9SNick Mathewson  *    notice, this list of conditions and the following disclaimer.
9169321c9SNick Mathewson  * 2. Redistributions in binary form must reproduce the above copyright
10169321c9SNick Mathewson  *    notice, this list of conditions and the following disclaimer in the
11169321c9SNick Mathewson  *    documentation and/or other materials provided with the distribution.
12169321c9SNick Mathewson  * 3. The name of the author may not be used to endorse or promote products
13169321c9SNick Mathewson  *    derived from this software without specific prior written permission.
14169321c9SNick Mathewson  *
15169321c9SNick Mathewson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16169321c9SNick Mathewson  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17169321c9SNick Mathewson  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18169321c9SNick Mathewson  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19169321c9SNick Mathewson  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20169321c9SNick Mathewson  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21169321c9SNick Mathewson  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22169321c9SNick Mathewson  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23169321c9SNick Mathewson  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24169321c9SNick Mathewson  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25169321c9SNick Mathewson  */
263f8c7cd0SNick Mathewson #ifndef EVMAP_INTERNAL_H_INCLUDED_
273f8c7cd0SNick Mathewson #define EVMAP_INTERNAL_H_INCLUDED_
28169321c9SNick Mathewson 
29169321c9SNick Mathewson /** @file evmap-internal.h
30169321c9SNick Mathewson  *
31169321c9SNick Mathewson  * An event_map is a utility structure to map each fd or signal to zero or
32169321c9SNick Mathewson  * more events.  Functions to manipulate event_maps should only be used from
33a2a7d1d1SNick Mathewson  * inside libevent.  They generally need to hold the lock on the corresponding
34a2a7d1d1SNick Mathewson  * event_base.
35169321c9SNick Mathewson  **/
36169321c9SNick Mathewson 
37169321c9SNick Mathewson struct event_base;
38169321c9SNick Mathewson struct event;
39169321c9SNick Mathewson 
406bb2f842SNick Mathewson /** Initialize an event_map for use.
416bb2f842SNick Mathewson  */
42*8ac3c4c2SNick Mathewson void evmap_io_initmap_(struct event_io_map* ctx);
43*8ac3c4c2SNick Mathewson void evmap_signal_initmap_(struct event_signal_map* ctx);
446bb2f842SNick Mathewson 
45169321c9SNick Mathewson /** Remove all entries from an event_map.
46169321c9SNick Mathewson 
47169321c9SNick Mathewson 	@param ctx the map to clear.
48169321c9SNick Mathewson  */
49*8ac3c4c2SNick Mathewson void evmap_io_clear_(struct event_io_map* ctx);
50*8ac3c4c2SNick Mathewson void evmap_signal_clear_(struct event_signal_map* ctx);
51169321c9SNick Mathewson 
52169321c9SNick Mathewson /** Add an IO event (some combination of EV_READ or EV_WRITE) to an
53169321c9SNick Mathewson     event_base's list of events on a given file descriptor, and tell the
54169321c9SNick Mathewson     underlying eventops about the fd if its state has changed.
55169321c9SNick Mathewson 
56c247adc7SNick Mathewson     Requires that ev is not already added.
57c247adc7SNick Mathewson 
58169321c9SNick Mathewson     @param base the event_base to operate on.
59169321c9SNick Mathewson     @param fd the file descriptor corresponding to ev.
60169321c9SNick Mathewson     @param ev the event to add.
61169321c9SNick Mathewson */
62*8ac3c4c2SNick Mathewson int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev);
63169321c9SNick Mathewson /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an
64169321c9SNick Mathewson     event_base's list of events on a given file descriptor, and tell the
65169321c9SNick Mathewson     underlying eventops about the fd if its state has changed.
66169321c9SNick Mathewson 
67169321c9SNick Mathewson     @param base the event_base to operate on.
68169321c9SNick Mathewson     @param fd the file descriptor corresponding to ev.
69169321c9SNick Mathewson     @param ev the event to remove.
70169321c9SNick Mathewson  */
71*8ac3c4c2SNick Mathewson int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev);
72169321c9SNick Mathewson /** Active the set of events waiting on an event_base for a given fd.
73169321c9SNick Mathewson 
74169321c9SNick Mathewson     @param base the event_base to operate on.
75169321c9SNick Mathewson     @param fd the file descriptor that has become active.
76169321c9SNick Mathewson     @param events a bitmask of EV_READ|EV_WRITE|EV_ET.
77169321c9SNick Mathewson */
78*8ac3c4c2SNick Mathewson void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events);
79169321c9SNick Mathewson 
80c247adc7SNick Mathewson 
81c247adc7SNick Mathewson /* These functions behave in the same way as evmap_io_*, except they work on
82c247adc7SNick Mathewson  * signals rather than fds.  signals use a linear map everywhere; fds use
83c247adc7SNick Mathewson  * either a linear map or a hashtable. */
84*8ac3c4c2SNick Mathewson int evmap_signal_add_(struct event_base *base, int signum, struct event *ev);
85*8ac3c4c2SNick Mathewson int evmap_signal_del_(struct event_base *base, int signum, struct event *ev);
86*8ac3c4c2SNick Mathewson void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls);
87169321c9SNick Mathewson 
88c89b4e63SNick Mathewson /* Return the fdinfo object associated with a given fd.  If the fd has no
89c89b4e63SNick Mathewson  * events associated with it, the result may be NULL.
90c89b4e63SNick Mathewson  */
91*8ac3c4c2SNick Mathewson void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd);
92554e1493SNick Mathewson 
93c89b4e63SNick Mathewson /* Helper for event_reinit(): Tell the backend to re-add every fd and signal
94c89b4e63SNick Mathewson  * for which we have a pending event.
95c89b4e63SNick Mathewson  */
96*8ac3c4c2SNick Mathewson int evmap_reinit_(struct event_base *base);
97272033efSNick Mathewson 
98c89b4e63SNick Mathewson /* Helper for event_base_free(): Call event_del() on every pending fd and
99c89b4e63SNick Mathewson  * signal event.
100c89b4e63SNick Mathewson  */
101*8ac3c4c2SNick Mathewson void evmap_delete_all_(struct event_base *base);
102604569bfSNick Mathewson 
103*8ac3c4c2SNick Mathewson /* Helper for event_base_assert_ok_(): Check referential integrity of the
104c89b4e63SNick Mathewson  * evmaps.
105c89b4e63SNick Mathewson  */
106*8ac3c4c2SNick Mathewson void evmap_check_integrity_(struct event_base *base);
10727737d55SNick Mathewson 
108c89b4e63SNick Mathewson /* Helper: Call fn on every fd or signal event, passing as its arguments the
109c89b4e63SNick Mathewson  * provided event_base, the event, and arg.  If fn returns 0, process the next
110c89b4e63SNick Mathewson  * event.  If it returns any other value, return that value and process no
111c89b4e63SNick Mathewson  * more events.
112c89b4e63SNick Mathewson  */
113*8ac3c4c2SNick Mathewson int evmap_foreach_event_(struct event_base *base,
114c89b4e63SNick Mathewson     event_base_foreach_event_cb fn,
115c89b4e63SNick Mathewson     void *arg);
116c89b4e63SNick Mathewson 
1173f8c7cd0SNick Mathewson #endif /* EVMAP_INTERNAL_H_INCLUDED_ */
118