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