evmap-internal.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. /** @file evmap-internal.h
  29. *
  30. * An event_map is a utility structure to map each fd or signal to zero or
  31. * more events. Functions to manipulate event_maps should only be used from
  32. * inside libevent. They generally need to hold the lock on the corresponding
  33. * event_base.
  34. **/
  35. struct event_base;
  36. struct event;
  37. /** Initialize an event_map for use.
  38. */
  39. void evmap_io_initmap_(struct event_io_map* ctx);
  40. void evmap_signal_initmap_(struct event_signal_map* ctx);
  41. /** Remove all entries from an event_map.
  42. @param ctx the map to clear.
  43. */
  44. void evmap_io_clear_(struct event_io_map* ctx);
  45. void evmap_signal_clear_(struct event_signal_map* ctx);
  46. /** Add an IO event (some combination of EV_READ or EV_WRITE) to an
  47. event_base's list of events on a given file descriptor, and tell the
  48. underlying eventops about the fd if its state has changed.
  49. Requires that ev is not already added.
  50. @param base the event_base to operate on.
  51. @param fd the file descriptor corresponding to ev.
  52. @param ev the event to add.
  53. */
  54. int evmap_io_add_(struct event_base *base, evutil_socket_t fd, struct event *ev);
  55. /** Remove an IO event (some combination of EV_READ or EV_WRITE) to an
  56. event_base's list of events on a given file descriptor, and tell the
  57. underlying eventops about the fd if its state has changed.
  58. @param base the event_base to operate on.
  59. @param fd the file descriptor corresponding to ev.
  60. @param ev the event to remove.
  61. */
  62. int evmap_io_del_(struct event_base *base, evutil_socket_t fd, struct event *ev);
  63. /** Active the set of events waiting on an event_base for a given fd.
  64. @param base the event_base to operate on.
  65. @param fd the file descriptor that has become active.
  66. @param events a bitmask of EV_READ|EV_WRITE|EV_ET.
  67. */
  68. void evmap_io_active_(struct event_base *base, evutil_socket_t fd, short events);
  69. /* These functions behave in the same way as evmap_io_*, except they work on
  70. * signals rather than fds. signals use a linear map everywhere; fds use
  71. * either a linear map or a hashtable. */
  72. int evmap_signal_add_(struct event_base *base, int signum, struct event *ev);
  73. int evmap_signal_del_(struct event_base *base, int signum, struct event *ev);
  74. void evmap_signal_active_(struct event_base *base, evutil_socket_t signum, int ncalls);
  75. /* Return the fdinfo object associated with a given fd. If the fd has no
  76. * events associated with it, the result may be NULL.
  77. */
  78. void *evmap_io_get_fdinfo_(struct event_io_map *ctx, evutil_socket_t fd);
  79. /* Helper for event_reinit(): Tell the backend to re-add every fd and signal
  80. * for which we have a pending event.
  81. */
  82. int evmap_reinit_(struct event_base *base);
  83. /* Helper for event_base_free(): Call event_del() on every pending fd and
  84. * signal event.
  85. */
  86. void evmap_delete_all_(struct event_base *base);
  87. /* Helper for event_base_assert_ok_(): Check referential integrity of the
  88. * evmaps.
  89. */
  90. void evmap_check_integrity_(struct event_base *base);
  91. /* Helper: Call fn on every fd or signal event, passing as its arguments the
  92. * provided event_base, the event, and arg. If fn returns 0, process the next
  93. * event. If it returns any other value, return that value and process no
  94. * more events.
  95. */
  96. int evmap_foreach_event_(struct event_base *base,
  97. event_base_foreach_event_cb fn,
  98. void *arg);
  99. #endif /* EVMAP_INTERNAL_H_INCLUDED_ */