asyncengine 0.0.1.testing1 → 0.0.2.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -30,98 +30,66 @@
30
30
  #include "winsock.h"
31
31
 
32
32
 
33
- /*
34
- * Timers
35
- */
36
- void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle);
37
-
38
- DWORD uv_get_poll_timeout(uv_loop_t* loop);
39
- void uv_process_timers(uv_loop_t* loop);
40
-
41
-
42
33
  /*
43
34
  * Handles
35
+ * (also see handle-inl.h)
44
36
  */
45
37
 
46
- /* Private uv_handle flags */
38
+ /* Used by all handles. */
47
39
  #define UV_HANDLE_CLOSING 0x00000001
48
40
  #define UV_HANDLE_CLOSED 0x00000002
49
- #define UV_HANDLE_BOUND 0x00000004
50
- #define UV_HANDLE_LISTENING 0x00000008
51
- #define UV_HANDLE_CONNECTION 0x00000010
52
- #define UV_HANDLE_CONNECTED 0x00000020
53
- #define UV_HANDLE_READING 0x00000040
54
- #define UV_HANDLE_ACTIVE 0x00000040
55
- #define UV_HANDLE_EOF 0x00000080
56
- #define UV_HANDLE_SHUTTING 0x00000100
57
- #define UV_HANDLE_SHUT 0x00000200
58
- #define UV_HANDLE_ENDGAME_QUEUED 0x00000400
59
- #define UV_HANDLE_BIND_ERROR 0x00001000
60
- #define UV_HANDLE_IPV6 0x00002000
61
- #define UV_HANDLE_PIPESERVER 0x00004000
62
- #define UV_HANDLE_READ_PENDING 0x00008000
63
- #define UV_HANDLE_UV_ALLOCED 0x00010000
64
- #define UV_HANDLE_SYNC_BYPASS_IOCP 0x00020000
65
- #define UV_HANDLE_ZERO_READ 0x00040000
66
- #define UV_HANDLE_TTY_RAW 0x00080000
41
+ #define UV_HANDLE_ENDGAME_QUEUED 0x00000004
42
+ #define UV_HANDLE_ACTIVE 0x00000010
43
+
44
+ /* uv-common.h: #define UV__HANDLE_ACTIVE 0x00000040 */
45
+ /* uv-common.h: #define UV__HANDLE_REF 0x00000020 */
46
+ /* reserved: #define UV_HANDLE_INTERNAL 0x00000080 */
47
+
48
+ /* Used by streams and UDP handles. */
49
+ #define UV_HANDLE_READING 0x00000100
50
+ #define UV_HANDLE_BOUND 0x00000200
51
+ #define UV_HANDLE_BIND_ERROR 0x00000400
52
+ #define UV_HANDLE_LISTENING 0x00000800
53
+ #define UV_HANDLE_CONNECTION 0x00001000
54
+ #define UV_HANDLE_CONNECTED 0x00002000
55
+ #define UV_HANDLE_EOF 0x00004000
56
+ #define UV_HANDLE_SHUTTING 0x00008000
57
+ #define UV_HANDLE_SHUT 0x00010000
58
+ #define UV_HANDLE_READ_PENDING 0x00020000
59
+ #define UV_HANDLE_SYNC_BYPASS_IOCP 0x00040000
60
+ #define UV_HANDLE_ZERO_READ 0x00080000
67
61
  #define UV_HANDLE_EMULATE_IOCP 0x00100000
68
- #define UV_HANDLE_NON_OVERLAPPED_PIPE 0x00200000
69
- #define UV_HANDLE_TTY_SAVED_POSITION 0x00400000
70
- #define UV_HANDLE_TTY_SAVED_ATTRIBUTES 0x00800000
71
- #define UV_HANDLE_SHARED_TCP_SOCKET 0x01000000
62
+
63
+ /* Only used by uv_tcp_t handles. */
64
+ #define UV_HANDLE_IPV6 0x01000000
72
65
  #define UV_HANDLE_TCP_NODELAY 0x02000000
73
66
  #define UV_HANDLE_TCP_KEEPALIVE 0x04000000
74
67
  #define UV_HANDLE_TCP_SINGLE_ACCEPT 0x08000000
75
68
  #define UV_HANDLE_TCP_ACCEPT_STATE_CHANGING 0x10000000
76
69
  #define UV_HANDLE_TCP_SOCKET_CLOSED 0x20000000
70
+ #define UV_HANDLE_SHARED_TCP_SOCKET 0x40000000
77
71
 
78
- void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle);
79
- void uv_process_endgames(uv_loop_t* loop);
72
+ /* Only used by uv_pipe_t handles. */
73
+ #define UV_HANDLE_NON_OVERLAPPED_PIPE 0x01000000
74
+ #define UV_HANDLE_PIPESERVER 0x02000000
80
75
 
81
- #define DECREASE_PENDING_REQ_COUNT(handle) \
82
- do { \
83
- assert(handle->reqs_pending > 0); \
84
- handle->reqs_pending--; \
85
- \
86
- if (handle->flags & UV_HANDLE_CLOSING && \
87
- handle->reqs_pending == 0) { \
88
- uv_want_endgame(loop, (uv_handle_t*)handle); \
89
- } \
90
- } while (0)
76
+ /* Only used by uv_tty_t handles. */
77
+ #define UV_HANDLE_TTY_RAW 0x01000000
78
+ #define UV_HANDLE_TTY_SAVED_POSITION 0x02000000
79
+ #define UV_HANDLE_TTY_SAVED_ATTRIBUTES 0x04000000
91
80
 
92
- #define UV_SUCCEEDED_WITHOUT_IOCP(result) \
93
- ((result) && (handle->flags & UV_HANDLE_SYNC_BYPASS_IOCP))
94
-
95
- #define UV_SUCCEEDED_WITH_IOCP(result) \
96
- ((result) || (GetLastError() == ERROR_IO_PENDING))
81
+ /* Only used by uv_poll_t handles. */
82
+ #define UV_HANDLE_POLL_SLOW 0x02000000
97
83
 
98
84
 
99
85
  /*
100
- * Requests
86
+ * Requests: see req-inl.h
101
87
  */
102
- void uv_req_init(uv_loop_t* loop, uv_req_t* req);
103
-
104
- uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped);
105
-
106
- void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req);
107
- void uv_process_reqs(uv_loop_t* loop);
108
-
109
- #define POST_COMPLETION_FOR_REQ(loop, req) \
110
- if (!PostQueuedCompletionStatus((loop)->iocp, \
111
- 0, \
112
- 0, \
113
- &((req)->overlapped))) { \
114
- uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); \
115
- }
116
88
 
117
89
 
118
90
  /*
119
- * Streams
91
+ * Streams: see stream-inl.h
120
92
  */
121
- void uv_stream_init(uv_loop_t* loop, uv_stream_t* handle);
122
- void uv_connection_init(uv_stream_t* handle);
123
-
124
- size_t uv_count_bufs(uv_buf_t bufs[], int count);
125
93
 
126
94
 
127
95
  /*
@@ -142,6 +110,7 @@ void uv_process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
142
110
  void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
143
111
  uv_connect_t* req);
144
112
 
113
+ void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp);
145
114
  void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);
146
115
 
147
116
  int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
@@ -150,8 +119,6 @@ int uv_tcp_import(uv_tcp_t* tcp, WSAPROTOCOL_INFOW* socket_protocol_info,
150
119
  int uv_tcp_duplicate_socket(uv_tcp_t* handle, int pid,
151
120
  LPWSAPROTOCOL_INFOW protocol_info);
152
121
 
153
- void uv_tcp_close(uv_tcp_t* tcp);
154
-
155
122
 
156
123
  /*
157
124
  * UDP
@@ -160,6 +127,7 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, uv_req_t* req);
160
127
  void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
161
128
  uv_udp_send_t* req);
162
129
 
130
+ void uv_udp_close(uv_loop_t* loop, uv_udp_t* handle);
163
131
  void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
164
132
 
165
133
 
@@ -168,8 +136,6 @@ void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
168
136
  */
169
137
  int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
170
138
  char* name, size_t nameSize);
171
- void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err);
172
- void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle);
173
139
 
174
140
  int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
175
141
  int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client);
@@ -193,6 +159,10 @@ void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
193
159
  void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
194
160
  uv_shutdown_t* req);
195
161
 
162
+ void uv_pipe_close(uv_loop_t* loop, uv_pipe_t* handle);
163
+ void uv_pipe_cleanup(uv_loop_t* loop, uv_pipe_t* handle);
164
+ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle);
165
+
196
166
 
197
167
  /*
198
168
  * TTY
@@ -220,6 +190,25 @@ void uv_process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle,
220
190
  void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle);
221
191
 
222
192
 
193
+ /*
194
+ * Poll watchers
195
+ */
196
+ void uv_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
197
+ uv_req_t* req);
198
+
199
+ void uv_poll_close(uv_loop_t* loop, uv_poll_t* handle);
200
+ void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
201
+
202
+
203
+ /*
204
+ * Timers
205
+ */
206
+ void uv_timer_endgame(uv_loop_t* loop, uv_timer_t* handle);
207
+
208
+ DWORD uv_get_poll_timeout(uv_loop_t* loop);
209
+ void uv_process_timers(uv_loop_t* loop);
210
+
211
+
223
212
  /*
224
213
  * Loop watchers
225
214
  */
@@ -229,10 +218,13 @@ void uv_prepare_invoke(uv_loop_t* loop);
229
218
  void uv_check_invoke(uv_loop_t* loop);
230
219
  void uv_idle_invoke(uv_loop_t* loop);
231
220
 
221
+ void uv__once_init();
222
+
232
223
 
233
224
  /*
234
225
  * Async watcher
235
226
  */
227
+ void uv_async_close(uv_loop_t* loop, uv_async_t* handle);
236
228
  void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle);
237
229
 
238
230
  void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
@@ -248,21 +240,10 @@ void uv_process_close(uv_loop_t* loop, uv_process_t* handle);
248
240
  void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle);
249
241
 
250
242
 
251
- /*
252
- * C-ares integration
253
- */
254
- typedef struct uv_ares_action_s uv_ares_action_t;
255
-
256
- void uv_process_ares_event_req(uv_loop_t* loop, uv_ares_action_t* handle,
257
- uv_req_t* req);
258
- void uv_process_ares_cleanup_req(uv_loop_t* loop, uv_ares_task_t* handle,
259
- uv_req_t* req);
260
-
261
243
  /*
262
244
  * Getaddrinfo
263
245
  */
264
- void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
265
- uv_req_t* req);
246
+ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req);
266
247
 
267
248
 
268
249
  /*
@@ -281,37 +262,38 @@ void uv_process_work_req(uv_loop_t* loop, uv_work_t* req);
281
262
  /*
282
263
  * FS Event
283
264
  */
284
- void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req, uv_fs_event_t* handle);
265
+ void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
266
+ uv_fs_event_t* handle);
285
267
  void uv_fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle);
286
268
  void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);
287
269
 
288
270
 
289
- /* Utils */
290
- int uv_parent_pid();
291
- void uv_filetime_to_time_t(FILETIME* file_time, time_t* stat_time);
292
- void uv_fatal_error(const int errorno, const char* syscall);
293
- uv_err_code uv_translate_sys_error(int sys_errno);
294
-
295
- #define SET_REQ_STATUS(req, status) \
296
- (req)->overlapped.Internal = (ULONG_PTR) (status)
297
-
298
- #define SET_REQ_ERROR(req, error) \
299
- SET_REQ_STATUS((req), NTSTATUS_FROM_WIN32((error)))
271
+ /*
272
+ * Stat poller.
273
+ */
274
+ void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
300
275
 
301
- #define SET_REQ_SUCCESS(req) \
302
- SET_REQ_STATUS((req), STATUS_SUCCESS)
303
276
 
304
- #define GET_REQ_STATUS(req) \
305
- ((req)->overlapped.Internal)
277
+ /*
278
+ * Utilities.
279
+ */
280
+ void uv__util_init();
306
281
 
307
- #define REQ_SUCCESS(req) \
308
- (NT_SUCCESS(GET_REQ_STATUS((req))))
282
+ int uv_parent_pid();
283
+ void uv_fatal_error(const int errorno, const char* syscall);
284
+ uv_err_code uv_translate_sys_error(int sys_errno);
309
285
 
310
- #define GET_REQ_ERROR(req) \
311
- (pRtlNtStatusToDosError(GET_REQ_STATUS((req))))
312
286
 
313
- #define GET_REQ_SOCK_ERROR(req) \
314
- (uv_ntstatus_to_winsock_error(GET_REQ_STATUS((req))))
287
+ /*
288
+ * Process stdio handles.
289
+ */
290
+ int uv__stdio_create(uv_loop_t* loop, uv_process_options_t* options,
291
+ BYTE** buffer_ptr);
292
+ void uv__stdio_destroy(BYTE* buffer);
293
+ void uv__stdio_noinherit(BYTE* buffer);
294
+ int uv__stdio_verify(BYTE* buffer, WORD size);
295
+ WORD uv__stdio_size(BYTE* buffer);
296
+ HANDLE uv__stdio_handle(BYTE* buffer, int fd);
315
297
 
316
298
 
317
299
  /*
@@ -338,6 +320,9 @@ int WSAAPI uv_wsarecvfrom_workaround(SOCKET socket, WSABUF* buffers,
338
320
  int* addr_len, WSAOVERLAPPED *overlapped,
339
321
  LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
340
322
 
323
+ int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info,
324
+ OVERLAPPED* overlapped);
325
+
341
326
  /* Whether ipv6 is supported */
342
327
  extern int uv_allow_ipv6;
343
328
 
@@ -22,33 +22,23 @@
22
22
  #include <assert.h>
23
23
 
24
24
  #include "uv.h"
25
- #include "../uv-common.h"
26
25
  #include "internal.h"
26
+ #include "handle-inl.h"
27
27
 
28
28
 
29
29
  void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
30
30
  if (handle->flags & UV_HANDLE_CLOSING) {
31
31
  assert(!(handle->flags & UV_HANDLE_CLOSED));
32
32
  handle->flags |= UV_HANDLE_CLOSED;
33
-
34
- if (handle->close_cb) {
35
- handle->close_cb(handle);
36
- }
37
-
38
- uv_unref(loop);
33
+ uv__handle_stop(handle);
34
+ uv__handle_close(handle);
39
35
  }
40
36
  }
41
37
 
42
38
 
43
39
  #define UV_LOOP_WATCHER_DEFINE(name, NAME) \
44
40
  int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \
45
- handle->type = UV_##NAME; \
46
- handle->loop = loop; \
47
- handle->flags = 0; \
48
- \
49
- uv_ref(loop); \
50
- \
51
- loop->counters.handle_init++; \
41
+ uv__handle_init(loop, (uv_handle_t*) handle, UV_##NAME); \
52
42
  loop->counters.name##_init++; \
53
43
  \
54
44
  return 0; \
@@ -77,6 +67,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
77
67
  \
78
68
  handle->name##_cb = cb; \
79
69
  handle->flags |= UV_HANDLE_ACTIVE; \
70
+ uv__handle_start(handle); \
80
71
  \
81
72
  return 0; \
82
73
  } \
@@ -108,6 +99,7 @@ void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle) {
108
99
  } \
109
100
  \
110
101
  handle->flags &= ~UV_HANDLE_ACTIVE; \
102
+ uv__handle_stop(handle); \
111
103
  \
112
104
  return 0; \
113
105
  } \
@@ -25,8 +25,10 @@
25
25
  #include <stdio.h>
26
26
 
27
27
  #include "uv.h"
28
- #include "../uv-common.h"
29
28
  #include "internal.h"
29
+ #include "handle-inl.h"
30
+ #include "stream-inl.h"
31
+ #include "req-inl.h"
30
32
 
31
33
 
32
34
  /* A zero-size buffer for use by uv_pipe_read */
@@ -72,9 +74,8 @@ static void uv_unique_pipe_name(char* ptr, char* name, size_t size) {
72
74
 
73
75
 
74
76
  int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) {
75
- uv_stream_init(loop, (uv_stream_t*)handle);
77
+ uv_stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE);
76
78
 
77
- handle->type = UV_NAMED_PIPE;
78
79
  handle->reqs_pending = 0;
79
80
  handle->handle = INVALID_HANDLE_VALUE;
80
81
  handle->name = NULL;
@@ -161,11 +162,11 @@ static HANDLE open_named_pipe(WCHAR* name, DWORD* duplex_flags) {
161
162
  int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
162
163
  char* name, size_t nameSize) {
163
164
  HANDLE pipeHandle;
164
- int errno;
165
+ int errorno;
165
166
  int err;
166
167
  char* ptr = (char*)handle;
167
168
 
168
- while (TRUE) {
169
+ for (;;) {
169
170
  uv_unique_pipe_name(ptr, name, nameSize);
170
171
 
171
172
  pipeHandle = CreateNamedPipeA(name,
@@ -178,9 +179,9 @@ int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access,
178
179
  break;
179
180
  }
180
181
 
181
- errno = GetLastError();
182
- if (errno != ERROR_PIPE_BUSY && errno != ERROR_ACCESS_DENIED) {
183
- uv__set_sys_error(loop, errno);
182
+ errorno = GetLastError();
183
+ if (errorno != ERROR_PIPE_BUSY && errorno != ERROR_ACCESS_DENIED) {
184
+ uv__set_sys_error(loop, errorno);
184
185
  err = -1;
185
186
  goto done;
186
187
  }
@@ -259,7 +260,6 @@ static int uv_set_pipe_handle(uv_loop_t* loop, uv_pipe_t* handle,
259
260
 
260
261
 
261
262
  static DWORD WINAPI pipe_shutdown_thread_proc(void* parameter) {
262
- int errno;
263
263
  uv_loop_t* loop;
264
264
  uv_pipe_t* handle;
265
265
  uv_shutdown_t* req;
@@ -281,7 +281,6 @@ static DWORD WINAPI pipe_shutdown_thread_proc(void* parameter) {
281
281
 
282
282
 
283
283
  void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
284
- unsigned int uv_alloced;
285
284
  DWORD result;
286
285
  uv_shutdown_t* req;
287
286
  NTSTATUS nt_status;
@@ -297,12 +296,14 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
297
296
  handle->shutdown_req = NULL;
298
297
 
299
298
  if (handle->flags & UV_HANDLE_CLOSING) {
299
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
300
+
300
301
  /* Already closing. Cancel the shutdown. */
301
302
  if (req->cb) {
302
303
  uv__set_sys_error(loop, WSAEINTR);
303
304
  req->cb(req, -1);
304
305
  }
305
- uv_unref(loop);
306
+
306
307
  DECREASE_PENDING_REQ_COUNT(handle);
307
308
  return;
308
309
  }
@@ -316,12 +317,14 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
316
317
 
317
318
  if (nt_status != STATUS_SUCCESS) {
318
319
  /* Failure */
320
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
321
+
319
322
  handle->flags &= ~UV_HANDLE_SHUTTING;
320
323
  if (req->cb) {
321
324
  uv__set_sys_error(loop, pRtlNtStatusToDosError(nt_status));
322
325
  req->cb(req, -1);
323
326
  }
324
- uv_unref(loop);
327
+
325
328
  DECREASE_PENDING_REQ_COUNT(handle);
326
329
  return;
327
330
  }
@@ -341,12 +344,14 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
341
344
 
342
345
  } else {
343
346
  /* Failure. */
347
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
348
+
344
349
  handle->flags &= ~UV_HANDLE_SHUTTING;
345
350
  if (req->cb) {
346
351
  uv__set_sys_error(loop, GetLastError());
347
352
  req->cb(req, -1);
348
353
  }
349
- uv_unref(loop);
354
+
350
355
  DECREASE_PENDING_REQ_COUNT(handle);
351
356
  return;
352
357
  }
@@ -355,7 +360,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
355
360
  if (handle->flags & UV_HANDLE_CLOSING &&
356
361
  handle->reqs_pending == 0) {
357
362
  assert(!(handle->flags & UV_HANDLE_CLOSED));
358
- handle->flags |= UV_HANDLE_CLOSED;
363
+ uv__handle_stop(handle);
359
364
 
360
365
  if (handle->flags & UV_HANDLE_CONNECTION) {
361
366
  if (handle->pending_ipc_info.socket_info) {
@@ -381,19 +386,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) {
381
386
  handle->accept_reqs = NULL;
382
387
  }
383
388
 
384
- /* Remember the state of this flag because the close callback is */
385
- /* allowed to clobber or free the handle's memory */
386
- uv_alloced = handle->flags & UV_HANDLE_UV_ALLOCED;
387
-
388
- if (handle->close_cb) {
389
- handle->close_cb((uv_handle_t*)handle);
390
- }
391
-
392
- if (uv_alloced) {
393
- free(handle);
394
- }
395
-
396
- uv_unref(loop);
389
+ uv__handle_close(handle);
397
390
  }
398
391
  }
399
392
 
@@ -407,7 +400,7 @@ void uv_pipe_pending_instances(uv_pipe_t* handle, int count) {
407
400
  /* Creates a pipe server. */
408
401
  int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
409
402
  uv_loop_t* loop = handle->loop;
410
- int i, errno, nameSize;
403
+ int i, errorno, nameSize;
411
404
  uv_pipe_accept_t* req;
412
405
 
413
406
  if (handle->flags & UV_HANDLE_BOUND) {
@@ -462,13 +455,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
462
455
  PIPE_UNLIMITED_INSTANCES, 65536, 65536, 0, NULL);
463
456
 
464
457
  if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) {
465
- errno = GetLastError();
466
- if (errno == ERROR_ACCESS_DENIED) {
467
- uv__set_error(loop, UV_EADDRINUSE, errno);
468
- } else if (errno == ERROR_PATH_NOT_FOUND || errno == ERROR_INVALID_NAME) {
469
- uv__set_error(loop, UV_EACCES, errno);
458
+ errorno = GetLastError();
459
+ if (errorno == ERROR_ACCESS_DENIED) {
460
+ uv__set_error(loop, UV_EADDRINUSE, errorno);
461
+ } else if (errorno == ERROR_PATH_NOT_FOUND || errorno == ERROR_INVALID_NAME) {
462
+ uv__set_error(loop, UV_EACCES, errorno);
470
463
  } else {
471
- uv__set_sys_error(loop, errno);
464
+ uv__set_sys_error(loop, errorno);
472
465
  }
473
466
  goto error;
474
467
  }
@@ -500,7 +493,6 @@ error:
500
493
 
501
494
 
502
495
  static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
503
- int errno;
504
496
  uv_loop_t* loop;
505
497
  uv_pipe_t* handle;
506
498
  uv_connect_t* req;
@@ -543,7 +535,7 @@ static DWORD WINAPI pipe_connect_thread_proc(void* parameter) {
543
535
  void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
544
536
  const char* name, uv_connect_cb cb) {
545
537
  uv_loop_t* loop = handle->loop;
546
- int errno, nameSize;
538
+ int errorno, nameSize;
547
539
  HANDLE pipeHandle = INVALID_HANDLE_VALUE;
548
540
  DWORD duplex_flags;
549
541
 
@@ -560,7 +552,7 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
560
552
  }
561
553
 
562
554
  if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(wchar_t))) {
563
- errno = GetLastError();
555
+ errorno = GetLastError();
564
556
  goto error;
565
557
  }
566
558
 
@@ -571,17 +563,17 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
571
563
  if (!QueueUserWorkItem(&pipe_connect_thread_proc,
572
564
  req,
573
565
  WT_EXECUTELONGFUNCTION)) {
574
- errno = GetLastError();
566
+ errorno = GetLastError();
575
567
  goto error;
576
568
  }
577
569
 
578
- uv_ref(loop);
570
+ REGISTER_HANDLE_REQ(loop, handle, req);
579
571
  handle->reqs_pending++;
580
572
 
581
573
  return;
582
574
  }
583
575
 
584
- errno = GetLastError();
576
+ errorno = GetLastError();
585
577
  goto error;
586
578
  }
587
579
 
@@ -591,14 +583,14 @@ void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
591
583
  (uv_pipe_t*) req->handle,
592
584
  pipeHandle,
593
585
  duplex_flags)) {
594
- errno = GetLastError();
586
+ errorno = GetLastError();
595
587
  goto error;
596
588
  }
597
589
 
598
590
  SET_REQ_SUCCESS(req);
599
591
  uv_insert_pending_req(loop, (uv_req_t*) req);
600
592
  handle->reqs_pending++;
601
- uv_ref(loop);
593
+ REGISTER_HANDLE_REQ(loop, handle, req);
602
594
  return;
603
595
 
604
596
  error:
@@ -612,17 +604,17 @@ error:
612
604
  }
613
605
 
614
606
  /* Make this req pending reporting an error. */
615
- SET_REQ_ERROR(req, errno);
607
+ SET_REQ_ERROR(req, errorno);
616
608
  uv_insert_pending_req(loop, (uv_req_t*) req);
617
609
  handle->reqs_pending++;
618
- uv_ref(loop);
610
+ REGISTER_HANDLE_REQ(loop, handle, req);
619
611
  return;
620
612
  }
621
613
 
622
614
 
623
615
  /* Cleans up uv_pipe_t (server or connection) and all resources associated */
624
616
  /* with it. */
625
- void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) {
617
+ void uv_pipe_cleanup(uv_loop_t* loop, uv_pipe_t* handle) {
626
618
  int i;
627
619
  HANDLE pipeHandle;
628
620
 
@@ -654,6 +646,27 @@ void close_pipe(uv_pipe_t* handle, int* status, uv_err_t* err) {
654
646
  }
655
647
 
656
648
 
649
+ void uv_pipe_close(uv_loop_t* loop, uv_pipe_t* handle) {
650
+ if (handle->flags & UV_HANDLE_READING) {
651
+ handle->flags &= ~UV_HANDLE_READING;
652
+ DECREASE_ACTIVE_COUNT(loop, handle);
653
+ }
654
+
655
+ if (handle->flags & UV_HANDLE_LISTENING) {
656
+ handle->flags &= ~UV_HANDLE_LISTENING;
657
+ DECREASE_ACTIVE_COUNT(loop, handle);
658
+ }
659
+
660
+ uv_pipe_cleanup(loop, handle);
661
+
662
+ if (handle->reqs_pending == 0) {
663
+ uv_want_endgame(loop, (uv_handle_t*) handle);
664
+ }
665
+
666
+ uv__handle_start(handle);
667
+ }
668
+
669
+
657
670
  static void uv_pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle,
658
671
  uv_pipe_accept_t* req, BOOL firstInstance) {
659
672
  assert(handle->flags & UV_HANDLE_LISTENING);
@@ -719,7 +732,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
719
732
  return -1;
720
733
  }
721
734
 
722
- return uv_tcp_import((uv_tcp_t*)client, server->pending_ipc_info.socket_info,
735
+ return uv_tcp_import((uv_tcp_t*)client, server->pending_ipc_info.socket_info,
723
736
  server->pending_ipc_info.tcp_connection);
724
737
  } else {
725
738
  pipe_client = (uv_pipe_t*)client;
@@ -755,17 +768,19 @@ int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
755
768
  /* Starts listening for connections for the given pipe. */
756
769
  int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
757
770
  uv_loop_t* loop = handle->loop;
771
+ int i;
758
772
 
759
- int i, errno;
773
+ if (handle->flags & UV_HANDLE_LISTENING) {
774
+ handle->connection_cb = cb;
775
+ }
760
776
 
761
777
  if (!(handle->flags & UV_HANDLE_BOUND)) {
762
778
  uv__set_artificial_error(loop, UV_EINVAL);
763
779
  return -1;
764
780
  }
765
781
 
766
- if (handle->flags & UV_HANDLE_LISTENING ||
767
- handle->flags & UV_HANDLE_READING) {
768
- uv__set_artificial_error(loop, UV_EALREADY);
782
+ if (handle->flags & UV_HANDLE_READING) {
783
+ uv__set_artificial_error(loop, UV_EISCONN);
769
784
  return -1;
770
785
  }
771
786
 
@@ -775,6 +790,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
775
790
  }
776
791
 
777
792
  handle->flags |= UV_HANDLE_LISTENING;
793
+ INCREASE_ACTIVE_COUNT(loop, handle);
778
794
  handle->connection_cb = cb;
779
795
 
780
796
  /* First pipe handle should have already been created in uv_pipe_bind */
@@ -957,17 +973,13 @@ static int uv_pipe_read_start_impl(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
957
973
  return -1;
958
974
  }
959
975
 
960
- if (handle->flags & UV_HANDLE_READING) {
961
- uv__set_artificial_error(loop, UV_EALREADY);
962
- return -1;
963
- }
964
-
965
976
  if (handle->flags & UV_HANDLE_EOF) {
966
977
  uv__set_artificial_error(loop, UV_EOF);
967
978
  return -1;
968
979
  }
969
980
 
970
981
  handle->flags |= UV_HANDLE_READING;
982
+ INCREASE_ACTIVE_COUNT(loop, handle);
971
983
  handle->read_cb = read_cb;
972
984
  handle->read2_cb = read2_cb;
973
985
  handle->alloc_cb = alloc_cb;
@@ -1156,10 +1168,10 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
1156
1168
  /* Request queued by the kernel. */
1157
1169
  ipc_header_req->queued_bytes = ipc_frame.header.flags & UV_IPC_TCP_SERVER ?
1158
1170
  sizeof(ipc_frame) : sizeof(ipc_frame.header);
1159
- handle->write_queue_size += req->queued_bytes;
1171
+ handle->write_queue_size += ipc_header_req->queued_bytes;
1160
1172
  }
1161
1173
 
1162
- uv_ref(loop);
1174
+ REGISTER_HANDLE_REQ(loop, handle, ipc_header_req);
1163
1175
  handle->reqs_pending++;
1164
1176
  handle->write_reqs_pending++;
1165
1177
 
@@ -1214,7 +1226,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop, uv_write_t* req,
1214
1226
  }
1215
1227
  }
1216
1228
 
1217
- uv_ref(loop);
1229
+ REGISTER_HANDLE_REQ(loop, handle, req);
1218
1230
  handle->reqs_pending++;
1219
1231
  handle->write_reqs_pending++;
1220
1232
 
@@ -1437,6 +1449,8 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
1437
1449
  assert(handle->write_queue_size >= req->queued_bytes);
1438
1450
  handle->write_queue_size -= req->queued_bytes;
1439
1451
 
1452
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
1453
+
1440
1454
  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
1441
1455
  if (req->wait_handle != INVALID_HANDLE_VALUE) {
1442
1456
  UnregisterWait(req->wait_handle);
@@ -1478,7 +1492,6 @@ void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
1478
1492
  uv_want_endgame(loop, (uv_handle_t*)handle);
1479
1493
  }
1480
1494
 
1481
- uv_unref(loop);
1482
1495
  DECREASE_PENDING_REQ_COUNT(handle);
1483
1496
  }
1484
1497
 
@@ -1515,6 +1528,8 @@ void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
1515
1528
  uv_connect_t* req) {
1516
1529
  assert(handle->type == UV_NAMED_PIPE);
1517
1530
 
1531
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
1532
+
1518
1533
  if (req->cb) {
1519
1534
  if (REQ_SUCCESS(req)) {
1520
1535
  uv_pipe_connection_init(handle);
@@ -1525,7 +1540,6 @@ void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
1525
1540
  }
1526
1541
  }
1527
1542
 
1528
- uv_unref(loop);
1529
1543
  DECREASE_PENDING_REQ_COUNT(handle);
1530
1544
  }
1531
1545
 
@@ -1534,6 +1548,8 @@ void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
1534
1548
  uv_shutdown_t* req) {
1535
1549
  assert(handle->type == UV_NAMED_PIPE);
1536
1550
 
1551
+ UNREGISTER_HANDLE_REQ(loop, handle, req);
1552
+
1537
1553
  /* Initialize and optionally start the eof timer. */
1538
1554
  /* This makes no sense if we've already seen EOF. */
1539
1555
  if (!(handle->flags & UV_HANDLE_EOF)) {
@@ -1550,7 +1566,6 @@ void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
1550
1566
  req->cb(req, 0);
1551
1567
  }
1552
1568
 
1553
- uv_unref(loop);
1554
1569
  DECREASE_PENDING_REQ_COUNT(handle);
1555
1570
  }
1556
1571
 
@@ -1566,7 +1581,7 @@ static void eof_timer_init(uv_pipe_t* pipe) {
1566
1581
  r = uv_timer_init(pipe->loop, pipe->eof_timer);
1567
1582
  assert(r == 0); /* timers can't fail */
1568
1583
  pipe->eof_timer->data = pipe;
1569
- uv_unref(pipe->loop);
1584
+ uv_unref((uv_handle_t*) pipe->eof_timer);
1570
1585
  }
1571
1586
 
1572
1587
 
@@ -1600,7 +1615,7 @@ static void eof_timer_cb(uv_timer_t* timer, int status) {
1600
1615
  /* or in uv_process_pipe_shutdown_req if a read is pending, */
1601
1616
  /* and we always immediately stop the timer in */
1602
1617
  /* uv_process_pipe_read_req. */
1603
- assert(pipe->flags & UV_HANDLE_READ_PENDING) ;
1618
+ assert(pipe->flags & UV_HANDLE_READ_PENDING);
1604
1619
 
1605
1620
  /* If there are many packets coming off the iocp then the timer callback */
1606
1621
  /* may be called before the read request is coming off the queue. */
@@ -1629,7 +1644,6 @@ static void eof_timer_destroy(uv_pipe_t* pipe) {
1629
1644
  assert(pipe->flags && UV_HANDLE_CONNECTION);
1630
1645
 
1631
1646
  if (pipe->eof_timer) {
1632
- uv_ref(pipe->loop);
1633
1647
  uv_close((uv_handle_t*) pipe->eof_timer, eof_timer_close_cb);
1634
1648
  pipe->eof_timer = NULL;
1635
1649
  }