asyncengine 0.0.1.testing1 → 0.0.2.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. data/README.markdown +3 -0
  2. data/Rakefile +38 -0
  3. data/asyncengine.gemspec +8 -4
  4. data/ext/asyncengine/ae_call_from_other_thread.c +106 -0
  5. data/ext/asyncengine/ae_call_from_other_thread.h +12 -0
  6. data/ext/asyncengine/ae_handle_common.c +193 -48
  7. data/ext/asyncengine/ae_handle_common.h +40 -13
  8. data/ext/asyncengine/ae_ip_utils.c +246 -0
  9. data/ext/asyncengine/ae_ip_utils.h +25 -0
  10. data/ext/asyncengine/ae_next_tick.c +81 -21
  11. data/ext/asyncengine/ae_next_tick.h +4 -2
  12. data/ext/asyncengine/ae_resolver.c +156 -0
  13. data/ext/asyncengine/ae_resolver.h +10 -0
  14. data/ext/asyncengine/ae_tcp.c +908 -0
  15. data/ext/asyncengine/ae_tcp.h +20 -0
  16. data/ext/asyncengine/ae_timer.c +355 -81
  17. data/ext/asyncengine/ae_timer.h +11 -4
  18. data/ext/asyncengine/ae_udp.c +579 -13
  19. data/ext/asyncengine/ae_udp.h +15 -2
  20. data/ext/asyncengine/ae_utils.c +192 -0
  21. data/ext/asyncengine/ae_utils.h +16 -0
  22. data/ext/asyncengine/asyncengine_ruby.c +469 -26
  23. data/ext/asyncengine/asyncengine_ruby.h +49 -11
  24. data/ext/asyncengine/debug.h +68 -0
  25. data/ext/asyncengine/extconf.rb +26 -2
  26. data/ext/asyncengine/ip_parser.c +5954 -0
  27. data/ext/asyncengine/ip_parser.h +16 -0
  28. data/ext/asyncengine/libuv/AUTHORS +16 -0
  29. data/ext/asyncengine/libuv/common.gypi +4 -4
  30. data/ext/asyncengine/libuv/config-mingw.mk +6 -6
  31. data/ext/asyncengine/libuv/config-unix.mk +13 -13
  32. data/ext/asyncengine/libuv/gyp_uv +5 -1
  33. data/ext/asyncengine/libuv/ibc_tests/exec_test.sh +8 -0
  34. data/ext/asyncengine/libuv/ibc_tests/uv_shutdown_write_issue.c +171 -0
  35. data/ext/asyncengine/libuv/ibc_tests/uv_tcp_close_while_connecting.c +102 -0
  36. data/ext/asyncengine/libuv/include/uv-private/ngx-queue.h +3 -1
  37. data/ext/asyncengine/libuv/include/uv-private/uv-unix.h +103 -50
  38. data/ext/asyncengine/libuv/include/uv-private/uv-win.h +76 -24
  39. data/ext/asyncengine/libuv/include/uv.h +353 -88
  40. data/ext/asyncengine/libuv/src/ares/ares__close_sockets.o +0 -0
  41. data/ext/asyncengine/libuv/src/ares/ares__get_hostent.o +0 -0
  42. data/ext/asyncengine/libuv/src/ares/ares__read_line.o +0 -0
  43. data/ext/asyncengine/libuv/src/ares/ares__timeval.o +0 -0
  44. data/ext/asyncengine/libuv/src/ares/ares_cancel.o +0 -0
  45. data/ext/asyncengine/libuv/src/ares/ares_data.o +0 -0
  46. data/ext/asyncengine/libuv/src/ares/ares_destroy.o +0 -0
  47. data/ext/asyncengine/libuv/src/ares/ares_expand_name.o +0 -0
  48. data/ext/asyncengine/libuv/src/ares/ares_expand_string.o +0 -0
  49. data/ext/asyncengine/libuv/src/ares/ares_fds.o +0 -0
  50. data/ext/asyncengine/libuv/src/ares/ares_free_hostent.o +0 -0
  51. data/ext/asyncengine/libuv/src/ares/ares_free_string.o +0 -0
  52. data/ext/asyncengine/libuv/src/ares/ares_gethostbyaddr.o +0 -0
  53. data/ext/asyncengine/libuv/src/ares/ares_gethostbyname.o +0 -0
  54. data/ext/asyncengine/libuv/src/ares/ares_getnameinfo.o +0 -0
  55. data/ext/asyncengine/libuv/src/ares/ares_getopt.o +0 -0
  56. data/ext/asyncengine/libuv/src/ares/ares_getsock.o +0 -0
  57. data/ext/asyncengine/libuv/src/ares/ares_init.o +0 -0
  58. data/ext/asyncengine/libuv/src/ares/ares_library_init.o +0 -0
  59. data/ext/asyncengine/libuv/src/ares/ares_llist.o +0 -0
  60. data/ext/asyncengine/libuv/src/ares/ares_mkquery.o +0 -0
  61. data/ext/asyncengine/libuv/src/ares/ares_nowarn.o +0 -0
  62. data/ext/asyncengine/libuv/src/ares/ares_options.o +0 -0
  63. data/ext/asyncengine/libuv/src/ares/ares_parse_a_reply.o +0 -0
  64. data/ext/asyncengine/libuv/src/ares/ares_parse_aaaa_reply.o +0 -0
  65. data/ext/asyncengine/libuv/src/ares/ares_parse_mx_reply.o +0 -0
  66. data/ext/asyncengine/libuv/src/ares/ares_parse_ns_reply.o +0 -0
  67. data/ext/asyncengine/libuv/src/ares/ares_parse_ptr_reply.o +0 -0
  68. data/ext/asyncengine/libuv/src/ares/ares_parse_srv_reply.o +0 -0
  69. data/ext/asyncengine/libuv/src/ares/ares_parse_txt_reply.o +0 -0
  70. data/ext/asyncengine/libuv/src/ares/ares_process.o +0 -0
  71. data/ext/asyncengine/libuv/src/ares/ares_query.o +0 -0
  72. data/ext/asyncengine/libuv/src/ares/ares_search.o +0 -0
  73. data/ext/asyncengine/libuv/src/ares/ares_send.o +0 -0
  74. data/ext/asyncengine/libuv/src/ares/ares_strcasecmp.o +0 -0
  75. data/ext/asyncengine/libuv/src/ares/ares_strdup.o +0 -0
  76. data/ext/asyncengine/libuv/src/ares/ares_strerror.o +0 -0
  77. data/ext/asyncengine/libuv/src/ares/ares_timeout.o +0 -0
  78. data/ext/asyncengine/libuv/src/ares/ares_version.o +0 -0
  79. data/ext/asyncengine/libuv/src/ares/ares_writev.o +0 -0
  80. data/ext/asyncengine/libuv/src/ares/bitncmp.o +0 -0
  81. data/ext/asyncengine/libuv/src/ares/inet_net_pton.o +0 -0
  82. data/ext/asyncengine/libuv/src/ares/inet_ntop.o +0 -0
  83. data/ext/asyncengine/libuv/src/cares.c +225 -0
  84. data/ext/asyncengine/libuv/src/cares.o +0 -0
  85. data/ext/asyncengine/libuv/src/fs-poll.c +237 -0
  86. data/ext/asyncengine/libuv/src/fs-poll.o +0 -0
  87. data/ext/asyncengine/libuv/src/unix/async.c +78 -17
  88. data/ext/asyncengine/libuv/src/unix/async.o +0 -0
  89. data/ext/asyncengine/libuv/src/unix/core.c +305 -213
  90. data/ext/asyncengine/libuv/src/unix/core.o +0 -0
  91. data/ext/asyncengine/libuv/src/unix/cygwin.c +1 -1
  92. data/ext/asyncengine/libuv/src/unix/darwin.c +2 -1
  93. data/ext/asyncengine/libuv/src/unix/dl.c +36 -44
  94. data/ext/asyncengine/libuv/src/unix/dl.o +0 -0
  95. data/ext/asyncengine/libuv/src/unix/eio/eio.o +0 -0
  96. data/ext/asyncengine/libuv/src/unix/error.c +6 -0
  97. data/ext/asyncengine/libuv/src/unix/error.o +0 -0
  98. data/ext/asyncengine/libuv/src/unix/ev/ev.c +8 -4
  99. data/ext/asyncengine/libuv/src/unix/ev/ev.o +0 -0
  100. data/ext/asyncengine/libuv/src/unix/freebsd.c +1 -1
  101. data/ext/asyncengine/libuv/src/unix/fs.c +25 -33
  102. data/ext/asyncengine/libuv/src/unix/fs.o +0 -0
  103. data/ext/asyncengine/libuv/src/unix/internal.h +50 -31
  104. data/ext/asyncengine/libuv/src/unix/kqueue.c +2 -7
  105. data/ext/asyncengine/libuv/src/unix/linux/core.o +0 -0
  106. data/ext/asyncengine/libuv/src/unix/linux/inotify.c +12 -14
  107. data/ext/asyncengine/libuv/src/unix/linux/inotify.o +0 -0
  108. data/ext/asyncengine/libuv/src/unix/linux/{core.c → linux-core.c} +1 -1
  109. data/ext/asyncengine/libuv/src/unix/linux/linux-core.o +0 -0
  110. data/ext/asyncengine/libuv/src/unix/linux/syscalls.c +147 -1
  111. data/ext/asyncengine/libuv/src/unix/linux/syscalls.h +39 -2
  112. data/ext/asyncengine/libuv/src/unix/linux/syscalls.o +0 -0
  113. data/ext/asyncengine/libuv/src/unix/loop-watcher.c +63 -0
  114. data/ext/asyncengine/libuv/src/unix/loop-watcher.o +0 -0
  115. data/ext/asyncengine/libuv/src/unix/loop.c +29 -6
  116. data/ext/asyncengine/libuv/src/unix/loop.o +0 -0
  117. data/ext/asyncengine/libuv/src/unix/netbsd.c +1 -1
  118. data/ext/asyncengine/libuv/src/unix/openbsd.c +1 -1
  119. data/ext/asyncengine/libuv/src/unix/pipe.c +31 -36
  120. data/ext/asyncengine/libuv/src/unix/pipe.o +0 -0
  121. data/ext/asyncengine/libuv/src/unix/poll.c +116 -0
  122. data/ext/asyncengine/libuv/src/unix/poll.o +0 -0
  123. data/ext/asyncengine/libuv/src/unix/process.c +193 -115
  124. data/ext/asyncengine/libuv/src/unix/process.o +0 -0
  125. data/ext/asyncengine/libuv/src/unix/stream.c +146 -153
  126. data/ext/asyncengine/libuv/src/unix/stream.o +0 -0
  127. data/ext/asyncengine/libuv/src/unix/sunos.c +45 -36
  128. data/ext/asyncengine/libuv/src/unix/tcp.c +6 -5
  129. data/ext/asyncengine/libuv/src/unix/tcp.o +0 -0
  130. data/ext/asyncengine/libuv/src/unix/thread.c +82 -25
  131. data/ext/asyncengine/libuv/src/unix/thread.o +0 -0
  132. data/ext/asyncengine/libuv/src/unix/timer.c +69 -58
  133. data/ext/asyncengine/libuv/src/unix/timer.o +0 -0
  134. data/ext/asyncengine/libuv/src/unix/tty.c +3 -3
  135. data/ext/asyncengine/libuv/src/unix/tty.o +0 -0
  136. data/ext/asyncengine/libuv/src/unix/udp.c +57 -66
  137. data/ext/asyncengine/libuv/src/unix/udp.o +0 -0
  138. data/ext/asyncengine/libuv/src/unix/uv-eio.c +33 -50
  139. data/ext/asyncengine/libuv/src/unix/uv-eio.o +0 -0
  140. data/ext/asyncengine/libuv/src/uv-common.c +68 -38
  141. data/ext/asyncengine/libuv/src/uv-common.h +104 -20
  142. data/ext/asyncengine/libuv/src/uv-common.o +0 -0
  143. data/ext/asyncengine/libuv/src/win/async.c +20 -17
  144. data/ext/asyncengine/libuv/src/win/core.c +44 -31
  145. data/ext/asyncengine/libuv/src/win/dl.c +40 -36
  146. data/ext/asyncengine/libuv/src/win/error.c +21 -1
  147. data/ext/asyncengine/libuv/src/win/fs-event.c +19 -21
  148. data/ext/asyncengine/libuv/src/win/fs.c +541 -189
  149. data/ext/asyncengine/libuv/src/win/getaddrinfo.c +56 -63
  150. data/ext/asyncengine/libuv/src/win/handle-inl.h +145 -0
  151. data/ext/asyncengine/libuv/src/win/handle.c +26 -101
  152. data/ext/asyncengine/libuv/src/win/internal.h +92 -107
  153. data/ext/asyncengine/libuv/src/win/loop-watcher.c +6 -14
  154. data/ext/asyncengine/libuv/src/win/pipe.c +78 -64
  155. data/ext/asyncengine/libuv/src/win/poll.c +618 -0
  156. data/ext/asyncengine/libuv/src/win/process-stdio.c +479 -0
  157. data/ext/asyncengine/libuv/src/win/process.c +147 -274
  158. data/ext/asyncengine/libuv/src/win/req-inl.h +225 -0
  159. data/ext/asyncengine/libuv/src/win/req.c +0 -149
  160. data/ext/asyncengine/libuv/src/{unix/check.c → win/stream-inl.h} +31 -42
  161. data/ext/asyncengine/libuv/src/win/stream.c +9 -43
  162. data/ext/asyncengine/libuv/src/win/tcp.c +200 -82
  163. data/ext/asyncengine/libuv/src/win/thread.c +42 -2
  164. data/ext/asyncengine/libuv/src/win/threadpool.c +3 -2
  165. data/ext/asyncengine/libuv/src/win/timer.c +13 -63
  166. data/ext/asyncengine/libuv/src/win/tty.c +26 -20
  167. data/ext/asyncengine/libuv/src/win/udp.c +26 -17
  168. data/ext/asyncengine/libuv/src/win/util.c +312 -167
  169. data/ext/asyncengine/libuv/src/win/winapi.c +16 -1
  170. data/ext/asyncengine/libuv/src/win/winapi.h +33 -9
  171. data/ext/asyncengine/libuv/src/win/winsock.c +88 -1
  172. data/ext/asyncengine/libuv/src/win/winsock.h +36 -3
  173. data/ext/asyncengine/libuv/test/benchmark-ares.c +16 -17
  174. data/ext/asyncengine/libuv/test/benchmark-fs-stat.c +164 -0
  175. data/ext/asyncengine/libuv/test/benchmark-list.h +9 -0
  176. data/ext/asyncengine/libuv/{src/unix/prepare.c → test/benchmark-loop-count.c} +42 -33
  177. data/ext/asyncengine/libuv/test/benchmark-million-timers.c +65 -0
  178. data/ext/asyncengine/libuv/test/benchmark-pound.c +1 -1
  179. data/ext/asyncengine/libuv/test/benchmark-sizes.c +2 -0
  180. data/ext/asyncengine/libuv/test/benchmark-spawn.c +7 -1
  181. data/ext/asyncengine/libuv/test/benchmark-udp-packet-storm.c +1 -1
  182. data/ext/asyncengine/libuv/test/echo-server.c +8 -0
  183. data/ext/asyncengine/libuv/test/run-tests.c +30 -0
  184. data/ext/asyncengine/libuv/test/runner-unix.c +6 -26
  185. data/ext/asyncengine/libuv/test/runner-win.c +5 -63
  186. data/ext/asyncengine/libuv/test/runner.c +10 -1
  187. data/ext/asyncengine/libuv/test/task.h +0 -8
  188. data/ext/asyncengine/libuv/test/test-async.c +43 -141
  189. data/ext/asyncengine/libuv/test/test-callback-order.c +76 -0
  190. data/ext/asyncengine/libuv/test/test-counters-init.c +2 -3
  191. data/ext/asyncengine/libuv/test/test-dlerror.c +17 -8
  192. data/ext/asyncengine/libuv/test/test-fs-event.c +31 -39
  193. data/ext/asyncengine/libuv/test/test-fs-poll.c +146 -0
  194. data/ext/asyncengine/libuv/test/test-fs.c +114 -2
  195. data/ext/asyncengine/libuv/test/test-gethostbyname.c +8 -8
  196. data/ext/asyncengine/libuv/test/test-hrtime.c +18 -15
  197. data/ext/asyncengine/libuv/test/test-ipc.c +8 -2
  198. data/ext/asyncengine/libuv/test/test-list.h +59 -9
  199. data/ext/asyncengine/libuv/test/test-loop-handles.c +2 -25
  200. data/ext/asyncengine/libuv/{src/unix/idle.c → test/test-poll-close.c} +37 -39
  201. data/ext/asyncengine/libuv/test/test-poll.c +573 -0
  202. data/ext/asyncengine/libuv/test/test-ref.c +79 -63
  203. data/ext/asyncengine/libuv/test/test-run-once.c +15 -11
  204. data/ext/asyncengine/libuv/test/test-semaphore.c +111 -0
  205. data/ext/asyncengine/libuv/test/test-spawn.c +368 -20
  206. data/ext/asyncengine/libuv/test/test-stdio-over-pipes.c +25 -35
  207. data/ext/asyncengine/libuv/test/test-tcp-close-while-connecting.c +80 -0
  208. data/ext/asyncengine/libuv/test/test-tcp-close.c +1 -1
  209. data/ext/asyncengine/libuv/test/test-tcp-connect-error-after-write.c +95 -0
  210. data/ext/asyncengine/libuv/test/test-tcp-connect-timeout.c +85 -0
  211. data/ext/asyncengine/libuv/test/test-tcp-shutdown-after-write.c +131 -0
  212. data/ext/asyncengine/libuv/test/test-tcp-write-error.c +2 -2
  213. data/ext/asyncengine/libuv/test/test-tcp-writealot.c +29 -54
  214. data/ext/asyncengine/libuv/test/test-timer-again.c +1 -1
  215. data/ext/asyncengine/libuv/test/test-timer.c +23 -1
  216. data/ext/asyncengine/libuv/test/test-udp-options.c +1 -1
  217. data/ext/asyncengine/libuv/test/{test-eio-overflow.c → test-walk-handles.c} +31 -44
  218. data/ext/asyncengine/libuv/uv.gyp +26 -9
  219. data/ext/asyncengine/rb_utilities.c +54 -0
  220. data/ext/asyncengine/rb_utilities.h +63 -0
  221. data/lib/asyncengine.rb +45 -38
  222. data/lib/asyncengine/asyncengine_ext.so +0 -0
  223. data/lib/asyncengine/debug.rb +37 -0
  224. data/lib/asyncengine/handle.rb +9 -0
  225. data/lib/asyncengine/tcp.rb +28 -0
  226. data/lib/asyncengine/timer.rb +18 -28
  227. data/lib/asyncengine/udp.rb +29 -0
  228. data/lib/asyncengine/utils.rb +32 -0
  229. data/lib/asyncengine/uv_error.rb +17 -0
  230. data/lib/asyncengine/version.rb +9 -1
  231. data/test/ae_test_helper.rb +62 -0
  232. data/test/test_basic.rb +169 -0
  233. data/test/test_call_from_other_thread.rb +55 -0
  234. data/test/test_error.rb +92 -0
  235. data/test/test_ip_utils.rb +44 -0
  236. data/test/test_next_tick.rb +37 -0
  237. data/test/test_resolver.rb +51 -0
  238. data/test/test_threads.rb +69 -0
  239. data/test/test_timer.rb +95 -0
  240. data/test/test_udp.rb +216 -0
  241. data/test/test_utils.rb +49 -0
  242. metadata +84 -57
  243. data/ext/asyncengine/libuv/mkmf.log +0 -24
  244. data/ext/asyncengine/libuv/src/unix/cares.c +0 -194
  245. data/ext/asyncengine/libuv/src/unix/cares.o +0 -0
  246. data/ext/asyncengine/libuv/src/unix/check.o +0 -0
  247. data/ext/asyncengine/libuv/src/unix/idle.o +0 -0
  248. data/ext/asyncengine/libuv/src/unix/prepare.o +0 -0
  249. data/ext/asyncengine/libuv/src/win/cares.c +0 -290
  250. data/lib/asyncengine/errors.rb +0 -5
  251. data/lib/asyncengine/next_tick.rb +0 -24
@@ -42,12 +42,10 @@ static void uv__fs_event_start(uv_fs_event_t* handle) {
42
42
  handle->fd,
43
43
  EV_LIBUV_KQUEUE_HACK);
44
44
  ev_io_start(handle->loop->ev, &handle->event_watcher);
45
- ev_unref(handle->loop->ev);
46
45
  }
47
46
 
48
47
 
49
48
  static void uv__fs_event_stop(uv_fs_event_t* handle) {
50
- ev_ref(handle->loop->ev);
51
49
  ev_io_stop(handle->loop->ev, &handle->event_watcher);
52
50
  }
53
51
 
@@ -97,11 +95,6 @@ int uv_fs_event_init(uv_loop_t* loop,
97
95
  /* We don't support any flags yet. */
98
96
  assert(!flags);
99
97
 
100
- if (cb == NULL) {
101
- uv__set_sys_error(loop, EINVAL);
102
- return -1;
103
- }
104
-
105
98
  /* TODO open asynchronously - but how do we report back errors? */
106
99
  if ((fd = open(filename, O_RDONLY)) == -1) {
107
100
  uv__set_sys_error(loop, errno);
@@ -109,6 +102,7 @@ int uv_fs_event_init(uv_loop_t* loop,
109
102
  }
110
103
 
111
104
  uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
105
+ uv__handle_start(handle); /* FIXME shouldn't start automatically */
112
106
  handle->filename = strdup(filename);
113
107
  handle->fflags = 0;
114
108
  handle->cb = cb;
@@ -121,6 +115,7 @@ int uv_fs_event_init(uv_loop_t* loop,
121
115
 
122
116
  void uv__fs_event_close(uv_fs_event_t* handle) {
123
117
  uv__fs_event_stop(handle);
118
+ uv__handle_stop(handle);
124
119
  free(handle->filename);
125
120
  close(handle->fd);
126
121
  handle->fd = -1;
@@ -51,7 +51,7 @@ static int compare_watchers(const uv_fs_event_t* a, const uv_fs_event_t* b) {
51
51
  RB_GENERATE_STATIC(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers)
52
52
 
53
53
 
54
- static void uv__inotify_read(EV_P_ ev_io* w, int revents);
54
+ static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int revents);
55
55
 
56
56
 
57
57
  static int new_inotify_fd(void) {
@@ -85,12 +85,11 @@ static int init_inotify(uv_loop_t* loop) {
85
85
  return -1;
86
86
  }
87
87
 
88
- ev_io_init(&loop->inotify_read_watcher,
89
- uv__inotify_read,
90
- loop->inotify_fd,
91
- EV_READ);
92
- ev_io_start(loop->ev, &loop->inotify_read_watcher);
93
- ev_unref(loop->ev);
88
+ uv__io_init(&loop->inotify_read_watcher,
89
+ uv__inotify_read,
90
+ loop->inotify_fd,
91
+ UV__IO_READ);
92
+ uv__io_start(loop, &loop->inotify_read_watcher);
94
93
 
95
94
  return 0;
96
95
  }
@@ -113,22 +112,18 @@ static void remove_watcher(uv_fs_event_t* handle) {
113
112
  }
114
113
 
115
114
 
116
- static void uv__inotify_read(EV_P_ ev_io* w, int revents) {
115
+ static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int events) {
117
116
  const struct uv__inotify_event* e;
118
117
  uv_fs_event_t* handle;
119
- uv_loop_t* uv_loop;
120
118
  const char* filename;
121
119
  ssize_t size;
122
- int events;
123
120
  const char *p;
124
121
  /* needs to be large enough for sizeof(inotify_event) + strlen(filename) */
125
122
  char buf[4096];
126
123
 
127
- uv_loop = container_of(w, uv_loop_t, inotify_read_watcher);
128
-
129
124
  while (1) {
130
125
  do {
131
- size = read(uv_loop->inotify_fd, buf, sizeof buf);
126
+ size = read(loop->inotify_fd, buf, sizeof buf);
132
127
  }
133
128
  while (size == -1 && errno == EINTR);
134
129
 
@@ -149,7 +144,7 @@ static void uv__inotify_read(EV_P_ ev_io* w, int revents) {
149
144
  if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
150
145
  events |= UV_RENAME;
151
146
 
152
- handle = find_watcher(uv_loop, e->wd);
147
+ handle = find_watcher(loop, e->wd);
153
148
  if (handle == NULL)
154
149
  continue; /* Handle has already been closed. */
155
150
 
@@ -185,6 +180,7 @@ int uv_fs_event_init(uv_loop_t* loop,
185
180
  | UV__IN_MODIFY
186
181
  | UV__IN_DELETE
187
182
  | UV__IN_DELETE_SELF
183
+ | UV__IN_MOVE_SELF
188
184
  | UV__IN_MOVED_FROM
189
185
  | UV__IN_MOVED_TO;
190
186
 
@@ -192,6 +188,7 @@ int uv_fs_event_init(uv_loop_t* loop,
192
188
  if (wd == -1) return uv__set_sys_error(loop, errno);
193
189
 
194
190
  uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
191
+ uv__handle_start(handle); /* FIXME shouldn't start automatically */
195
192
  handle->filename = strdup(filename);
196
193
  handle->cb = cb;
197
194
  handle->fd = wd;
@@ -208,4 +205,5 @@ void uv__fs_event_close(uv_fs_event_t* handle) {
208
205
 
209
206
  free(handle->filename);
210
207
  handle->filename = NULL;
208
+ uv__handle_stop(handle);
211
209
  }
@@ -46,7 +46,7 @@
46
46
  #endif
47
47
 
48
48
  #undef NANOSEC
49
- #define NANOSEC 1000000000
49
+ #define NANOSEC ((uint64_t) 1e9)
50
50
 
51
51
  /* This is rather annoying: CLOCK_BOOTTIME lives in <linux/time.h> but we can't
52
52
  * include that file because it conflicts with <time.h>. We'll just have to
@@ -49,6 +49,76 @@
49
49
  # endif
50
50
  #endif /* __NR_accept4 */
51
51
 
52
+ #ifndef __NR_eventfd
53
+ # if __x86_64__
54
+ # define __NR_eventfd 284
55
+ # elif __i386__
56
+ # define __NR_eventfd 323
57
+ # elif __arm__
58
+ # define __NR_eventfd (UV_SYSCALL_BASE + 351)
59
+ # endif
60
+ #endif /* __NR_eventfd */
61
+
62
+ #ifndef __NR_eventfd2
63
+ # if __x86_64__
64
+ # define __NR_eventfd2 290
65
+ # elif __i386__
66
+ # define __NR_eventfd2 328
67
+ # elif __arm__
68
+ # define __NR_eventfd2 (UV_SYSCALL_BASE + 356)
69
+ # endif
70
+ #endif /* __NR_eventfd2 */
71
+
72
+ #ifndef __NR_epoll_create
73
+ # if __x86_64__
74
+ # define __NR_epoll_create 213
75
+ # elif __i386__
76
+ # define __NR_epoll_create 254
77
+ # elif __arm__
78
+ # define __NR_epoll_create (UV_SYSCALL_BASE + 250)
79
+ # endif
80
+ #endif /* __NR_epoll_create */
81
+
82
+ #ifndef __NR_epoll_create1
83
+ # if __x86_64__
84
+ # define __NR_epoll_create1 291
85
+ # elif __i386__
86
+ # define __NR_epoll_create1 329
87
+ # elif __arm__
88
+ # define __NR_epoll_create1 (UV_SYSCALL_BASE + 357)
89
+ # endif
90
+ #endif /* __NR_epoll_create1 */
91
+
92
+ #ifndef __NR_epoll_ctl
93
+ # if __x86_64__
94
+ # define __NR_epoll_ctl 233 /* used to be 214 */
95
+ # elif __i386__
96
+ # define __NR_epoll_ctl 255
97
+ # elif __arm__
98
+ # define __NR_epoll_ctl (UV_SYSCALL_BASE + 251)
99
+ # endif
100
+ #endif /* __NR_epoll_ctl */
101
+
102
+ #ifndef __NR_epoll_wait
103
+ # if __x86_64__
104
+ # define __NR_epoll_wait 232 /* used to be 215 */
105
+ # elif __i386__
106
+ # define __NR_epoll_wait 256
107
+ # elif __arm__
108
+ # define __NR_epoll_wait (UV_SYSCALL_BASE + 252)
109
+ # endif
110
+ #endif /* __NR_epoll_wait */
111
+
112
+ #ifndef __NR_epoll_pwait
113
+ # if __x86_64__
114
+ # define __NR_epoll_pwait 281
115
+ # elif __i386__
116
+ # define __NR_epoll_pwait 319
117
+ # elif __arm__
118
+ # define __NR_epoll_pwait (UV_SYSCALL_BASE + 346)
119
+ # endif
120
+ #endif /* __NR_epoll_pwait */
121
+
52
122
  #ifndef __NR_inotify_init
53
123
  # if __x86_64__
54
124
  # define __NR_inotify_init 253
@@ -115,7 +185,7 @@
115
185
  # elif __i386__
116
186
  # define __NR_sendmmsg 345
117
187
  # elif __arm__
118
- # define __NR_recvmmsg (UV_SYSCALL_BASE + 374)
188
+ # define __NR_sendmmsg (UV_SYSCALL_BASE + 374)
119
189
  # endif
120
190
  #endif /* __NR_sendmmsg */
121
191
 
@@ -147,6 +217,82 @@ int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) {
147
217
  }
148
218
 
149
219
 
220
+ int uv__eventfd(unsigned int count) {
221
+ #if __NR_eventfd
222
+ return syscall(__NR_eventfd, count);
223
+ #else
224
+ return errno = ENOSYS, -1;
225
+ #endif
226
+ }
227
+
228
+
229
+ int uv__eventfd2(unsigned int count, int flags) {
230
+ #if __NR_eventfd2
231
+ return syscall(__NR_eventfd2, count, flags);
232
+ #else
233
+ return errno = ENOSYS, -1;
234
+ #endif
235
+ }
236
+
237
+
238
+ int uv__epoll_create(void) {
239
+ #if __NR_epoll_create
240
+ return syscall(__NR_epoll_create);
241
+ #else
242
+ return errno = ENOSYS, -1;
243
+ #endif
244
+ }
245
+
246
+
247
+ int uv__epoll_create1(int flags) {
248
+ #if __NR_epoll_create1
249
+ return syscall(__NR_epoll_create1, flags);
250
+ #else
251
+ return errno = ENOSYS, -1;
252
+ #endif
253
+ }
254
+
255
+
256
+ int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event* events) {
257
+ #if __NR_epoll_ctl
258
+ return syscall(__NR_epoll_ctl, epfd, op, fd, events);
259
+ #else
260
+ return errno = ENOSYS, -1;
261
+ #endif
262
+ }
263
+
264
+
265
+ int uv__epoll_wait(int epfd,
266
+ struct uv__epoll_event* events,
267
+ int nevents,
268
+ int timeout) {
269
+ #if __NR_epoll_wait
270
+ return syscall(__NR_epoll_wait, epfd, events, nevents, timeout);
271
+ #else
272
+ return errno = ENOSYS, -1;
273
+ #endif
274
+ }
275
+
276
+
277
+ int uv__epoll_pwait(int epfd,
278
+ struct uv__epoll_event* events,
279
+ int nevents,
280
+ int timeout,
281
+ const sigset_t* sigmask) {
282
+ #if __NR_epoll_pwait
283
+ return syscall(__NR_epoll_pwait,
284
+ epfd,
285
+ events,
286
+ nevents,
287
+ timeout,
288
+ sigmask,
289
+ sizeof(*sigmask));
290
+ #else
291
+ return errno = ENOSYS, -1;
292
+ #endif
293
+ }
294
+
295
+
150
296
  int uv__inotify_init(void) {
151
297
  #if __NR_inotify_init
152
298
  return syscall(__NR_inotify_init);
@@ -25,6 +25,7 @@
25
25
  #undef _GNU_SOURCE
26
26
  #define _GNU_SOURCE
27
27
 
28
+ #include <signal.h>
28
29
  #include <sys/types.h>
29
30
  #include <sys/socket.h>
30
31
  #include <linux/types.h>
@@ -32,12 +33,29 @@
32
33
  #define UV__O_NONBLOCK 0x800
33
34
  #define UV__O_CLOEXEC 0x80000
34
35
 
35
- #define UV__SOCK_CLOEXEC UV__O_CLOEXEC
36
- #define UV__SOCK_NONBLOCK UV__O_NONBLOCK
36
+ #define UV__EFD_CLOEXEC UV__O_CLOEXEC
37
+ #define UV__EFD_NONBLOCK UV__O_NONBLOCK
37
38
 
38
39
  #define UV__IN_CLOEXEC UV__O_CLOEXEC
39
40
  #define UV__IN_NONBLOCK UV__O_NONBLOCK
40
41
 
42
+ #define UV__SOCK_CLOEXEC UV__O_CLOEXEC
43
+ #define UV__SOCK_NONBLOCK UV__O_NONBLOCK
44
+
45
+ /* epoll flags */
46
+ #define UV__EPOLL_CLOEXEC UV__O_CLOEXEC
47
+ #define UV__EPOLL_CTL_ADD 1
48
+ #define UV__EPOLL_CTL_DEL 2
49
+ #define UV__EPOLL_CTL_MOD 3
50
+
51
+ #define UV__EPOLLIN 1
52
+ #define UV__EPOLLOUT 4
53
+ #define UV__EPOLLERR 8
54
+ #define UV__EPOLLHUP 16
55
+ #define UV__EPOLLONESHOT 0x40000000
56
+ #define UV__EPOLLET 0x80000000
57
+
58
+ /* inotify flags */
41
59
  #define UV__IN_ACCESS 0x001
42
60
  #define UV__IN_MODIFY 0x002
43
61
  #define UV__IN_ATTRIB 0x004
@@ -51,6 +69,11 @@
51
69
  #define UV__IN_DELETE_SELF 0x400
52
70
  #define UV__IN_MOVE_SELF 0x800
53
71
 
72
+ struct uv__epoll_event {
73
+ __u32 events;
74
+ __u64 data;
75
+ } __attribute__((packed));
76
+
54
77
  struct uv__inotify_event {
55
78
  __s32 wd;
56
79
  __u32 mask;
@@ -65,6 +88,20 @@ struct uv__mmsghdr {
65
88
  };
66
89
 
67
90
  int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags);
91
+ int uv__eventfd(unsigned int count);
92
+ int uv__epoll_create(void);
93
+ int uv__epoll_create1(int flags);
94
+ int uv__epoll_ctl(int epfd, int op, int fd, struct uv__epoll_event *ev);
95
+ int uv__epoll_wait(int epfd,
96
+ struct uv__epoll_event* events,
97
+ int nevents,
98
+ int timeout);
99
+ int uv__epoll_pwait(int epfd,
100
+ struct uv__epoll_event* events,
101
+ int nevents,
102
+ int timeout,
103
+ const sigset_t* sigmask);
104
+ int uv__eventfd2(unsigned int count, int flags);
68
105
  int uv__inotify_init(void);
69
106
  int uv__inotify_init1(int flags);
70
107
  int uv__inotify_add_watch(int fd, const char* path, __u32 mask);
@@ -0,0 +1,63 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ #include "uv.h"
23
+ #include "internal.h"
24
+
25
+ #define UV_LOOP_WATCHER_DEFINE(name, type) \
26
+ int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
27
+ uv__handle_init(loop, (uv_handle_t*)handle, UV_##type); \
28
+ loop->counters.name##_init++; \
29
+ handle->name##_cb = NULL; \
30
+ return 0; \
31
+ } \
32
+ \
33
+ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
34
+ if (uv__is_active(handle)) return 0; \
35
+ ngx_queue_insert_head(&handle->loop->name##_handles, &handle->queue); \
36
+ handle->name##_cb = cb; \
37
+ uv__handle_start(handle); \
38
+ return 0; \
39
+ } \
40
+ \
41
+ int uv_##name##_stop(uv_##name##_t* handle) { \
42
+ if (!uv__is_active(handle)) return 0; \
43
+ ngx_queue_remove(&handle->queue); \
44
+ uv__handle_stop(handle); \
45
+ return 0; \
46
+ } \
47
+ \
48
+ void uv__run_##name(uv_loop_t* loop) { \
49
+ uv_##name##_t* h; \
50
+ ngx_queue_t* q; \
51
+ ngx_queue_foreach(q, &loop->name##_handles) { \
52
+ h = ngx_queue_data(q, uv_##name##_t, queue); \
53
+ if (h->name##_cb) h->name##_cb(h, 0); \
54
+ } \
55
+ } \
56
+ \
57
+ void uv__##name##_close(uv_##name##_t* handle) { \
58
+ uv_##name##_stop(handle); \
59
+ }
60
+
61
+ UV_LOOP_WATCHER_DEFINE(prepare, PREPARE)
62
+ UV_LOOP_WATCHER_DEFINE(check, CHECK)
63
+ UV_LOOP_WATCHER_DEFINE(idle, IDLE)
@@ -33,14 +33,32 @@ int uv__loop_init(uv_loop_t* loop, int default_loop) {
33
33
  #else
34
34
  int flags = EVFLAG_AUTO;
35
35
  #endif
36
- RB_INIT(&loop->uv_ares_handles_);
37
- loop->endgame_handles = NULL;
36
+
37
+ memset(loop, 0, sizeof(*loop));
38
+
39
+ RB_INIT(&loop->ares_handles);
40
+ RB_INIT(&loop->timer_handles);
41
+ ngx_queue_init(&loop->active_reqs);
42
+ ngx_queue_init(&loop->idle_handles);
43
+ ngx_queue_init(&loop->async_handles);
44
+ ngx_queue_init(&loop->check_handles);
45
+ ngx_queue_init(&loop->prepare_handles);
46
+ ngx_queue_init(&loop->handle_queue);
47
+ loop->closing_handles = NULL;
48
+ loop->channel = NULL;
49
+ loop->time = uv_hrtime() / 1000000;
50
+ loop->async_pipefd[0] = -1;
51
+ loop->async_pipefd[1] = -1;
38
52
  loop->ev = (default_loop ? ev_default_loop : ev_loop_new)(flags);
39
53
  ev_set_userdata(loop->ev, loop);
40
54
  eio_channel_init(&loop->uv_eio_channel, loop);
55
+
41
56
  #if __linux__
42
57
  RB_INIT(&loop->inotify_watchers);
43
58
  loop->inotify_fd = -1;
59
+ #endif
60
+ #if HAVE_PORTS_FS
61
+ loop->fs_fd = -1;
44
62
  #endif
45
63
  return 0;
46
64
  }
@@ -50,9 +68,14 @@ void uv__loop_delete(uv_loop_t* loop) {
50
68
  uv_ares_destroy(loop, loop->channel);
51
69
  ev_loop_destroy(loop->ev);
52
70
  #if __linux__
53
- if (loop->inotify_fd == -1) return;
54
- ev_io_stop(loop->ev, &loop->inotify_read_watcher);
55
- close(loop->inotify_fd);
56
- loop->inotify_fd = -1;
71
+ if (loop->inotify_fd != -1) {
72
+ uv__io_stop(loop, &loop->inotify_read_watcher);
73
+ close(loop->inotify_fd);
74
+ loop->inotify_fd = -1;
75
+ }
76
+ #endif
77
+ #if HAVE_PORTS_FS
78
+ if (loop->fs_fd != -1)
79
+ close(loop->fs_fd);
57
80
  #endif
58
81
  }