event_struct.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_
  28. #define _EVENT2_EVENT_STRUCT_H_
  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_INIT 0x80
  55. /* EVLIST_X_ Private space: 0x1000-0xf000 */
  56. #define EVLIST_ALL (0xf000 | 0x9f)
  57. /* Fix so that people don't have to run with <sys/queue.h> */
  58. #ifndef TAILQ_ENTRY
  59. #define _EVENT_DEFINED_TQENTRY
  60. #define TAILQ_ENTRY(type) \
  61. struct { \
  62. struct type *tqe_next; /* next element */ \
  63. struct type **tqe_prev; /* address of previous next element */ \
  64. }
  65. #endif /* !TAILQ_ENTRY */
  66. #ifndef TAILQ_HEAD
  67. #define _EVENT_DEFINED_TQHEAD
  68. #define TAILQ_HEAD(name, type) \
  69. struct name { \
  70. struct type *tqh_first; \
  71. struct type **tqh_last; \
  72. }
  73. #endif
  74. struct event_base;
  75. struct event {
  76. TAILQ_ENTRY(event) ev_active_next;
  77. TAILQ_ENTRY(event) ev_next;
  78. /* for managing timeouts */
  79. union {
  80. TAILQ_ENTRY(event) ev_next_with_common_timeout;
  81. int min_heap_idx;
  82. } ev_timeout_pos;
  83. evutil_socket_t ev_fd;
  84. struct event_base *ev_base;
  85. union {
  86. /* used for io events */
  87. struct {
  88. TAILQ_ENTRY(event) ev_io_next;
  89. struct timeval ev_timeout;
  90. } ev_io;
  91. /* used by signal events */
  92. struct {
  93. TAILQ_ENTRY(event) ev_signal_next;
  94. short ev_ncalls;
  95. /* Allows deletes in callback */
  96. short *ev_pncalls;
  97. } ev_signal;
  98. } _ev;
  99. short ev_events;
  100. short ev_res; /* result passed to event callback */
  101. short ev_flags;
  102. ev_uint8_t ev_pri; /* smaller numbers are higher priority */
  103. ev_uint8_t ev_closure;
  104. struct timeval ev_timeout;
  105. /* allows us to adopt for different types of events */
  106. void (*ev_callback)(evutil_socket_t, short, void *arg);
  107. void *ev_arg;
  108. };
  109. TAILQ_HEAD (event_list, event);
  110. #ifdef _EVENT_DEFINED_TQENTRY
  111. #undef TAILQ_ENTRY
  112. #endif
  113. #ifdef _EVENT_DEFINED_TQHEAD
  114. #undef TAILQ_HEAD
  115. #endif
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* _EVENT2_EVENT_STRUCT_H_ */