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