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
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include "uv.h"
26
26
  #include "internal.h"
27
+ #include "req-inl.h"
27
28
 
28
29
 
29
30
  /*
@@ -77,23 +78,21 @@ static uv_err_code uv_translate_eai_error(int eai_errno) {
77
78
 
78
79
  /* getaddrinfo worker thread implementation */
79
80
  static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
80
- uv_getaddrinfo_t* handle = (uv_getaddrinfo_t*) parameter;
81
- uv_loop_t* loop = handle->loop;
81
+ uv_getaddrinfo_t* req = (uv_getaddrinfo_t*) parameter;
82
+ uv_loop_t* loop = req->loop;
82
83
  int ret;
83
84
 
84
- assert(handle != NULL);
85
+ assert(req != NULL);
85
86
 
86
- if (handle != NULL) {
87
- /* call OS function on this thread */
88
- ret = GetAddrInfoW(handle->node,
89
- handle->service,
90
- handle->hints,
91
- &handle->res);
92
- handle->retcode = ret;
87
+ /* call OS function on this thread */
88
+ ret = GetAddrInfoW(req->node,
89
+ req->service,
90
+ req->hints,
91
+ &req->res);
92
+ req->retcode = ret;
93
93
 
94
- /* post getaddrinfo completed */
95
- POST_COMPLETION_FOR_REQ(loop, &handle->getadddrinfo_req);
96
- }
94
+ /* post getaddrinfo completed */
95
+ POST_COMPLETION_FOR_REQ(loop, req);
97
96
 
98
97
  return 0;
99
98
  }
@@ -108,8 +107,7 @@ static DWORD WINAPI getaddrinfo_thread_proc(void* parameter) {
108
107
  * and copy all structs and referenced strings into the one block.
109
108
  * Each size calculation is adjusted to avoid unaligned pointers.
110
109
  */
111
- void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
112
- uv_req_t* req) {
110
+ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* req) {
113
111
  int addrinfo_len = 0;
114
112
  int name_len = 0;
115
113
  size_t addrinfo_struct_len = ALIGNED_SIZE(sizeof(struct addrinfo));
@@ -120,15 +118,15 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
120
118
  int status = 0;
121
119
 
122
120
  /* release input parameter memory */
123
- if (handle->alloc != NULL) {
124
- free(handle->alloc);
125
- handle->alloc = NULL;
121
+ if (req->alloc != NULL) {
122
+ free(req->alloc);
123
+ req->alloc = NULL;
126
124
  }
127
125
 
128
- if (handle->retcode == 0) {
126
+ if (req->retcode == 0) {
129
127
  /* convert addrinfoW to addrinfo */
130
128
  /* first calculate required length */
131
- addrinfow_ptr = handle->res;
129
+ addrinfow_ptr = req->res;
132
130
  while (addrinfow_ptr != NULL) {
133
131
  addrinfo_len += addrinfo_struct_len +
134
132
  ALIGNED_SIZE(addrinfow_ptr->ai_addrlen);
@@ -150,7 +148,7 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
150
148
  /* do conversions */
151
149
  if (alloc_ptr != NULL) {
152
150
  cur_ptr = alloc_ptr;
153
- addrinfow_ptr = handle->res;
151
+ addrinfow_ptr = req->res;
154
152
 
155
153
  while (addrinfow_ptr != NULL) {
156
154
  /* copy addrinfo struct data */
@@ -206,21 +204,21 @@ void uv_process_getaddrinfo_req(uv_loop_t* loop, uv_getaddrinfo_t* handle,
206
204
  }
207
205
  } else {
208
206
  /* GetAddrInfo failed */
209
- uv__set_artificial_error(loop, uv_translate_eai_error(handle->retcode));
207
+ uv__set_artificial_error(loop, uv_translate_eai_error(req->retcode));
210
208
  status = -1;
211
209
  }
212
210
 
213
211
  /* return memory to system */
214
- if (handle->res != NULL) {
215
- FreeAddrInfoW(handle->res);
216
- handle->res = NULL;
212
+ if (req->res != NULL) {
213
+ FreeAddrInfoW(req->res);
214
+ req->res = NULL;
217
215
  }
218
216
 
219
217
  complete:
220
- /* finally do callback with converted result */
221
- handle->getaddrinfo_cb(handle, status, (struct addrinfo*)alloc_ptr);
218
+ uv__req_unregister(loop, req);
222
219
 
223
- uv_unref(loop);
220
+ /* finally do callback with converted result */
221
+ req->getaddrinfo_cb(req, status, (struct addrinfo*)alloc_ptr);
224
222
  }
225
223
 
226
224
 
@@ -237,7 +235,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
237
235
  /*
238
236
  * Entry point for getaddrinfo
239
237
  * we convert the UTF-8 strings to UNICODE
240
- * and save the UNICODE string pointers in the handle
238
+ * and save the UNICODE string pointers in the req
241
239
  * We also copy hints so that caller does not need to keep memory until the
242
240
  * callback.
243
241
  * return UV_OK if a callback will be made
@@ -248,7 +246,7 @@ void uv_freeaddrinfo(struct addrinfo* ai) {
248
246
  * Each size calculation is adjusted to avoid unaligned pointers.
249
247
  */
250
248
  int uv_getaddrinfo(uv_loop_t* loop,
251
- uv_getaddrinfo_t* handle,
249
+ uv_getaddrinfo_t* req,
252
250
  uv_getaddrinfo_cb getaddrinfo_cb,
253
251
  const char* node,
254
252
  const char* service,
@@ -258,18 +256,18 @@ int uv_getaddrinfo(uv_loop_t* loop,
258
256
  int hintssize = 0;
259
257
  char* alloc_ptr = NULL;
260
258
 
261
- if (handle == NULL || getaddrinfo_cb == NULL ||
259
+ if (req == NULL || getaddrinfo_cb == NULL ||
262
260
  (node == NULL && service == NULL)) {
263
261
  uv__set_sys_error(loop, WSAEINVAL);
264
262
  goto error;
265
263
  }
266
264
 
267
- uv_req_init(loop, (uv_req_t*)handle);
265
+ uv_req_init(loop, (uv_req_t*)req);
268
266
 
269
- handle->getaddrinfo_cb = getaddrinfo_cb;
270
- handle->res = NULL;
271
- handle->type = UV_GETADDRINFO;
272
- handle->loop = loop;
267
+ req->getaddrinfo_cb = getaddrinfo_cb;
268
+ req->res = NULL;
269
+ req->type = UV_GETADDRINFO;
270
+ req->loop = loop;
273
271
 
274
272
  /* calculate required memory size for all input values */
275
273
  if (node != NULL) {
@@ -300,12 +298,12 @@ int uv_getaddrinfo(uv_loop_t* loop,
300
298
  }
301
299
 
302
300
  /* save alloc_ptr now so we can free if error */
303
- handle->alloc = (void*)alloc_ptr;
301
+ req->alloc = (void*)alloc_ptr;
304
302
 
305
303
  /* convert node string to UTF16 into allocated memory and save pointer in */
306
- /* handle */
304
+ /* the reques. */
307
305
  if (node != NULL) {
308
- handle->node = (wchar_t*)alloc_ptr;
306
+ req->node = (wchar_t*)alloc_ptr;
309
307
  if (uv_utf8_to_utf16(node,
310
308
  (wchar_t*) alloc_ptr,
311
309
  nodesize / sizeof(wchar_t)) == 0) {
@@ -314,13 +312,13 @@ int uv_getaddrinfo(uv_loop_t* loop,
314
312
  }
315
313
  alloc_ptr += nodesize;
316
314
  } else {
317
- handle->node = NULL;
315
+ req->node = NULL;
318
316
  }
319
317
 
320
318
  /* convert service string to UTF16 into allocated memory and save pointer */
321
- /* in handle */
319
+ /* in the req. */
322
320
  if (service != NULL) {
323
- handle->service = (wchar_t*)alloc_ptr;
321
+ req->service = (wchar_t*)alloc_ptr;
324
322
  if (uv_utf8_to_utf16(service,
325
323
  (wchar_t*) alloc_ptr,
326
324
  servicesize / sizeof(wchar_t)) == 0) {
@@ -329,44 +327,39 @@ int uv_getaddrinfo(uv_loop_t* loop,
329
327
  }
330
328
  alloc_ptr += servicesize;
331
329
  } else {
332
- handle->service = NULL;
330
+ req->service = NULL;
333
331
  }
334
332
 
335
- /* copy hints to allocated memory and save pointer in handle */
333
+ /* copy hints to allocated memory and save pointer in req */
336
334
  if (hints != NULL) {
337
- handle->hints = (struct addrinfoW*)alloc_ptr;
338
- handle->hints->ai_family = hints->ai_family;
339
- handle->hints->ai_socktype = hints->ai_socktype;
340
- handle->hints->ai_protocol = hints->ai_protocol;
341
- handle->hints->ai_flags = hints->ai_flags;
342
- handle->hints->ai_addrlen = 0;
343
- handle->hints->ai_canonname = NULL;
344
- handle->hints->ai_addr = NULL;
345
- handle->hints->ai_next = NULL;
335
+ req->hints = (struct addrinfoW*)alloc_ptr;
336
+ req->hints->ai_family = hints->ai_family;
337
+ req->hints->ai_socktype = hints->ai_socktype;
338
+ req->hints->ai_protocol = hints->ai_protocol;
339
+ req->hints->ai_flags = hints->ai_flags;
340
+ req->hints->ai_addrlen = 0;
341
+ req->hints->ai_canonname = NULL;
342
+ req->hints->ai_addr = NULL;
343
+ req->hints->ai_next = NULL;
346
344
  } else {
347
- handle->hints = NULL;
345
+ req->hints = NULL;
348
346
  }
349
347
 
350
- /* init request for Post handling */
351
- uv_req_init(loop, &handle->getadddrinfo_req);
352
- handle->getadddrinfo_req.data = handle;
353
- handle->getadddrinfo_req.type = UV_GETADDRINFO_REQ;
354
-
355
348
  /* Ask thread to run. Treat this as a long operation */
356
349
  if (QueueUserWorkItem(&getaddrinfo_thread_proc,
357
- handle,
350
+ req,
358
351
  WT_EXECUTELONGFUNCTION) == 0) {
359
352
  uv__set_sys_error(loop, GetLastError());
360
353
  goto error;
361
354
  }
362
355
 
363
- uv_ref(loop);
356
+ uv__req_register(loop, req);
364
357
 
365
358
  return 0;
366
359
 
367
360
  error:
368
- if (handle != NULL && handle->alloc != NULL) {
369
- free(handle->alloc);
361
+ if (req != NULL && req->alloc != NULL) {
362
+ free(req->alloc);
370
363
  }
371
364
  return -1;
372
365
  }
@@ -0,0 +1,145 @@
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
+ #ifndef UV_WIN_HANDLE_INL_H_
23
+ #define UV_WIN_HANDLE_INL_H_
24
+
25
+ #include <assert.h>
26
+
27
+ #include "uv.h"
28
+ #include "internal.h"
29
+
30
+
31
+ #define DECREASE_ACTIVE_COUNT(loop, handle) \
32
+ do { \
33
+ if (--(handle)->activecnt == 0 && \
34
+ !((handle)->flags & UV_HANDLE_CLOSING)) { \
35
+ uv__handle_stop((handle)); \
36
+ } \
37
+ assert((handle)->activecnt >= 0); \
38
+ } while (0)
39
+
40
+
41
+ #define INCREASE_ACTIVE_COUNT(loop, handle) \
42
+ do { \
43
+ if ((handle)->activecnt++ == 0) { \
44
+ uv__handle_start((handle)); \
45
+ } \
46
+ assert((handle)->activecnt > 0); \
47
+ } while (0)
48
+
49
+
50
+ #define DECREASE_PENDING_REQ_COUNT(handle) \
51
+ do { \
52
+ assert(handle->reqs_pending > 0); \
53
+ handle->reqs_pending--; \
54
+ \
55
+ if (handle->flags & UV_HANDLE_CLOSING && \
56
+ handle->reqs_pending == 0) { \
57
+ uv_want_endgame(loop, (uv_handle_t*)handle); \
58
+ } \
59
+ } while (0)
60
+
61
+
62
+ #define uv__handle_close(handle) \
63
+ do { \
64
+ ngx_queue_remove(&(handle)->handle_queue); \
65
+ (handle)->flags |= UV_HANDLE_CLOSED; \
66
+ if ((handle)->close_cb) { \
67
+ (handle)->close_cb((uv_handle_t*)(handle)); \
68
+ } \
69
+ } while (0)
70
+
71
+
72
+ INLINE static void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
73
+ if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
74
+ handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
75
+
76
+ handle->endgame_next = loop->endgame_handles;
77
+ loop->endgame_handles = handle;
78
+ }
79
+ }
80
+
81
+
82
+ INLINE static void uv_process_endgames(uv_loop_t* loop) {
83
+ uv_handle_t* handle;
84
+
85
+ while (loop->endgame_handles) {
86
+ handle = loop->endgame_handles;
87
+ loop->endgame_handles = handle->endgame_next;
88
+
89
+ handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
90
+
91
+ switch (handle->type) {
92
+ case UV_TCP:
93
+ uv_tcp_endgame(loop, (uv_tcp_t*) handle);
94
+ break;
95
+
96
+ case UV_NAMED_PIPE:
97
+ uv_pipe_endgame(loop, (uv_pipe_t*) handle);
98
+ break;
99
+
100
+ case UV_TTY:
101
+ uv_tty_endgame(loop, (uv_tty_t*) handle);
102
+ break;
103
+
104
+ case UV_UDP:
105
+ uv_udp_endgame(loop, (uv_udp_t*) handle);
106
+ break;
107
+
108
+ case UV_POLL:
109
+ uv_poll_endgame(loop, (uv_poll_t*) handle);
110
+ break;
111
+
112
+ case UV_TIMER:
113
+ uv_timer_endgame(loop, (uv_timer_t*) handle);
114
+ break;
115
+
116
+ case UV_PREPARE:
117
+ case UV_CHECK:
118
+ case UV_IDLE:
119
+ uv_loop_watcher_endgame(loop, handle);
120
+ break;
121
+
122
+ case UV_ASYNC:
123
+ uv_async_endgame(loop, (uv_async_t*) handle);
124
+ break;
125
+
126
+ case UV_PROCESS:
127
+ uv_process_endgame(loop, (uv_process_t*) handle);
128
+ break;
129
+
130
+ case UV_FS_EVENT:
131
+ uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
132
+ break;
133
+
134
+ case UV_FS_POLL:
135
+ uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle);
136
+ break;
137
+
138
+ default:
139
+ assert(0);
140
+ break;
141
+ }
142
+ }
143
+ }
144
+
145
+ #endif /* UV_WIN_HANDLE_INL_H_ */
@@ -24,6 +24,7 @@
24
24
 
25
25
  #include "uv.h"
26
26
  #include "internal.h"
27
+ #include "handle-inl.h"
27
28
 
28
29
 
29
30
  uv_handle_type uv_guess_handle(uv_file file) {
@@ -56,28 +57,17 @@ uv_handle_type uv_guess_handle(uv_file file) {
56
57
  }
57
58
 
58
59
 
59
- int uv_is_active(uv_handle_t* handle) {
60
- switch (handle->type) {
61
- case UV_TIMER:
62
- case UV_IDLE:
63
- case UV_PREPARE:
64
- case UV_CHECK:
65
- return (handle->flags & UV_HANDLE_ACTIVE) ? 1 : 0;
66
-
67
- default:
68
- return 1;
69
- }
60
+ int uv_is_active(const uv_handle_t* handle) {
61
+ return (handle->flags & UV__HANDLE_ACTIVE) &&
62
+ !(handle->flags & UV_HANDLE_CLOSING);
70
63
  }
71
64
 
72
65
 
73
66
  void uv_close(uv_handle_t* handle, uv_close_cb cb) {
74
- uv_pipe_t* pipe;
75
- uv_udp_t* udp;
76
- uv_process_t* process;
77
-
78
67
  uv_loop_t* loop = handle->loop;
79
68
 
80
69
  if (handle->flags & UV_HANDLE_CLOSING) {
70
+ assert(0);
81
71
  return;
82
72
  }
83
73
 
@@ -87,16 +77,11 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
87
77
  /* Handle-specific close actions */
88
78
  switch (handle->type) {
89
79
  case UV_TCP:
90
- uv_tcp_close((uv_tcp_t*)handle);
80
+ uv_tcp_close(loop, (uv_tcp_t*)handle);
91
81
  return;
92
82
 
93
83
  case UV_NAMED_PIPE:
94
- pipe = (uv_pipe_t*)handle;
95
- pipe->flags &= ~(UV_HANDLE_READING | UV_HANDLE_LISTENING);
96
- close_pipe(pipe, NULL, NULL);
97
- if (pipe->reqs_pending == 0) {
98
- uv_want_endgame(loop, handle);
99
- }
84
+ uv_pipe_close(loop, (uv_pipe_t*) handle);
100
85
  return;
101
86
 
102
87
  case UV_TTY:
@@ -104,47 +89,53 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
104
89
  return;
105
90
 
106
91
  case UV_UDP:
107
- udp = (uv_udp_t*) handle;
108
- uv_udp_recv_stop(udp);
109
- closesocket(udp->socket);
110
- if (udp->reqs_pending == 0) {
111
- uv_want_endgame(loop, handle);
112
- }
92
+ uv_udp_close(loop, (uv_udp_t*) handle);
93
+ return;
94
+
95
+ case UV_POLL:
96
+ uv_poll_close(loop, (uv_poll_t*) handle);
113
97
  return;
114
98
 
115
99
  case UV_TIMER:
116
100
  uv_timer_stop((uv_timer_t*)handle);
101
+ uv__handle_start(handle);
117
102
  uv_want_endgame(loop, handle);
118
103
  return;
119
104
 
120
105
  case UV_PREPARE:
121
106
  uv_prepare_stop((uv_prepare_t*)handle);
107
+ uv__handle_start(handle);
122
108
  uv_want_endgame(loop, handle);
123
109
  return;
124
110
 
125
111
  case UV_CHECK:
126
112
  uv_check_stop((uv_check_t*)handle);
113
+ uv__handle_start(handle);
127
114
  uv_want_endgame(loop, handle);
128
115
  return;
129
116
 
130
117
  case UV_IDLE:
131
118
  uv_idle_stop((uv_idle_t*)handle);
119
+ uv__handle_start(handle);
132
120
  uv_want_endgame(loop, handle);
133
121
  return;
134
122
 
135
123
  case UV_ASYNC:
136
- if (!((uv_async_t*)handle)->async_sent) {
137
- uv_want_endgame(loop, handle);
138
- }
124
+ uv_async_close(loop, (uv_async_t*) handle);
139
125
  return;
140
126
 
141
127
  case UV_PROCESS:
142
- process = (uv_process_t*)handle;
143
- uv_process_close(loop, process);
128
+ uv_process_close(loop, (uv_process_t*) handle);
144
129
  return;
145
130
 
146
131
  case UV_FS_EVENT:
147
- uv_fs_event_close(loop, (uv_fs_event_t*)handle);
132
+ uv_fs_event_close(loop, (uv_fs_event_t*) handle);
133
+ return;
134
+
135
+ case UV_FS_POLL:
136
+ uv__fs_poll_close((uv_fs_poll_t*) handle);
137
+ uv__handle_start(handle);
138
+ uv_want_endgame(loop, handle);
148
139
  return;
149
140
 
150
141
  default:
@@ -154,72 +145,6 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
154
145
  }
155
146
 
156
147
 
157
- int uv_is_closing(uv_handle_t* handle) {
148
+ int uv_is_closing(const uv_handle_t* handle) {
158
149
  return handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED);
159
150
  }
160
-
161
-
162
- void uv_want_endgame(uv_loop_t* loop, uv_handle_t* handle) {
163
- if (!(handle->flags & UV_HANDLE_ENDGAME_QUEUED)) {
164
- handle->flags |= UV_HANDLE_ENDGAME_QUEUED;
165
-
166
- handle->endgame_next = loop->endgame_handles;
167
- loop->endgame_handles = handle;
168
- }
169
- }
170
-
171
-
172
- void uv_process_endgames(uv_loop_t* loop) {
173
- uv_handle_t* handle;
174
-
175
- while (loop->endgame_handles && loop->refs > 0) {
176
- handle = loop->endgame_handles;
177
- loop->endgame_handles = handle->endgame_next;
178
-
179
- handle->flags &= ~UV_HANDLE_ENDGAME_QUEUED;
180
-
181
- switch (handle->type) {
182
- case UV_TCP:
183
- uv_tcp_endgame(loop, (uv_tcp_t*) handle);
184
- break;
185
-
186
- case UV_NAMED_PIPE:
187
- uv_pipe_endgame(loop, (uv_pipe_t*) handle);
188
- break;
189
-
190
- case UV_TTY:
191
- uv_tty_endgame(loop, (uv_tty_t*) handle);
192
- break;
193
-
194
- case UV_UDP:
195
- uv_udp_endgame(loop, (uv_udp_t*) handle);
196
- break;
197
-
198
- case UV_TIMER:
199
- uv_timer_endgame(loop, (uv_timer_t*) handle);
200
- break;
201
-
202
- case UV_PREPARE:
203
- case UV_CHECK:
204
- case UV_IDLE:
205
- uv_loop_watcher_endgame(loop, handle);
206
- break;
207
-
208
- case UV_ASYNC:
209
- uv_async_endgame(loop, (uv_async_t*) handle);
210
- break;
211
-
212
- case UV_PROCESS:
213
- uv_process_endgame(loop, (uv_process_t*) handle);
214
- break;
215
-
216
- case UV_FS_EVENT:
217
- uv_fs_event_endgame(loop, (uv_fs_event_t*) handle);
218
- break;
219
-
220
- default:
221
- assert(0);
222
- break;
223
- }
224
- }
225
- }