/*1* Copyright (c) 2007-2012 Niels Provos and Nick Mathewson2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions and the following disclaimer.8* 2. Redistributions in binary form must reproduce the above copyright9* notice, this list of conditions and the following disclaimer in the10* documentation and/or other materials provided with the distribution.11* 3. The name of the author may not be used to endorse or promote products12* derived from this software without specific prior written permission.13*14* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR15* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES16* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.17* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,18* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT19* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,20* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY21* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF23* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/25#ifndef EVMAP_INTERNAL_H_INCLUDED_26#define EVMAP_INTERNAL_H_INCLUDED_2728/** @file evmap-internal.h29*30* An event_map is a utility structure to map each fd or signal to zero or31* more events. Functions to manipulate event_maps should only be used from32* inside libevent. They generally need to hold the lock on the corresponding33* event_base.34**/3536struct event_base;37struct event;3839/** Initialize an event_map for use.40*/41void evmap_io_initmap_(struct event_io_map* ctx);42void evmap_signal_initmap_(struct event_signal_map* ctx);4344/** Remove all entries from an event_map.4546@param ctx the map to clear.47*/48void evmap_io_clear_(struct event_io_map* ctx);49void evmap_signal_clear_(struct event_signal_map* ctx);5051/** Add an IO event (some combination of EV_READ or EV_WRITE) to an52event_base's list of events on a given file descriptor, and tell the53underlying eventops about the fd if its state has changed.5455Requires that ev is not already added.5657@param base the event_base to operate on.58@param fd the file descriptor corresponding to ev.59@param ev the event to add.60*/61int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev);62/** Remove an IO event (some combination of EV_READ or EV_WRITE) to an63event_base's list of events on a given file descriptor, and tell the64underlying eventops about the fd if its state has changed.6566@param base the event_base to operate on.67@param fd the file descriptor corresponding to ev.68@param ev the event to remove.69*/70int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev);71/** Active the set of events waiting on an event_base for a given fd.7273@param base the event_base to operate on.74@param fd the file descriptor that has become active.75@param events a bitmask of EV_READ|EV_WRITE|EV_ET.76*/77void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events);787980/* These functions behave in the same way as evmap_io_*, except they work on81* signals rather than fds. signals use a linear map everywhere; fds use82* either a linear map or a hashtable. */83int evmap_signal_add_(struct event_base *base, int signum, struct event *ev);84int evmap_signal_del_(struct event_base *base, int signum, struct event *ev);85void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls);8687/* Return the fdinfo object associated with a given fd. If the fd has no88* events associated with it, the result may be NULL.89*/90void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd);9192/* Helper for event_reinit(): Tell the backend to re-add every fd and signal93* for which we have a pending event.94*/95int evmap_reinit_(struct event_base *base);9697/* Helper for event_base_free(): Call event_del() on every pending fd and98* signal event.99*/100void evmap_delete_all_(struct event_base *base);101102/* Helper for event_base_assert_ok_(): Check referential integrity of the103* evmaps.104*/105void evmap_check_integrity_(struct event_base *base);106107/* Helper: Call fn on every fd or signal event, passing as its arguments the108* provided event_base, the event, and arg. If fn returns 0, process the next109* event. If it returns any other value, return that value and process no110* more events.111*/112int evmap_foreach_event_(struct event_base *base,113event_base_foreach_event_cb fn,114void *arg);115116#endif /* EVMAP_INTERNAL_H_INCLUDED_ */117118119