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
@@ -38,11 +38,11 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
38
38
 
39
39
  if (readable) {
40
40
  uv__nonblock(fd, 1);
41
- uv__stream_open((uv_stream_t*)tty, fd, UV_READABLE);
41
+ uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_READABLE);
42
42
  } else {
43
43
  /* Note: writable tty we set to blocking mode. */
44
- uv__stream_open((uv_stream_t*)tty, fd, UV_WRITABLE);
45
- tty->blocking = 1;
44
+ uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
45
+ tty->flags |= UV_STREAM_BLOCKING;
46
46
  }
47
47
 
48
48
  loop->counters.tty_init++;
@@ -31,63 +31,39 @@
31
31
 
32
32
  static void uv__udp_run_completed(uv_udp_t* handle);
33
33
  static void uv__udp_run_pending(uv_udp_t* handle);
34
- static void uv__udp_recvmsg(EV_P_ ev_io* w, int revents);
35
- static void uv__udp_sendmsg(EV_P_ ev_io* w, int revents);
34
+ static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents);
35
+ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents);
36
36
  static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, int domain);
37
37
  static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[],
38
38
  int bufcnt, struct sockaddr* addr, socklen_t addrlen, uv_udp_send_cb send_cb);
39
39
 
40
40
 
41
41
  static void uv__udp_start_watcher(uv_udp_t* handle,
42
- ev_io* w,
43
- void (*cb)(EV_P_ ev_io*, int),
44
- int flags) {
45
- if (ev_is_active(w)) return;
46
- ev_set_cb(w, cb);
47
- ev_io_set(w, handle->fd, flags);
48
- ev_io_start(handle->loop->ev, w);
49
- ev_unref(handle->loop->ev);
42
+ uv__io_t* w,
43
+ uv__io_cb cb,
44
+ int events) {
45
+ if (uv__io_active(w)) return;
46
+ uv__io_init(w, cb, handle->fd, events);
47
+ uv__io_start(handle->loop, w);
48
+ uv__handle_start(handle);
50
49
  }
51
50
 
52
51
 
53
- static void uv__udp_stop_watcher(uv_udp_t* handle, ev_io* w) {
54
- if (!ev_is_active(w)) return;
55
- ev_ref(handle->loop->ev);
56
- ev_io_stop(handle->loop->ev, w);
57
- ev_io_set(w, -1, 0);
58
- ev_set_cb(w, NULL);
59
- }
60
-
61
-
62
- static void uv__udp_start_read_watcher(uv_udp_t* handle) {
63
- uv__udp_start_watcher(handle,
64
- &handle->read_watcher,
65
- uv__udp_recvmsg,
66
- EV_READ);
67
- }
68
-
69
-
70
- static void uv__udp_start_write_watcher(uv_udp_t* handle) {
71
- uv__udp_start_watcher(handle,
72
- &handle->write_watcher,
73
- uv__udp_sendmsg,
74
- EV_WRITE);
75
- }
76
-
77
-
78
- static void uv__udp_stop_read_watcher(uv_udp_t* handle) {
79
- uv__udp_stop_watcher(handle, &handle->read_watcher);
80
- }
81
-
52
+ static void uv__udp_stop_watcher(uv_udp_t* handle, uv__io_t* w) {
53
+ if (!uv__io_active(w)) return;
54
+ uv__io_stop(handle->loop, w);
82
55
 
83
- static void uv__udp_stop_write_watcher(uv_udp_t* handle) {
84
- uv__udp_stop_watcher(handle, &handle->write_watcher);
56
+ if (!uv__io_active(&handle->read_watcher) &&
57
+ !uv__io_active(&handle->write_watcher))
58
+ {
59
+ uv__handle_stop(handle);
60
+ }
85
61
  }
86
62
 
87
63
 
88
64
  void uv__udp_close(uv_udp_t* handle) {
89
- uv__udp_stop_write_watcher(handle);
90
- uv__udp_stop_read_watcher(handle);
65
+ uv__udp_stop_watcher(handle, &handle->write_watcher);
66
+ uv__udp_stop_watcher(handle, &handle->read_watcher);
91
67
  close(handle->fd);
92
68
  handle->fd = -1;
93
69
  }
@@ -97,8 +73,8 @@ void uv__udp_finish_close(uv_udp_t* handle) {
97
73
  uv_udp_send_t* req;
98
74
  ngx_queue_t* q;
99
75
 
100
- assert(!ev_is_active(&handle->write_watcher));
101
- assert(!ev_is_active(&handle->read_watcher));
76
+ assert(!uv__io_active(&handle->write_watcher));
77
+ assert(!uv__io_active(&handle->read_watcher));
102
78
  assert(handle->fd == -1);
103
79
 
104
80
  uv__udp_run_completed(handle);
@@ -108,6 +84,8 @@ void uv__udp_finish_close(uv_udp_t* handle) {
108
84
  ngx_queue_remove(q);
109
85
 
110
86
  req = ngx_queue_data(q, uv_udp_send_t, queue);
87
+ uv__req_unregister(handle->loop, req);
88
+
111
89
  if (req->send_cb) {
112
90
  /* FIXME proper error code like UV_EABORTED */
113
91
  uv__set_artificial_error(handle->loop, UV_EINTR);
@@ -138,7 +116,8 @@ static void uv__udp_run_pending(uv_udp_t* handle) {
138
116
 
139
117
  memset(&h, 0, sizeof h);
140
118
  h.msg_name = &req->addr;
141
- h.msg_namelen = req->addrlen;
119
+ h.msg_namelen = (req->addr.sin6_family == AF_INET6 ?
120
+ sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in));
142
121
  h.msg_iov = (struct iovec*)req->bufs;
143
122
  h.msg_iovlen = req->bufcnt;
144
123
 
@@ -185,12 +164,10 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
185
164
 
186
165
  while (!ngx_queue_empty(&handle->write_completed_queue)) {
187
166
  q = ngx_queue_head(&handle->write_completed_queue);
188
- assert(q != NULL);
189
-
190
167
  ngx_queue_remove(q);
191
168
 
192
169
  req = ngx_queue_data(q, uv_udp_send_t, queue);
193
- assert(req != NULL);
170
+ uv__req_unregister(handle->loop, req);
194
171
 
195
172
  if (req->bufs != req->bufsml)
196
173
  free(req->bufs);
@@ -212,30 +189,36 @@ static void uv__udp_run_completed(uv_udp_t* handle) {
212
189
  }
213
190
 
214
191
 
215
- static void uv__udp_recvmsg(EV_P_ ev_io* w, int revents) {
192
+ static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
216
193
  struct sockaddr_storage peer;
217
194
  struct msghdr h;
218
195
  uv_udp_t* handle;
219
196
  ssize_t nread;
220
197
  uv_buf_t buf;
221
198
  int flags;
199
+ int count;
222
200
 
223
201
  handle = container_of(w, uv_udp_t, read_watcher);
224
202
  assert(handle->type == UV_UDP);
225
- assert(revents & EV_READ);
203
+ assert(revents & UV__IO_READ);
226
204
 
227
205
  assert(handle->recv_cb != NULL);
228
206
  assert(handle->alloc_cb != NULL);
229
207
 
208
+ /* Prevent loop starvation when the data comes in as fast as (or faster than)
209
+ * we can read it. XXX Need to rearm fd if we switch to edge-triggered I/O.
210
+ */
211
+ count = 32;
212
+
213
+ memset(&h, 0, sizeof(h));
214
+ h.msg_name = &peer;
215
+
230
216
  do {
231
- /* FIXME: hoist alloc_cb out the loop but for now follow uv__read() */
232
217
  buf = handle->alloc_cb((uv_handle_t*)handle, 64 * 1024);
233
218
  assert(buf.len > 0);
234
219
  assert(buf.base != NULL);
235
220
 
236
- memset(&h, 0, sizeof h);
237
- h.msg_name = &peer;
238
- h.msg_namelen = sizeof peer;
221
+ h.msg_namelen = sizeof(peer);
239
222
  h.msg_iov = (struct iovec*)&buf;
240
223
  h.msg_iovlen = 1;
241
224
 
@@ -269,17 +252,18 @@ static void uv__udp_recvmsg(EV_P_ ev_io* w, int revents) {
269
252
  }
270
253
  /* recv_cb callback may decide to pause or close the handle */
271
254
  while (nread != -1
255
+ && count-- > 0
272
256
  && handle->fd != -1
273
257
  && handle->recv_cb != NULL);
274
258
  }
275
259
 
276
260
 
277
- static void uv__udp_sendmsg(EV_P_ ev_io* w, int revents) {
261
+ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) {
278
262
  uv_udp_t* handle;
279
263
 
280
264
  handle = container_of(w, uv_udp_t, write_watcher);
281
265
  assert(handle->type == UV_UDP);
282
- assert(revents & EV_WRITE);
266
+ assert(revents & UV__IO_WRITE);
283
267
 
284
268
  assert(!ngx_queue_empty(&handle->write_queue)
285
269
  || !ngx_queue_empty(&handle->write_completed_queue));
@@ -292,11 +276,11 @@ static void uv__udp_sendmsg(EV_P_ ev_io* w, int revents) {
292
276
 
293
277
  if (!ngx_queue_empty(&handle->write_completed_queue)) {
294
278
  /* Schedule completion callbacks. */
295
- ev_feed_event(handle->loop->ev, &handle->write_watcher, EV_WRITE);
279
+ uv__io_feed(handle->loop, &handle->write_watcher, UV__IO_WRITE);
296
280
  }
297
281
  else if (ngx_queue_empty(&handle->write_queue)) {
298
282
  /* Pending queue and completion queue empty, stop watcher. */
299
- uv__udp_stop_write_watcher(handle);
283
+ uv__udp_stop_watcher(handle, &handle->write_watcher);
300
284
  }
301
285
  }
302
286
 
@@ -437,14 +421,13 @@ static int uv__udp_send(uv_udp_send_t* req,
437
421
  if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
438
422
  return -1;
439
423
 
440
- uv__req_init(handle->loop, (uv_req_t*)req);
424
+ uv__req_init(handle->loop, req, UV_UDP_SEND);
441
425
 
426
+ assert(addrlen <= sizeof(req->addr));
442
427
  memcpy(&req->addr, addr, addrlen);
443
- req->addrlen = addrlen;
444
428
  req->send_cb = send_cb;
445
429
  req->handle = handle;
446
430
  req->bufcnt = bufcnt;
447
- req->type = UV_UDP_SEND;
448
431
 
449
432
  if (bufcnt <= UV_REQ_BUFSML_SIZE) {
450
433
  req->bufs = req->bufsml;
@@ -456,7 +439,11 @@ static int uv__udp_send(uv_udp_send_t* req,
456
439
  memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0]));
457
440
 
458
441
  ngx_queue_insert_tail(&handle->write_queue, &req->queue);
459
- uv__udp_start_write_watcher(handle);
442
+
443
+ uv__udp_start_watcher(handle,
444
+ &handle->write_watcher,
445
+ uv__udp_sendmsg,
446
+ UV__IO_WRITE);
460
447
 
461
448
  return 0;
462
449
  }
@@ -646,7 +633,7 @@ int uv_udp_recv_start(uv_udp_t* handle,
646
633
  return -1;
647
634
  }
648
635
 
649
- if (ev_is_active(&handle->read_watcher)) {
636
+ if (uv__io_active(&handle->read_watcher)) {
650
637
  uv__set_artificial_error(handle->loop, UV_EALREADY);
651
638
  return -1;
652
639
  }
@@ -656,14 +643,18 @@ int uv_udp_recv_start(uv_udp_t* handle,
656
643
 
657
644
  handle->alloc_cb = alloc_cb;
658
645
  handle->recv_cb = recv_cb;
659
- uv__udp_start_read_watcher(handle);
646
+
647
+ uv__udp_start_watcher(handle,
648
+ &handle->read_watcher,
649
+ uv__udp_recvmsg,
650
+ UV__IO_READ);
660
651
 
661
652
  return 0;
662
653
  }
663
654
 
664
655
 
665
656
  int uv_udp_recv_stop(uv_udp_t* handle) {
666
- uv__udp_stop_read_watcher(handle);
657
+ uv__udp_stop_watcher(handle, &handle->read_watcher);
667
658
  handle->alloc_cb = NULL;
668
659
  handle->recv_cb = NULL;
669
660
  return 0;
@@ -22,52 +22,37 @@
22
22
 
23
23
  #include "uv.h"
24
24
  #include "eio.h"
25
+ #include "internal.h"
25
26
 
26
27
  #include <assert.h>
27
28
  #include <stdio.h>
28
29
 
29
30
 
30
- static void uv_eio_do_poll(uv_idle_t* watcher, int status) {
31
- assert(watcher == &(watcher->loop->uv_eio_poller));
31
+ static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT;
32
32
 
33
- /* printf("uv_eio_poller\n"); */
34
33
 
35
- if (eio_poll(&watcher->loop->uv_eio_channel) != -1 && uv_is_active((uv_handle_t*) watcher)) {
36
- /* printf("uv_eio_poller stop\n"); */
34
+ static void uv_eio_do_poll(uv_idle_t* watcher, int status) {
35
+ uv_loop_t* loop = watcher->loop;
36
+ assert(watcher == &loop->uv_eio_poller);
37
+ if (eio_poll(&loop->uv_eio_channel) != -1)
37
38
  uv_idle_stop(watcher);
38
- uv_unref(watcher->loop);
39
- }
40
39
  }
41
40
 
42
41
 
43
42
  /* Called from the main thread. */
44
43
  static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) {
45
44
  uv_loop_t* loop = watcher->loop;
46
-
47
45
  assert(watcher == &loop->uv_eio_want_poll_notifier);
48
-
49
- /* printf("want poll notifier\n"); */
50
-
51
- if (eio_poll(&watcher->loop->uv_eio_channel) == -1 && !uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) {
52
- /* printf("uv_eio_poller start\n"); */
46
+ if (eio_poll(&loop->uv_eio_channel) == -1)
53
47
  uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
54
- uv_ref(loop);
55
- }
56
48
  }
57
49
 
58
50
 
59
51
  static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) {
60
52
  uv_loop_t* loop = watcher->loop;
61
-
62
53
  assert(watcher == &loop->uv_eio_done_poll_notifier);
63
-
64
- /* printf("done poll notifier\n"); */
65
-
66
- if (eio_poll(&watcher->loop->uv_eio_channel) != -1 && uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) {
67
- /* printf("uv_eio_poller stop\n"); */
54
+ if (eio_poll(&loop->uv_eio_channel) != -1)
68
55
  uv_idle_stop(&loop->uv_eio_poller);
69
- uv_unref(loop);
70
- }
71
56
  }
72
57
 
73
58
 
@@ -77,13 +62,8 @@ static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) {
77
62
  */
78
63
  static void uv_eio_want_poll(eio_channel *channel) {
79
64
  /* Signal the main thread that eio_poll need to be processed. */
80
-
81
- /*
82
- * TODO need to select the correct uv_loop_t and async_send to
83
- * uv_eio_want_poll_notifier.
84
- */
85
-
86
- uv_async_send(&((uv_loop_t *)channel->data)->uv_eio_want_poll_notifier);
65
+ uv_loop_t* loop = channel->data;
66
+ uv_async_send(&loop->uv_eio_want_poll_notifier);
87
67
  }
88
68
 
89
69
 
@@ -92,7 +72,8 @@ static void uv_eio_done_poll(eio_channel *channel) {
92
72
  * Signal the main thread that we should stop calling eio_poll().
93
73
  * from the idle watcher.
94
74
  */
95
- uv_async_send(&((uv_loop_t *)channel->data)->uv_eio_done_poll_notifier);
75
+ uv_loop_t* loop = channel->data;
76
+ uv_async_send(&loop->uv_eio_done_poll_notifier);
96
77
  }
97
78
 
98
79
 
@@ -100,25 +81,27 @@ static void uv__eio_init(void) {
100
81
  eio_init(uv_eio_want_poll, uv_eio_done_poll);
101
82
  }
102
83
 
103
- static uv_once_t uv__eio_init_once_guard = UV_ONCE_INIT;
104
-
105
84
 
106
85
  void uv_eio_init(uv_loop_t* loop) {
107
- if (loop->counters.eio_init == 0) {
108
- loop->counters.eio_init++;
109
-
110
- uv_idle_init(loop, &loop->uv_eio_poller);
111
- uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
112
-
113
- loop->uv_eio_want_poll_notifier.data = loop;
114
- uv_async_init(loop, &loop->uv_eio_want_poll_notifier,
115
- uv_eio_want_poll_notifier_cb);
116
- uv_unref(loop);
117
-
118
- uv_async_init(loop, &loop->uv_eio_done_poll_notifier,
119
- uv_eio_done_poll_notifier_cb);
120
- uv_unref(loop);
121
-
122
- uv_once(&uv__eio_init_once_guard, uv__eio_init);
123
- }
86
+ if (loop->counters.eio_init) return;
87
+ loop->counters.eio_init = 1;
88
+
89
+ uv_idle_init(loop, &loop->uv_eio_poller);
90
+ uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll);
91
+ loop->uv_eio_poller.flags |= UV__HANDLE_INTERNAL;
92
+
93
+ loop->uv_eio_want_poll_notifier.data = loop;
94
+ uv_async_init(loop,
95
+ &loop->uv_eio_want_poll_notifier,
96
+ uv_eio_want_poll_notifier_cb);
97
+ loop->uv_eio_want_poll_notifier.flags |= UV__HANDLE_INTERNAL;
98
+ uv__handle_unref(&loop->uv_eio_want_poll_notifier);
99
+
100
+ uv_async_init(loop,
101
+ &loop->uv_eio_done_poll_notifier,
102
+ uv_eio_done_poll_notifier_cb);
103
+ loop->uv_eio_done_poll_notifier.flags |= UV__HANDLE_INTERNAL;
104
+ uv__handle_unref(&loop->uv_eio_done_poll_notifier);
105
+
106
+ uv_once(&uv__eio_init_once_guard, uv__eio_init);
124
107
  }
@@ -22,6 +22,7 @@
22
22
  #include "uv.h"
23
23
  #include "uv-common.h"
24
24
 
25
+ #include <stdio.h>
25
26
  #include <assert.h>
26
27
  #include <stddef.h> /* NULL */
27
28
  #include <stdlib.h> /* malloc */
@@ -87,7 +88,7 @@ size_t uv_strlcat(char* dst, const char* src, size_t size) {
87
88
  }
88
89
 
89
90
 
90
- uv_buf_t uv_buf_init(char* base, size_t len) {
91
+ uv_buf_t uv_buf_init(char* base, unsigned int len) {
91
92
  uv_buf_t buf;
92
93
  buf.base = base;
93
94
  buf.len = len;
@@ -199,43 +200,6 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
199
200
  }
200
201
 
201
202
 
202
- static int cmp_ares_tasks(const uv_ares_task_t* a, const uv_ares_task_t* b) {
203
- if (a->sock < b->sock) return -1;
204
- if (a->sock > b->sock) return 1;
205
- return 0;
206
- }
207
-
208
-
209
- RB_GENERATE_STATIC(uv__ares_tasks, uv_ares_task_s, node, cmp_ares_tasks)
210
-
211
-
212
- /* add ares handle to list */
213
- void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle) {
214
- assert(loop == handle->loop);
215
- RB_INSERT(uv__ares_tasks, &loop->uv_ares_handles_, handle);
216
- }
217
-
218
-
219
- /* find matching ares handle in list */
220
- uv_ares_task_t* uv_find_ares_handle(uv_loop_t* loop, ares_socket_t sock) {
221
- uv_ares_task_t handle;
222
- handle.sock = sock;
223
- return RB_FIND(uv__ares_tasks, &loop->uv_ares_handles_, &handle);
224
- }
225
-
226
-
227
- /* remove ares handle in list */
228
- void uv_remove_ares_handle(uv_ares_task_t* handle) {
229
- RB_REMOVE(uv__ares_tasks, &handle->loop->uv_ares_handles_, handle);
230
- }
231
-
232
-
233
- /* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */
234
- int uv_ares_handles_empty(uv_loop_t* loop) {
235
- return RB_EMPTY(&loop->uv_ares_handles_);
236
- }
237
-
238
-
239
203
  int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) {
240
204
  if (handle->type != UV_TCP || addr.sin_family != AF_INET) {
241
205
  uv__set_artificial_error(handle->loop, UV_EFAULT);
@@ -352,3 +316,69 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
352
316
 
353
317
  return 0;
354
318
  }
319
+
320
+
321
+ void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
322
+ ngx_queue_t* q;
323
+ uv_handle_t* h;
324
+
325
+ ngx_queue_foreach(q, &loop->handle_queue) {
326
+ h = ngx_queue_data(q, uv_handle_t, handle_queue);
327
+ if (h->flags & UV__HANDLE_INTERNAL) continue;
328
+ walk_cb(h, arg);
329
+ }
330
+ }
331
+
332
+
333
+ #ifndef NDEBUG
334
+ static void uv__print_handles(uv_loop_t* loop, int only_active) {
335
+ const char* type;
336
+ ngx_queue_t* q;
337
+ uv_handle_t* h;
338
+
339
+ if (loop == NULL)
340
+ loop = uv_default_loop();
341
+
342
+ ngx_queue_foreach(q, &loop->handle_queue) {
343
+ h = ngx_queue_data(q, uv_handle_t, handle_queue);
344
+
345
+ if (only_active && !uv__is_active(h))
346
+ continue;
347
+
348
+ switch (h->type) {
349
+ #define X(uc, lc) case UV_##uc: type = #lc; break;
350
+ UV_HANDLE_TYPE_MAP(X)
351
+ #undef X
352
+ default: type = "<unknown>";
353
+ }
354
+
355
+ fprintf(stderr,
356
+ "[%c%c%c] %-8s %p\n",
357
+ "R-"[!(h->flags & UV__HANDLE_REF)],
358
+ "A-"[!(h->flags & UV__HANDLE_ACTIVE)],
359
+ "I-"[!(h->flags & UV__HANDLE_INTERNAL)],
360
+ type,
361
+ (void*)h);
362
+ }
363
+ }
364
+
365
+
366
+ void uv_print_all_handles(uv_loop_t* loop) {
367
+ uv__print_handles(loop, 0);
368
+ }
369
+
370
+
371
+ void uv_print_active_handles(uv_loop_t* loop) {
372
+ uv__print_handles(loop, 1);
373
+ }
374
+ #endif
375
+
376
+
377
+ void uv_ref(uv_handle_t* handle) {
378
+ uv__handle_ref(handle);
379
+ }
380
+
381
+
382
+ void uv_unref(uv_handle_t* handle) {
383
+ uv__handle_unref(handle);
384
+ }