event_struct.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
  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 EVENT2_EVENT_STRUCT_H_INCLUDED_
  28. #define EVENT2_EVENT_STRUCT_H_INCLUDED_
  29. /** @file event2/event_struct.h
  30. Structures used by event.h. Using these structures directly WILL harm
  31. forward compatibility: be careful.
  32. No field declared in this file should be used directly in user code. Except
  33. for historical reasons, these fields would not be exposed at all.
  34. */
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. #include <event2/event-config.h>
  39. #ifdef EVENT__HAVE_SYS_TYPES_H
  40. #include <sys/types.h>
  41. #endif
  42. #ifdef EVENT__HAVE_SYS_TIME_H
  43. #include <sys/time.h>
  44. #endif
  45. /* For int types. */
  46. #include <event2/util.h>
  47. /* For evkeyvalq */
  48. #include <event2/keyvalq_struct.h>
  49. #define EVLIST_TIMEOUT 0x01
  50. #define EVLIST_INSERTED 0x02
  51. #define EVLIST_SIGNAL 0x04
  52. #define EVLIST_ACTIVE 0x08
  53. #define EVLIST_INTERNAL 0x10
  54. #define EVLIST_ACTIVE_LATER 0x20
  55. #define EVLIST_FINALIZING 0x40
  56. #define EVLIST_INIT 0x80
  57. #define EVLIST_ALL 0xff
  58. /* Fix so that people don't have to run with <sys/queue.h> */
  59. #ifndef TAILQ_ENTRY
  60. #define EVENT_DEFINED_TQENTRY_
  61. #define TAILQ_ENTRY(type) \
  62. struct { \
  63. struct type *tqe_next; /* next element */ \
  64. struct type **tqe_prev; /* address of previous next element */ \
  65. }
  66. #endif /* !TAILQ_ENTRY */
  67. #ifndef TAILQ_HEAD
  68. #define EVENT_DEFINED_TQHEAD_
  69. #define TAILQ_HEAD(name, type) \
  70. struct name { \
  71. struct type *tqh_first; \
  72. struct type **tqh_last; \
  73. }
  74. #endif
  75. /* Fix so that people don't have to run with <sys/queue.h> */
  76. #ifndef LIST_ENTRY
  77. #define EVENT_DEFINED_LISTENTRY_
  78. #define LIST_ENTRY(type) \
  79. struct { \
  80. struct type *le_next; /* next element */ \
  81. struct type **le_prev; /* address of previous next element */ \
  82. }
  83. #endif /* !LIST_ENTRY */
  84. #ifndef LIST_HEAD
  85. #define EVENT_DEFINED_LISTHEAD_
  86. #define LIST_HEAD(name, type) \
  87. struct name { \
  88. struct type *lh_first; /* first element */ \
  89. }
  90. #endif /* !LIST_HEAD */
  91. struct event;
  92. struct event_callback {
  93. TAILQ_ENTRY(event_callback) evcb_active_next;
  94. short evcb_flags;
  95. ev_uint8_t evcb_pri; /* smaller numbers are higher priority */
  96. ev_uint8_t evcb_closure;
  97. /* allows us to adopt for different types of events */
  98. union {
  99. void (*evcb_callback)(evutil_socket_t, short, void *);
  100. void (*evcb_selfcb)(struct event_callback *, void *);
  101. void (*evcb_evfinalize)(struct event *, void *);
  102. void (*evcb_cbfinalize)(struct event_callback *, void *);
  103. } evcb_cb_union;
  104. void *evcb_arg;
  105. };
  106. struct event_base;
  107. struct event {
  108. struct event_callback ev_evcallback;
  109. /* for managing timeouts */
  110. union {
  111. TAILQ_ENTRY(event) ev_next_with_common_timeout;
  112. int min_heap_idx;
  113. } ev_timeout_pos;
  114. evutil_socket_t ev_fd;
  115. struct event_base *ev_base;
  116. union {
  117. /* used for io events */
  118. struct {
  119. LIST_ENTRY (event) ev_io_next;
  120. struct timeval ev_timeout;
  121. } ev_io;
  122. /* used by signal events */
  123. struct {
  124. LIST_ENTRY (event) ev_signal_next;
  125. short ev_ncalls;
  126. /* Allows deletes in callback */
  127. short *ev_pncalls;
  128. } ev_signal;
  129. } ev_;
  130. short ev_events;
  131. short ev_res; /* result passed to event callback */
  132. struct timeval ev_timeout;
  133. };
  134. TAILQ_HEAD (event_list, event);
  135. #ifdef EVENT_DEFINED_TQENTRY_
  136. #undef TAILQ_ENTRY
  137. #endif
  138. #ifdef EVENT_DEFINED_TQHEAD_
  139. #undef TAILQ_HEAD
  140. #endif
  141. LIST_HEAD (event_dlist, event);
  142. #ifdef EVENT_DEFINED_LISTENTRY_
  143. #undef LIST_ENTRY
  144. #endif
  145. #ifdef EVENT_DEFINED_LISTHEAD_
  146. #undef LIST_HEAD
  147. #endif
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* EVENT2_EVENT_STRUCT_H_INCLUDED_ */