Mirror of :pserver:anonymous@cvs.schmorp.de/schmorpforge libev http://software.schmorp.de/pkg/libev.html
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.

3095 lines
66 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
13 years ago
13 years ago
13 years ago
13 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. /*
  2. * libev event processing core, watcher management
  3. *
  4. * Copyright (c) 2007,2008 Marc Alexander Lehmann <libev@schmorp.de>
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modifica-
  8. * tion, are permitted provided that the following conditions are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
  19. * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  20. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
  21. * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
  25. * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  26. * OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * Alternatively, the contents of this file may be used under the terms of
  29. * the GNU General Public License ("GPL") version 2 or any later version,
  30. * in which case the provisions of the GPL are applicable instead of
  31. * the above. If you wish to allow the use of your version of this file
  32. * only under the terms of the GPL and not to allow others to use your
  33. * version of this file under the BSD license, indicate your decision
  34. * by deleting the provisions above and replace them with the notice
  35. * and other provisions required by the GPL. If you do not delete the
  36. * provisions above, a recipient may use your version of this file under
  37. * either the BSD or the GPL.
  38. */
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* this big block deduces configuration from config.h */
  43. #ifndef EV_STANDALONE
  44. # ifdef EV_CONFIG_H
  45. # include EV_CONFIG_H
  46. # else
  47. # include "config.h"
  48. # endif
  49. # if HAVE_CLOCK_GETTIME
  50. # ifndef EV_USE_MONOTONIC
  51. # define EV_USE_MONOTONIC 1
  52. # endif
  53. # ifndef EV_USE_REALTIME
  54. # define EV_USE_REALTIME 1
  55. # endif
  56. # else
  57. # ifndef EV_USE_MONOTONIC
  58. # define EV_USE_MONOTONIC 0
  59. # endif
  60. # ifndef EV_USE_REALTIME
  61. # define EV_USE_REALTIME 0
  62. # endif
  63. # endif
  64. # ifndef EV_USE_NANOSLEEP
  65. # if HAVE_NANOSLEEP
  66. # define EV_USE_NANOSLEEP 1
  67. # else
  68. # define EV_USE_NANOSLEEP 0
  69. # endif
  70. # endif
  71. # ifndef EV_USE_SELECT
  72. # if HAVE_SELECT && HAVE_SYS_SELECT_H
  73. # define EV_USE_SELECT 1
  74. # else
  75. # define EV_USE_SELECT 0
  76. # endif
  77. # endif
  78. # ifndef EV_USE_POLL
  79. # if HAVE_POLL && HAVE_POLL_H
  80. # define EV_USE_POLL 1
  81. # else
  82. # define EV_USE_POLL 0
  83. # endif
  84. # endif
  85. # ifndef EV_USE_EPOLL
  86. # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
  87. # define EV_USE_EPOLL 1
  88. # else
  89. # define EV_USE_EPOLL 0
  90. # endif
  91. # endif
  92. # ifndef EV_USE_KQUEUE
  93. # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H
  94. # define EV_USE_KQUEUE 1
  95. # else
  96. # define EV_USE_KQUEUE 0
  97. # endif
  98. # endif
  99. # ifndef EV_USE_PORT
  100. # if HAVE_PORT_H && HAVE_PORT_CREATE
  101. # define EV_USE_PORT 1
  102. # else
  103. # define EV_USE_PORT 0
  104. # endif
  105. # endif
  106. # ifndef EV_USE_INOTIFY
  107. # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H
  108. # define EV_USE_INOTIFY 1
  109. # else
  110. # define EV_USE_INOTIFY 0
  111. # endif
  112. # endif
  113. # ifndef EV_USE_EVENTFD
  114. # if HAVE_EVENTFD
  115. # define EV_USE_EVENTFD 1
  116. # else
  117. # define EV_USE_EVENTFD 0
  118. # endif
  119. # endif
  120. #endif
  121. #include <math.h>
  122. #include <stdlib.h>
  123. #include <fcntl.h>
  124. #include <stddef.h>
  125. #include <stdio.h>
  126. #include <assert.h>
  127. #include <errno.h>
  128. #include <sys/types.h>
  129. #include <time.h>
  130. #include <signal.h>
  131. #ifdef EV_H
  132. # include EV_H
  133. #else
  134. # include "ev.h"
  135. #endif
  136. #ifndef _WIN32
  137. # include <sys/time.h>
  138. # include <sys/wait.h>
  139. # include <unistd.h>
  140. #else
  141. # include <io.h>
  142. # define WIN32_LEAN_AND_MEAN
  143. # include <windows.h>
  144. # ifndef EV_SELECT_IS_WINSOCKET
  145. # define EV_SELECT_IS_WINSOCKET 1
  146. # endif
  147. #endif
  148. /* this block tries to deduce configuration from header-defined symbols and defaults */
  149. #ifndef EV_USE_MONOTONIC
  150. # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
  151. # define EV_USE_MONOTONIC 1
  152. # else
  153. # define EV_USE_MONOTONIC 0
  154. # endif
  155. #endif
  156. #ifndef EV_USE_REALTIME
  157. # define EV_USE_REALTIME 0
  158. #endif
  159. #ifndef EV_USE_NANOSLEEP
  160. # if _POSIX_C_SOURCE >= 199309L
  161. # define EV_USE_NANOSLEEP 1
  162. # else
  163. # define EV_USE_NANOSLEEP 0
  164. # endif
  165. #endif
  166. #ifndef EV_USE_SELECT
  167. # define EV_USE_SELECT 1
  168. #endif
  169. #ifndef EV_USE_POLL
  170. # ifdef _WIN32
  171. # define EV_USE_POLL 0
  172. # else
  173. # define EV_USE_POLL 1
  174. # endif
  175. #endif
  176. #ifndef EV_USE_EPOLL
  177. # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
  178. # define EV_USE_EPOLL 1
  179. # else
  180. # define EV_USE_EPOLL 0
  181. # endif
  182. #endif
  183. #ifndef EV_USE_KQUEUE
  184. # define EV_USE_KQUEUE 0
  185. #endif
  186. #ifndef EV_USE_PORT
  187. # define EV_USE_PORT 0
  188. #endif
  189. #ifndef EV_USE_INOTIFY
  190. # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
  191. # define EV_USE_INOTIFY 1
  192. # else
  193. # define EV_USE_INOTIFY 0
  194. # endif
  195. #endif
  196. #ifndef EV_PID_HASHSIZE
  197. # if EV_MINIMAL
  198. # define EV_PID_HASHSIZE 1
  199. # else
  200. # define EV_PID_HASHSIZE 16
  201. # endif
  202. #endif
  203. #ifndef EV_INOTIFY_HASHSIZE
  204. # if EV_MINIMAL
  205. # define EV_INOTIFY_HASHSIZE 1
  206. # else
  207. # define EV_INOTIFY_HASHSIZE 16
  208. # endif
  209. #endif
  210. #ifndef EV_US