1290001Sglebius/* 2290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3290001Sglebius * 4290001Sglebius * Redistribution and use in source and binary forms, with or without 5290001Sglebius * modification, are permitted provided that the following conditions 6290001Sglebius * are met: 7290001Sglebius * 1. Redistributions of source code must retain the above copyright 8290001Sglebius * notice, this list of conditions and the following disclaimer. 9290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright 10290001Sglebius * notice, this list of conditions and the following disclaimer in the 11290001Sglebius * documentation and/or other materials provided with the distribution. 12290001Sglebius * 3. The name of the author may not be used to endorse or promote products 13290001Sglebius * derived from this software without specific prior written permission. 14290001Sglebius * 15290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25290001Sglebius */ 26290001Sglebius#ifndef EVMAP_INTERNAL_H_INCLUDED_ 27290001Sglebius#define EVMAP_INTERNAL_H_INCLUDED_ 28290001Sglebius 29290001Sglebius/** @file evmap-internal.h 30290001Sglebius * 31290001Sglebius * An event_map is a utility structure to map each fd or signal to zero or 32290001Sglebius * more events. Functions to manipulate event_maps should only be used from 33290001Sglebius * inside libevent. They generally need to hold the lock on the corresponding 34290001Sglebius * event_base. 35290001Sglebius **/ 36290001Sglebius 37290001Sglebiusstruct event_base; 38290001Sglebiusstruct event; 39290001Sglebius 40290001Sglebius/** Initialize an event_map for use. 41290001Sglebius */ 42290001Sglebiusvoid evmap_io_initmap_(struct event_io_map* ctx); 43290001Sglebiusvoid evmap_signal_initmap_(struct event_signal_map* ctx); 44290001Sglebius 45290001Sglebius/** Remove all entries from an event_map. 46290001Sglebius 47290001Sglebius @param ctx the map to clear. 48290001Sglebius */ 49290001Sglebiusvoid evmap_io_clear_(struct event_io_map* ctx); 50290001Sglebiusvoid evmap_signal_clear_(struct event_signal_map* ctx); 51290001Sglebius 52290001Sglebius/** Add an IO event (some combination of EV_READ or EV_WRITE) to an 53290001Sglebius event_base's list of events on a given file descriptor, and tell the 54290001Sglebius underlying eventops about the fd if its state has changed. 55290001Sglebius 56290001Sglebius Requires that ev is not already added. 57290001Sglebius 58290001Sglebius @param base the event_base to operate on. 59290001Sglebius @param fd the file descriptor corresponding to ev. 60290001Sglebius @param ev the event to add. 61290001Sglebius*/ 62290001Sglebiusint evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev); 63290001Sglebius/** Remove an IO event (some combination of EV_READ or EV_WRITE) to an 64290001Sglebius event_base's list of events on a given file descriptor, and tell the 65290001Sglebius underlying eventops about the fd if its state has changed. 66290001Sglebius 67290001Sglebius @param base the event_base to operate on. 68290001Sglebius @param fd the file descriptor corresponding to ev. 69290001Sglebius @param ev the event to remove. 70290001Sglebius */ 71290001Sglebiusint evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev); 72290001Sglebius/** Active the set of events waiting on an event_base for a given fd. 73290001Sglebius 74290001Sglebius @param base the event_base to operate on. 75290001Sglebius @param fd the file descriptor that has become active. 76290001Sglebius @param events a bitmask of EV_READ|EV_WRITE|EV_ET. 77290001Sglebius*/ 78290001Sglebiusvoid evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events); 79290001Sglebius 80290001Sglebius 81290001Sglebius/* These functions behave in the same way as evmap_io_*, except they work on 82290001Sglebius * signals rather than fds. signals use a linear map everywhere; fds use 83290001Sglebius * either a linear map or a hashtable. */ 84290001Sglebiusint evmap_signal_add_(struct event_base *base, int signum, struct event *ev); 85290001Sglebiusint evmap_signal_del_(struct event_base *base, int signum, struct event *ev); 86290001Sglebiusvoid evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls); 87290001Sglebius 88290001Sglebius/* Return the fdinfo object associated with a given fd. If the fd has no 89290001Sglebius * events associated with it, the result may be NULL. 90290001Sglebius */ 91290001Sglebiusvoid *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd); 92290001Sglebius 93290001Sglebius/* Helper for event_reinit(): Tell the backend to re-add every fd and signal 94290001Sglebius * for which we have a pending event. 95290001Sglebius */ 96290001Sglebiusint evmap_reinit_(struct event_base *base); 97290001Sglebius 98290001Sglebius/* Helper for event_base_free(): Call event_del() on every pending fd and 99290001Sglebius * signal event. 100290001Sglebius */ 101290001Sglebiusvoid evmap_delete_all_(struct event_base *base); 102290001Sglebius 103290001Sglebius/* Helper for event_base_assert_ok_(): Check referential integrity of the 104290001Sglebius * evmaps. 105290001Sglebius */ 106290001Sglebiusvoid evmap_check_integrity_(struct event_base *base); 107290001Sglebius 108290001Sglebius/* Helper: Call fn on every fd or signal event, passing as its arguments the 109290001Sglebius * provided event_base, the event, and arg. If fn returns 0, process the next 110290001Sglebius * event. If it returns any other value, return that value and process no 111290001Sglebius * more events. 112290001Sglebius */ 113290001Sglebiusint evmap_foreach_event_(struct event_base *base, 114290001Sglebius event_base_foreach_event_cb fn, 115290001Sglebius void *arg); 116290001Sglebius 117290001Sglebius#endif /* EVMAP_INTERNAL_H_INCLUDED_ */ 118