You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.2KB

  1. /*
  2. * wepoll - epoll for Windows
  3. * https://github.com/piscisaureus/wepoll
  4. *
  5. * Copyright 2012-2020, 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. enum EPOLL_EVENTS {
  38. EPOLLIN = (int)(1U << 0),
  39. EPOLLPRI = (int)(1U << 1),
  40. EPOLLOUT = (int)(1U << 2),
  41. EPOLLERR = (int)(1U << 3),
  42. EPOLLHUP = (int)(1U << 4),
  43. EPOLLRDNORM = (int)(1U << 6),
  44. EPOLLRDBAND = (int)(1U << 7),
  45. EPOLLWRNORM = (int)(1U << 8),
  46. EPOLLWRBAND = (int)(1U << 9),
  47. EPOLLMSG = (int)(1U << 10), /* Never reported. */
  48. EPOLLRDHUP = (int)(1U << 13),
  49. EPOLLONESHOT = (int)(1U << 31)
  50. };
  51. #define EPOLLIN (1U << 0)
  52. #define EPOLLPRI (1U << 1)
  53. #define EPOLLOUT (1U << 2)
  54. #define EPOLLERR (1U << 3)
  55. #define EPOLLHUP (1U << 4)
  56. #define EPOLLRDNORM (1U << 6)
  57. #define EPOLLRDBAND (1U << 7)
  58. #define EPOLLWRNORM (1U << 8)
  59. #define EPOLLWRBAND (1U << 9)
  60. #define EPOLLMSG (1U << 10)
  61. #define EPOLLRDHUP (1U << 13)
  62. #define EPOLLONESHOT (1U << 31)
  63. #define EPOLL_CTL_ADD 1
  64. #define EPOLL_CTL_MOD 2
  65. #define EPOLL_CTL_DEL 3
  66. typedef void *HANDLE;
  67. typedef uintptr_t SOCKET;
  68. typedef union epoll_data {
  69. void *ptr;
  70. int fd;
  71. uint32_t u32;
  72. uint64_t u64;
  73. SOCKET sock; /* Windows specific */
  74. HANDLE hnd; /* Windows specific */
  75. } epoll_data_t;
  76. struct epoll_event {
  77. uint32_t events; /* Epoll events and flags */
  78. epoll_data_t data; /* User data variable */
  79. };
  80. #ifdef __cplusplus
  81. extern "C" {
  82. #endif
  83. WEPOLL_EXPORT HANDLE epoll_create(int size);
  84. WEPOLL_EXPORT HANDLE epoll_create1(int flags);
  85. WEPOLL_EXPORT int epoll_close(HANDLE ephnd);
  86. WEPOLL_EXPORT int epoll_ctl(HANDLE ephnd, int op, SOCKET sock, struct epoll_event *event);
  87. WEPOLL_EXPORT int epoll_wait(HANDLE ephnd, struct epoll_event *events, int maxevents, int timeout);
  88. #ifdef __cplusplus
  89. } /* extern "C" */
  90. #endif
  91. #endif /* WEPOLL_H_ */