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
@@ -20,6 +20,8 @@
20
20
  */
21
21
 
22
22
  BENCHMARK_DECLARE (sizes)
23
+ BENCHMARK_DECLARE (loop_count)
24
+ BENCHMARK_DECLARE (loop_count_timed)
23
25
  BENCHMARK_DECLARE (ping_pongs)
24
26
  BENCHMARK_DECLARE (tcp_write_batch)
25
27
  BENCHMARK_DECLARE (tcp4_pound_100)
@@ -42,8 +44,10 @@ BENCHMARK_DECLARE (udp_packet_storm_100v1000)
42
44
  BENCHMARK_DECLARE (udp_packet_storm_1000v1000)
43
45
  BENCHMARK_DECLARE (gethostbyname)
44
46
  BENCHMARK_DECLARE (getaddrinfo)
47
+ BENCHMARK_DECLARE (fs_stat)
45
48
  BENCHMARK_DECLARE (spawn)
46
49
  BENCHMARK_DECLARE (thread_create)
50
+ BENCHMARK_DECLARE (million_timers)
47
51
  HELPER_DECLARE (tcp4_blackhole_server)
48
52
  HELPER_DECLARE (tcp_pump_server)
49
53
  HELPER_DECLARE (pipe_pump_server)
@@ -53,6 +57,8 @@ HELPER_DECLARE (dns_server)
53
57
 
54
58
  TASK_LIST_START
55
59
  BENCHMARK_ENTRY (sizes)
60
+ BENCHMARK_ENTRY (loop_count)
61
+ BENCHMARK_ENTRY (loop_count_timed)
56
62
 
57
63
  BENCHMARK_ENTRY (ping_pongs)
58
64
  BENCHMARK_HELPER (ping_pongs, tcp4_echo_server)
@@ -100,6 +106,9 @@ TASK_LIST_START
100
106
 
101
107
  BENCHMARK_ENTRY (getaddrinfo)
102
108
 
109
+ BENCHMARK_ENTRY (fs_stat)
110
+
103
111
  BENCHMARK_ENTRY (spawn)
104
112
  BENCHMARK_ENTRY (thread_create)
113
+ BENCHMARK_ENTRY (million_timers)
105
114
  TASK_LIST_END
@@ -1,4 +1,5 @@
1
1
  /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
2
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
3
4
  * of this software and associated documentation files (the "Software"), to
4
5
  * deal in the Software without restriction, including without limitation the
@@ -18,62 +19,70 @@
18
19
  * IN THE SOFTWARE.
19
20
  */
20
21
 
22
+ #include "task.h"
21
23
  #include "uv.h"
22
- #include "internal.h"
23
24
 
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+
28
+ #define NUM_TICKS (2 * 1000 * 1000)
29
+
30
+ static unsigned long ticks;
31
+ static uv_idle_t idle_handle;
32
+ static uv_timer_t timer_handle;
24
33
 
25
- static void uv__prepare(EV_P_ ev_prepare* w, int revents) {
26
- uv_prepare_t* prepare = container_of(w, uv_prepare_t, prepare_watcher);
27
34
 
28
- if (prepare->prepare_cb) {
29
- prepare->prepare_cb(prepare, 0);
30
- }
35
+ static void idle_cb(uv_idle_t* handle, int status) {
36
+ if (++ticks == NUM_TICKS)
37
+ uv_idle_stop(handle);
31
38
  }
32
39
 
33
40
 
34
- int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) {
35
- uv__handle_init(loop, (uv_handle_t*)prepare, UV_PREPARE);
36
- loop->counters.prepare_init++;
41
+ static void idle2_cb(uv_idle_t* handle, int status) {
42
+ ticks++;
43
+ }
37
44
 
38
- ev_prepare_init(&prepare->prepare_watcher, uv__prepare);
39
- prepare->prepare_cb = NULL;
40
45
 
41
- return 0;
46
+ static void timer_cb(uv_timer_t* handle, int status) {
47
+ uv_idle_stop(&idle_handle);
48
+ uv_timer_stop(&timer_handle);
42
49
  }
43
50
 
44
51
 
45
- int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) {
46
- int was_active = ev_is_active(&prepare->prepare_watcher);
52
+ BENCHMARK_IMPL(loop_count) {
53
+ uv_loop_t* loop = uv_default_loop();
54
+ uint64_t ns;
55
+
56
+ uv_idle_init(loop, &idle_handle);
57
+ uv_idle_start(&idle_handle, idle_cb);
47
58
 
48
- prepare->prepare_cb = cb;
59
+ ns = uv_hrtime();
60
+ uv_run(loop);
61
+ ns = uv_hrtime() - ns;
49
62
 
50
- ev_prepare_start(prepare->loop->ev, &prepare->prepare_watcher);
63
+ ASSERT(ticks == NUM_TICKS);
51
64
 
52
- if (!was_active) {
53
- ev_unref(prepare->loop->ev);
54
- }
65
+ LOGF("loop_count: %d ticks in %.2fs (%.0f/s)\n",
66
+ NUM_TICKS,
67
+ ns / 1e9,
68
+ NUM_TICKS / (ns / 1e9));
55
69
 
56
70
  return 0;
57
71
  }
58
72
 
59
73
 
60
- int uv_prepare_stop(uv_prepare_t* prepare) {
61
- int was_active = ev_is_active(&prepare->prepare_watcher);
74
+ BENCHMARK_IMPL(loop_count_timed) {
75
+ uv_loop_t* loop = uv_default_loop();
62
76
 
63
- ev_prepare_stop(prepare->loop->ev, &prepare->prepare_watcher);
77
+ uv_idle_init(loop, &idle_handle);
78
+ uv_idle_start(&idle_handle, idle2_cb);
64
79
 
65
- if (was_active) {
66
- ev_ref(prepare->loop->ev);
67
- }
68
- return 0;
69
- }
80
+ uv_timer_init(loop, &timer_handle);
81
+ uv_timer_start(&timer_handle, timer_cb, 5000, 0);
70
82
 
83
+ uv_run(loop);
71
84
 
72
- int uv__prepare_active(const uv_prepare_t* handle) {
73
- return ev_is_active(&handle->prepare_watcher);
74
- }
85
+ LOGF("loop_count: %lu ticks (%.0f ticks/s)\n", ticks, ticks / 5.0);
75
86
 
76
-
77
- void uv__prepare_close(uv_prepare_t* handle) {
78
- uv_prepare_stop(handle);
87
+ return 0;
79
88
  }
@@ -0,0 +1,65 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ *
3
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ * of this software and associated documentation files (the "Software"), to
5
+ * deal in the Software without restriction, including without limitation the
6
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ * sell copies of the Software, and to permit persons to whom the Software is
8
+ * furnished to do so, subject to the following conditions:
9
+ *
10
+ * The above copyright notice and this permission notice shall be included in
11
+ * all copies or substantial portions of the Software.
12
+ *
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ * IN THE SOFTWARE.
20
+ */
21
+
22
+ #include "task.h"
23
+ #include "uv.h"
24
+
25
+ #define NUM_TIMERS (1000 * 1000)
26
+
27
+ static int timer_cb_called;
28
+
29
+
30
+ static void timer_cb(uv_timer_t* handle, int status) {
31
+ timer_cb_called++;
32
+ }
33
+
34
+
35
+ BENCHMARK_IMPL(million_timers) {
36
+ uv_timer_t* timers;
37
+ uv_loop_t* loop;
38
+ uint64_t before;
39
+ uint64_t after;
40
+ int timeout;
41
+ int i;
42
+
43
+ timers = malloc(NUM_TIMERS * sizeof(timers[0]));
44
+ ASSERT(timers != NULL);
45
+
46
+ loop = uv_default_loop();
47
+ timeout = 0;
48
+
49
+ for (i = 0; i < NUM_TIMERS; i++) {
50
+ if (i % 1000 == 0) timeout++;
51
+ ASSERT(0 == uv_timer_init(loop, timers + i));
52
+ ASSERT(0 == uv_timer_start(timers + i, timer_cb, timeout, 0));
53
+ }
54
+
55
+ before = uv_hrtime();
56
+ ASSERT(0 == uv_run(loop));
57
+ after = uv_hrtime();
58
+
59
+ ASSERT(timer_cb_called == NUM_TIMERS);
60
+ free(timers);
61
+
62
+ LOGF("%.2f seconds\n", (after - before) / 1e9);
63
+
64
+ return 0;
65
+ }
@@ -26,7 +26,7 @@
26
26
  #define MAX_CONNS 1000
27
27
 
28
28
  #undef NANOSEC
29
- #define NANOSEC ((uint64_t)10e8)
29
+ #define NANOSEC ((uint64_t) 1e9)
30
30
 
31
31
  #undef DEBUG
32
32
  #define DEBUG 0
@@ -27,6 +27,7 @@ BENCHMARK_IMPL(sizes) {
27
27
  LOGF("uv_shutdown_t: %u bytes\n", (unsigned int) sizeof(uv_shutdown_t));
28
28
  LOGF("uv_write_t: %u bytes\n", (unsigned int) sizeof(uv_write_t));
29
29
  LOGF("uv_connect_t: %u bytes\n", (unsigned int) sizeof(uv_connect_t));
30
+ LOGF("uv_udp_send_t: %u bytes\n", (unsigned int) sizeof(uv_udp_send_t));
30
31
  LOGF("uv_tcp_t: %u bytes\n", (unsigned int) sizeof(uv_tcp_t));
31
32
  LOGF("uv_pipe_t: %u bytes\n", (unsigned int) sizeof(uv_pipe_t));
32
33
  LOGF("uv_tty_t: %u bytes\n", (unsigned int) sizeof(uv_tty_t));
@@ -36,5 +37,6 @@ BENCHMARK_IMPL(sizes) {
36
37
  LOGF("uv_async_t: %u bytes\n", (unsigned int) sizeof(uv_async_t));
37
38
  LOGF("uv_timer_t: %u bytes\n", (unsigned int) sizeof(uv_timer_t));
38
39
  LOGF("uv_process_t: %u bytes\n", (unsigned int) sizeof(uv_process_t));
40
+ LOGF("uv_poll_t: %u bytes\n", (unsigned int) sizeof(uv_poll_t));
39
41
  return 0;
40
42
  }
@@ -101,6 +101,7 @@ void on_read(uv_stream_t* pipe, ssize_t nread, uv_buf_t buf) {
101
101
 
102
102
 
103
103
  static void spawn() {
104
+ uv_stdio_container_t stdio[2];
104
105
  int r;
105
106
 
106
107
  ASSERT(process_open == 0);
@@ -114,7 +115,12 @@ static void spawn() {
114
115
  options.exit_cb = exit_cb;
115
116
 
116
117
  uv_pipe_init(loop, &out, 0);
117
- options.stdout_stream = &out;
118
+
119
+ options.stdio = stdio;
120
+ options.stdio_count = 2;
121
+ options.stdio[0].flags = UV_IGNORE;
122
+ options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
123
+ options.stdio[1].data.stream = (uv_stream_t*)&out;
118
124
 
119
125
  r = uv_spawn(loop, &process, options);
120
126
  ASSERT(r == 0);
@@ -144,7 +144,7 @@ static int do_packet_storm(int n_senders, int n_receivers) {
144
144
  ASSERT(r == 0);
145
145
 
146
146
  /* Timer should not keep loop alive. */
147
- uv_unref(loop);
147
+ uv_unref((uv_handle_t*)&timeout);
148
148
 
149
149
  for (i = 0; i < n_receivers; i++) {
150
150
  struct sockaddr_in addr;
@@ -298,6 +298,14 @@ static int udp4_echo_start(int port) {
298
298
  static int pipe_echo_start(char* pipeName) {
299
299
  int r;
300
300
 
301
+ #ifndef _WIN32
302
+ {
303
+ uv_fs_t req;
304
+ uv_fs_unlink(uv_default_loop(), &req, pipeName, NULL);
305
+ uv_fs_req_cleanup(&req);
306
+ }
307
+ #endif
308
+
301
309
  server = (uv_handle_t*)&pipeServer;
302
310
  serverType = PIPE;
303
311
 
@@ -22,6 +22,12 @@
22
22
  #include <stdio.h>
23
23
  #include <string.h>
24
24
 
25
+ #ifdef _WIN32
26
+ # include <io.h>
27
+ #else
28
+ # include <unistd.h>
29
+ #endif
30
+
25
31
  #include "uv.h"
26
32
  #include "runner.h"
27
33
  #include "task.h"
@@ -104,5 +110,29 @@ static int maybe_run_test(int argc, char **argv) {
104
110
  while (1) uv_sleep(10000);
105
111
  }
106
112
 
113
+ if (strcmp(argv[1], "spawn_helper5") == 0) {
114
+ const char* out = "fourth stdio!\n\0";
115
+ #ifdef _WIN32
116
+ DWORD bytes;
117
+ WriteFile((HANDLE) _get_osfhandle(3), out, strlen(out), &bytes, NULL);
118
+ #else
119
+ write(3, out, strlen(out));
120
+ fsync(3);
121
+ #endif
122
+ return 1;
123
+ }
124
+
125
+ if (strcmp(argv[1], "spawn_helper6") == 0) {
126
+ int r;
127
+
128
+ r = fprintf(stdout, "hello world\n");
129
+ ASSERT(r > 0);
130
+
131
+ r = fprintf(stderr, "hello errworld\n");
132
+ ASSERT(r > 0);
133
+
134
+ return 1;
135
+ }
136
+
107
137
  return run_test(argv[1], TEST_TIMEOUT, 0);
108
138
  }
@@ -40,6 +40,11 @@
40
40
 
41
41
  /* Do platform-specific initialization. */
42
42
  void platform_init(int argc, char **argv) {
43
+ /* Running the tests as root is not smart - don't do it. */
44
+ if (getuid() == 0) {
45
+ fprintf(stderr, "Running the tests as root is not safe.\n");
46
+ exit(1);
47
+ }
43
48
  /* Disable stdio output buffering. */
44
49
  setvbuf(stdout, NULL, _IONBF, 0);
45
50
  setvbuf(stderr, NULL, _IONBF, 0);
@@ -100,13 +105,12 @@ typedef struct {
100
105
  static void* dowait(void* data) {
101
106
  dowait_args* args = data;
102
107
 
103
- int i, status, r;
108
+ int i, r;
104
109
  process_info_t* p;
105
110
 
106
111
  for (i = 0; i < args->n; i++) {
107
112
  p = (process_info_t*)(args->vec + i * sizeof(process_info_t));
108
113
  if (p->terminated) continue;
109
- status = 0;
110
114
  r = waitpid(p->pid, &p->status, 0);
111
115
  if (r < 0) {
112
116
  perror("waitpid");
@@ -285,30 +289,6 @@ void rewind_cursor() {
285
289
  }
286
290
 
287
291
 
288
- typedef void* (*uv_thread_cb)(void* arg);
289
-
290
-
291
- uintptr_t uv_create_thread(void (*entry)(void* arg), void* arg) {
292
- pthread_t t;
293
- uv_thread_cb cb = (uv_thread_cb)entry;
294
- int r = pthread_create(&t, NULL, cb, arg);
295
-
296
- if (r) {
297
- return 0;
298
- }
299
-
300
- return (uintptr_t)t;
301
- }
302
-
303
-
304
- /* Wait for a thread to terminate. Should return 0 if the thread ended, -1 on
305
- * error.
306
- */
307
- int uv_wait_thread(uintptr_t thread_id) {
308
- return pthread_join((pthread_t)thread_id, NULL);
309
- }
310
-
311
-
312
292
  /* Pause the calling thread for a number of milliseconds. */
313
293
  void uv_sleep(int msec) {
314
294
  usleep(msec * 1000);
@@ -19,6 +19,7 @@
19
19
  * IN THE SOFTWARE.
20
20
  */
21
21
 
22
+ #include <fcntl.h>
22
23
  #include <io.h>
23
24
  #include <malloc.h>
24
25
  #include <stdio.h>
@@ -44,6 +45,10 @@ void platform_init(int argc, char **argv) {
44
45
  SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX |
45
46
  SEM_NOOPENFILEERRORBOX);
46
47
 
48
+ _setmode(0, _O_BINARY);
49
+ _setmode(1, _O_BINARY);
50
+ _setmode(2, _O_BINARY);
51
+
47
52
  /* Disable stdio output buffering. */
48
53
  setvbuf(stdout, NULL, _IONBF, 0);
49
54
  setvbuf(stderr, NULL, _IONBF, 0);
@@ -274,69 +279,6 @@ void rewind_cursor() {
274
279
  }
275
280
 
276
281
 
277
- typedef struct {
278
- void (*entry)(void* arg);
279
- void* arg;
280
- } thread_info_t;
281
-
282
-
283
- static unsigned __stdcall create_thread_helper(void* info) {
284
- /* Copy thread info locally, then free it */
285
- void (*entry)(void* arg) = ((thread_info_t*) info)->entry;
286
- void* arg = ((thread_info_t*) info)->arg;
287
-
288
- free(info);
289
-
290
- /* Run the actual thread proc */
291
- entry(arg);
292
-
293
- /* Finalize */
294
- _endthreadex(0);
295
- return 0;
296
- }
297
-
298
-
299
- /* Create a thread. Returns the thread identifier, or 0 on failure. */
300
- uintptr_t uv_create_thread(void (*entry)(void* arg), void* arg) {
301
- uintptr_t result;
302
- thread_info_t* info;
303
-
304
- info = (thread_info_t*) malloc(sizeof *info);
305
- if (info == NULL) {
306
- return 0;
307
- }
308
-
309
- info->entry = entry;
310
- info->arg = arg;
311
-
312
- result = _beginthreadex(NULL,
313
- 0,
314
- &create_thread_helper,
315
- (void*) info,
316
- 0,
317
- NULL);
318
-
319
- if (result == 0) {
320
- free(info);
321
- return 0;
322
- }
323
-
324
- return result;
325
- }
326
-
327
-
328
- /* Wait for a thread to terminate. Should return 0 if the thread ended, -1 on
329
- * error.
330
- */
331
- int uv_wait_thread(uintptr_t thread_id) {
332
- if (WaitForSingleObject((HANDLE)thread_id, INFINITE) != WAIT_OBJECT_0) {
333
- return -1;
334
- }
335
-
336
- return 0;
337
- }
338
-
339
-
340
282
  /* Pause the calling thread for a number of milliseconds. */
341
283
  void uv_sleep(int msec) {
342
284
  Sleep(msec);