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