1275970Scy/* 2275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3275970Scy * 4275970Scy * Redistribution and use in source and binary forms, with or without 5275970Scy * modification, are permitted provided that the following conditions 6275970Scy * are met: 7275970Scy * 1. Redistributions of source code must retain the above copyright 8275970Scy * notice, this list of conditions and the following disclaimer. 9275970Scy * 2. Redistributions in binary form must reproduce the above copyright 10275970Scy * notice, this list of conditions and the following disclaimer in the 11275970Scy * documentation and/or other materials provided with the distribution. 12275970Scy * 3. The name of the author may not be used to endorse or promote products 13275970Scy * derived from this software without specific prior written permission. 14275970Scy * 15275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25275970Scy */ 26275970Scy#ifndef EVMAP_INTERNAL_H_INCLUDED_ 27275970Scy#define EVMAP_INTERNAL_H_INCLUDED_ 28275970Scy 29275970Scy/** @file evmap-internal.h 30275970Scy * 31275970Scy * An event_map is a utility structure to map each fd or signal to zero or 32275970Scy * more events. Functions to manipulate event_maps should only be used from 33275970Scy * inside libevent. They generally need to hold the lock on the corresponding 34275970Scy * event_base. 35275970Scy **/ 36275970Scy 37275970Scystruct event_base; 38275970Scystruct event; 39275970Scy 40275970Scy/** Initialize an event_map for use. 41275970Scy */ 42275970Scyvoid evmap_io_initmap_(struct event_io_map* ctx); 43275970Scyvoid evmap_signal_initmap_(struct event_signal_map* ctx); 44275970Scy 45275970Scy/** Remove all entries from an event_map. 46275970Scy 47275970Scy @param ctx the map to clear. 48275970Scy */ 49275970Scyvoid evmap_io_clear_(struct event_io_map* ctx); 50275970Scyvoid evmap_signal_clear_(struct event_signal_map* ctx); 51275970Scy 52275970Scy/** Add an IO event (some combination of EV_READ or EV_WRITE) to an 53275970Scy event_base's list of events on a given file descriptor, and tell the 54275970Scy underlying eventops about the fd if its state has changed. 55275970Scy 56275970Scy Requires that ev is not already added. 57275970Scy 58275970Scy @param base the event_base to operate on. 59275970Scy @param fd the file descriptor corresponding to ev. 60275970Scy @param ev the event to add. 61275970Scy*/ 62275970Scyint evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev); 63275970Scy/** Remove an IO event (some combination of EV_READ or EV_WRITE) to an 64275970Scy event_base's list of events on a given file descriptor, and tell the 65275970Scy underlying eventops about the fd if its state has changed. 66275970Scy 67275970Scy @param base the event_base to operate on. 68275970Scy @param fd the file descriptor corresponding to ev. 69275970Scy @param ev the event to remove. 70275970Scy */ 71275970Scyint evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev); 72275970Scy/** Active the set of events waiting on an event_base for a given fd. 73275970Scy 74275970Scy @param base the event_base to operate on. 75275970Scy @param fd the file descriptor that has become active. 76275970Scy @param events a bitmask of EV_READ|EV_WRITE|EV_ET. 77275970Scy*/ 78275970Scyvoid evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events); 79275970Scy 80275970Scy 81275970Scy/* These functions behave in the same way as evmap_io_*, except they work on 82275970Scy * signals rather than fds. signals use a linear map everywhere; fds use 83275970Scy * either a linear map or a hashtable. */ 84275970Scyint evmap_signal_add_(struct event_base *base, int signum, struct event *ev); 85275970Scyint evmap_signal_del_(struct event_base *base, int signum, struct event *ev); 86275970Scyvoid evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls); 87275970Scy 88275970Scy/* Return the fdinfo object associated with a given fd. If the fd has no 89275970Scy * events associated with it, the result may be NULL. 90275970Scy */ 91275970Scyvoid *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd); 92275970Scy 93275970Scy/* Helper for event_reinit(): Tell the backend to re-add every fd and signal 94275970Scy * for which we have a pending event. 95275970Scy */ 96275970Scyint evmap_reinit_(struct event_base *base); 97275970Scy 98275970Scy/* Helper for event_base_free(): Call event_del() on every pending fd and 99275970Scy * signal event. 100275970Scy */ 101275970Scyvoid evmap_delete_all_(struct event_base *base); 102275970Scy 103275970Scy/* Helper for event_base_assert_ok_(): Check referential integrity of the 104275970Scy * evmaps. 105275970Scy */ 106275970Scyvoid evmap_check_integrity_(struct event_base *base); 107275970Scy 108275970Scy/* Helper: Call fn on every fd or signal event, passing as its arguments the 109275970Scy * provided event_base, the event, and arg. If fn returns 0, process the next 110275970Scy * event. If it returns any other value, return that value and process no 111275970Scy * more events. 112275970Scy */ 113275970Scyint evmap_foreach_event_(struct event_base *base, 114275970Scy event_base_foreach_event_cb fn, 115275970Scy void *arg); 116275970Scy 117275970Scy#endif /* EVMAP_INTERNAL_H_INCLUDED_ */ 118