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