wepoll.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * wepoll - epoll for Windows
  3. * https://github.com/piscisaureus/wepoll
  4. *
  5. * Copyright 2012-2018, Bert Belder <bertbelder@gmail.com>
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are
  10. * met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef WEPOLL_H_
  32. #define WEPOLL_H_
  33. #ifndef WEPOLL_EXPORT
  34. #define WEPOLL_EXPORT
  35. #endif
  36. #include <stdint.h>
  37. /* clang-format off */
  38. enum EPOLL_EVENTS {
  39. EPOLLIN = (int) (1U << 0),
  40. EPOLLPRI = (int) (1U << 1),
  41. EPOLLOUT = (int) (1U << 2),
  42. EPOLLERR = (int) (1U << 3),
  43. EPOLLHUP = (int) (1U << 4),
  44. EPOLLRDNORM = (int) (1U << 6),
  45. EPOLLRDBAND = (int) (1U << 7),
  46. EPOLLWRNORM = (int) (1U << 8),
  47. EPOLLWRBAND = (int) (1U << 9),
  48. EPOLLMSG = (int) (1U << 10), /* Never reported. */
  49. EPOLLRDHUP = (int) (1U << 13),
  50. EPOLLONESHOT = (int) (1U << 31)
  51. };
  52. #define EPOLLIN (1U << 0)
  53. #define EPOLLPRI (1U << 1)
  54. #define EPOLLOUT (1U << 2)
  55. #define EPOLLERR (1U << 3)
  56. #define EPOLLHUP (1U << 4)
  57. #define EPOLLRDNORM (1U << 6)
  58. #define EPOLLRDBAND (1U << 7)
  59. #define EPOLLWRNORM (1U << 8)
  60. #define EPOLLWRBAND (1U << 9)
  61. #define EPOLLMSG (1U << 10)
  62. #define EPOLLRDHUP (1U << 13)
  63. #define EPOLLONESHOT (1U << 31)
  64. #define EPOLL_CTL_ADD 1
  65. #define EPOLL_CTL_MOD 2
  66. #define EPOLL_CTL_DEL 3
  67. /* clang-format on */
  68. typedef void* HANDLE;
  69. typedef uintptr_t SOCKET;
  70. typedef union epoll_data {
  71. void* ptr;
  72. int fd;
  73. uint32_t u32;
  74. uint64_t u64;
  75. SOCKET sock; /* Windows specific */
  76. HANDLE hnd; /* Windows specific */
  77. } epoll_data_t;
  78. struct epoll_event {
  79. uint32_t events; /* Epoll events and flags */
  80. epoll_data_t data; /* User data variable */
  81. };
  82. #ifdef __cplusplus
  83. extern "C" {
  84. #endif
  85. WEPOLL_EXPORT HANDLE epoll_create(int size);
  86. WEPOLL_EXPORT HANDLE epoll_create1(int flags);
  87. WEPOLL_EXPORT int epoll_close(HANDLE ephnd);
  88. WEPOLL_EXPORT int epoll_ctl(HANDLE ephnd,
  89. int op,
  90. SOCKET sock,
  91. struct epoll_event* event);
  92. WEPOLL_EXPORT int epoll_wait(HANDLE ephnd,
  93. struct epoll_event* events,
  94. int maxevents,
  95. int timeout);
  96. #ifdef __cplusplus
  97. } /* extern "C" */
  98. #endif
  99. #endif /* WEPOLL_H_ */