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