event-internal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
  3. * All rights reserved.
  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 _EVENT_INTERNAL_H_
  28. #define _EVENT_INTERNAL_H_
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #include "config.h"
  33. #include "min_heap.h"
  34. #include "evsignal.h"
  35. struct eventop {
  36. const char *name;
  37. void *(*init)(struct event_base *);
  38. int (*add)(void *, struct event *);
  39. int (*del)(void *, struct event *);
  40. int (*dispatch)(struct event_base *, void *, struct timeval *);
  41. void (*dealloc)(struct event_base *, void *);
  42. /* set if we need to reinitialize the event base */
  43. int need_reinit;
  44. };
  45. struct event_base {
  46. const struct eventop *evsel;
  47. void *evbase;
  48. int event_count; /* counts number of total events */
  49. int event_count_active; /* counts number of active events */
  50. int event_gotterm; /* Set to terminate loop */
  51. int event_break; /* Set to terminate loop immediately */
  52. /* active event management */
  53. struct event_list **activequeues;
  54. int nactivequeues;
  55. /* signal handling info */
  56. struct evsignal_info sig;
  57. struct event_list eventqueue;
  58. struct timeval event_tv;
  59. struct min_heap timeheap;
  60. struct timeval tv_cache;
  61. };
  62. /* Internal use only: Functions that might be missing from <sys/queue.h> */
  63. #ifndef HAVE_TAILQFOREACH
  64. #define TAILQ_FIRST(head) ((head)->tqh_first)
  65. #define TAILQ_END(head) NULL
  66. #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  67. #define TAILQ_FOREACH(var, head, field) \
  68. for((var) = TAILQ_FIRST(head); \
  69. (var) != TAILQ_END(head); \
  70. (var) = TAILQ_NEXT(var, field))
  71. #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  72. (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  73. (elm)->field.tqe_next = (listelm); \
  74. *(listelm)->field.tqe_prev = (elm); \
  75. (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  76. } while (0)
  77. #endif /* TAILQ_FOREACH */
  78. int _evsignal_set_handler(struct event_base *base, int evsignal,
  79. void (*fn)(int));
  80. int _evsignal_restore_handler(struct event_base *base, int evsignal);
  81. /* defined in evutil.c */
  82. const char *evutil_getenv(const char *varname);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* _EVENT_INTERNAL_H_ */