1 /* $NetBSD: evmap-internal.h,v 1.1.1.1 2013/04/11 16:43:19 christos Exp $ */ 2 /* 3 * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 #ifndef _EVMAP_H_ 28 #define _EVMAP_H_ 29 30 /** @file evmap-internal.h 31 * 32 * An event_map is a utility structure to map each fd or signal to zero or 33 * more events. Functions to manipulate event_maps should only be used from 34 * inside libevent. They generally need to hold the lock on the corresponding 35 * event_base. 36 **/ 37 38 struct event_base; 39 struct event; 40 41 /** Initialize an event_map for use. 42 */ 43 void evmap_io_initmap(struct event_io_map* ctx); 44 void evmap_signal_initmap(struct event_signal_map* ctx); 45 46 /** Remove all entries from an event_map. 47 48 @param ctx the map to clear. 49 */ 50 void evmap_io_clear(struct event_io_map* ctx); 51 void evmap_signal_clear(struct event_signal_map* ctx); 52 53 /** Add an IO event (some combination of EV_READ or EV_WRITE) to an 54 event_base's list of events on a given file descriptor, and tell the 55 underlying eventops about the fd if its state has changed. 56 57 Requires that ev is not already added. 58 59 @param base the event_base to operate on. 60 @param fd the file descriptor corresponding to ev. 61 @param ev the event to add. 62 */ 63 int evmap_io_add(struct event_base *base, evutil_socket_t fd, struct event *ev); 64 /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an 65 event_base's list of events on a given file descriptor, and tell the 66 underlying eventops about the fd if its state has changed. 67 68 @param base the event_base to operate on. 69 @param fd the file descriptor corresponding to ev. 70 @param ev the event to remove. 71 */ 72 int evmap_io_del(struct event_base *base, evutil_socket_t fd, struct event *ev); 73 /** Active the set of events waiting on an event_base for a given fd. 74 75 @param base the event_base to operate on. 76 @param fd the file descriptor that has become active. 77 @param events a bitmask of EV_READ|EV_WRITE|EV_ET. 78 */ 79 void evmap_io_active(struct event_base *base, evutil_socket_t fd, short events); 80 81 82 /* These functions behave in the same way as evmap_io_*, except they work on 83 * signals rather than fds. signals use a linear map everywhere; fds use 84 * either a linear map or a hashtable. */ 85 int evmap_signal_add(struct event_base *base, int signum, struct event *ev); 86 int evmap_signal_del(struct event_base *base, int signum, struct event *ev); 87 void evmap_signal_active(struct event_base *base, evutil_socket_t signum, int ncalls); 88 89 void *evmap_io_get_fdinfo(struct event_io_map *ctx, evutil_socket_t fd); 90 91 void evmap_check_integrity(struct event_base *base); 92 93 #endif /* _EVMAP_H_ */ 94