asyncengine 0.0.1.testing

Sign up to get free protection for your applications and to get access to all the features.
Files changed (317) hide show
  1. data/README.markdown +0 -0
  2. data/asyncengine.gemspec +26 -0
  3. data/ext/asyncengine_ext/asyncengine_ruby.c +82 -0
  4. data/ext/asyncengine_ext/extconf.rb +47 -0
  5. data/ext/asyncengine_ext/libuv/AUTHORS +45 -0
  6. data/ext/asyncengine_ext/libuv/LICENSE +42 -0
  7. data/ext/asyncengine_ext/libuv/Makefile +119 -0
  8. data/ext/asyncengine_ext/libuv/README.md +88 -0
  9. data/ext/asyncengine_ext/libuv/build/gcc_version.py +20 -0
  10. data/ext/asyncengine_ext/libuv/common.gypi +176 -0
  11. data/ext/asyncengine_ext/libuv/config-mingw.mk +61 -0
  12. data/ext/asyncengine_ext/libuv/config-unix.mk +173 -0
  13. data/ext/asyncengine_ext/libuv/gyp_uv +60 -0
  14. data/ext/asyncengine_ext/libuv/include/ares.h +591 -0
  15. data/ext/asyncengine_ext/libuv/include/ares_version.h +24 -0
  16. data/ext/asyncengine_ext/libuv/include/uv-private/eio.h +403 -0
  17. data/ext/asyncengine_ext/libuv/include/uv-private/ev.h +838 -0
  18. data/ext/asyncengine_ext/libuv/include/uv-private/ngx-queue.h +106 -0
  19. data/ext/asyncengine_ext/libuv/include/uv-private/tree.h +768 -0
  20. data/ext/asyncengine_ext/libuv/include/uv-private/uv-unix.h +256 -0
  21. data/ext/asyncengine_ext/libuv/include/uv-private/uv-win.h +458 -0
  22. data/ext/asyncengine_ext/libuv/include/uv.h +1556 -0
  23. data/ext/asyncengine_ext/libuv/src/ares/AUTHORS +37 -0
  24. data/ext/asyncengine_ext/libuv/src/ares/CHANGES +1218 -0
  25. data/ext/asyncengine_ext/libuv/src/ares/CMakeLists.txt +22 -0
  26. data/ext/asyncengine_ext/libuv/src/ares/NEWS +21 -0
  27. data/ext/asyncengine_ext/libuv/src/ares/README +60 -0
  28. data/ext/asyncengine_ext/libuv/src/ares/README.cares +13 -0
  29. data/ext/asyncengine_ext/libuv/src/ares/README.msvc +142 -0
  30. data/ext/asyncengine_ext/libuv/src/ares/README.node +21 -0
  31. data/ext/asyncengine_ext/libuv/src/ares/RELEASE-NOTES +26 -0
  32. data/ext/asyncengine_ext/libuv/src/ares/TODO +23 -0
  33. data/ext/asyncengine_ext/libuv/src/ares/ares__close_sockets.c +66 -0
  34. data/ext/asyncengine_ext/libuv/src/ares/ares__get_hostent.c +263 -0
  35. data/ext/asyncengine_ext/libuv/src/ares/ares__read_line.c +71 -0
  36. data/ext/asyncengine_ext/libuv/src/ares/ares__timeval.c +111 -0
  37. data/ext/asyncengine_ext/libuv/src/ares/ares_cancel.c +63 -0
  38. data/ext/asyncengine_ext/libuv/src/ares/ares_data.c +190 -0
  39. data/ext/asyncengine_ext/libuv/src/ares/ares_data.h +65 -0
  40. data/ext/asyncengine_ext/libuv/src/ares/ares_destroy.c +105 -0
  41. data/ext/asyncengine_ext/libuv/src/ares/ares_dns.h +90 -0
  42. data/ext/asyncengine_ext/libuv/src/ares/ares_expand_name.c +200 -0
  43. data/ext/asyncengine_ext/libuv/src/ares/ares_expand_string.c +75 -0
  44. data/ext/asyncengine_ext/libuv/src/ares/ares_fds.c +63 -0
  45. data/ext/asyncengine_ext/libuv/src/ares/ares_free_hostent.c +42 -0
  46. data/ext/asyncengine_ext/libuv/src/ares/ares_free_string.c +25 -0
  47. data/ext/asyncengine_ext/libuv/src/ares/ares_getenv.c +30 -0
  48. data/ext/asyncengine_ext/libuv/src/ares/ares_getenv.h +26 -0
  49. data/ext/asyncengine_ext/libuv/src/ares/ares_gethostbyaddr.c +301 -0
  50. data/ext/asyncengine_ext/libuv/src/ares/ares_gethostbyname.c +523 -0
  51. data/ext/asyncengine_ext/libuv/src/ares/ares_getnameinfo.c +427 -0
  52. data/ext/asyncengine_ext/libuv/src/ares/ares_getopt.c +122 -0
  53. data/ext/asyncengine_ext/libuv/src/ares/ares_getopt.h +53 -0
  54. data/ext/asyncengine_ext/libuv/src/ares/ares_getsock.c +72 -0
  55. data/ext/asyncengine_ext/libuv/src/ares/ares_init.c +1809 -0
  56. data/ext/asyncengine_ext/libuv/src/ares/ares_iphlpapi.h +221 -0
  57. data/ext/asyncengine_ext/libuv/src/ares/ares_ipv6.h +78 -0
  58. data/ext/asyncengine_ext/libuv/src/ares/ares_library_init.c +142 -0
  59. data/ext/asyncengine_ext/libuv/src/ares/ares_library_init.h +42 -0
  60. data/ext/asyncengine_ext/libuv/src/ares/ares_llist.c +86 -0
  61. data/ext/asyncengine_ext/libuv/src/ares/ares_llist.h +42 -0
  62. data/ext/asyncengine_ext/libuv/src/ares/ares_mkquery.c +195 -0
  63. data/ext/asyncengine_ext/libuv/src/ares/ares_nowarn.c +181 -0
  64. data/ext/asyncengine_ext/libuv/src/ares/ares_nowarn.h +55 -0
  65. data/ext/asyncengine_ext/libuv/src/ares/ares_options.c +248 -0
  66. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_a_reply.c +263 -0
  67. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_aaaa_reply.c +259 -0
  68. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_mx_reply.c +170 -0
  69. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_ns_reply.c +182 -0
  70. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_ptr_reply.c +217 -0
  71. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_srv_reply.c +179 -0
  72. data/ext/asyncengine_ext/libuv/src/ares/ares_parse_txt_reply.c +201 -0
  73. data/ext/asyncengine_ext/libuv/src/ares/ares_platform.c +11035 -0
  74. data/ext/asyncengine_ext/libuv/src/ares/ares_platform.h +43 -0
  75. data/ext/asyncengine_ext/libuv/src/ares/ares_private.h +355 -0
  76. data/ext/asyncengine_ext/libuv/src/ares/ares_process.c +1295 -0
  77. data/ext/asyncengine_ext/libuv/src/ares/ares_query.c +183 -0
  78. data/ext/asyncengine_ext/libuv/src/ares/ares_rules.h +144 -0
  79. data/ext/asyncengine_ext/libuv/src/ares/ares_search.c +321 -0
  80. data/ext/asyncengine_ext/libuv/src/ares/ares_send.c +134 -0
  81. data/ext/asyncengine_ext/libuv/src/ares/ares_setup.h +199 -0
  82. data/ext/asyncengine_ext/libuv/src/ares/ares_strcasecmp.c +66 -0
  83. data/ext/asyncengine_ext/libuv/src/ares/ares_strcasecmp.h +30 -0
  84. data/ext/asyncengine_ext/libuv/src/ares/ares_strdup.c +42 -0
  85. data/ext/asyncengine_ext/libuv/src/ares/ares_strdup.h +26 -0
  86. data/ext/asyncengine_ext/libuv/src/ares/ares_strerror.c +56 -0
  87. data/ext/asyncengine_ext/libuv/src/ares/ares_timeout.c +80 -0
  88. data/ext/asyncengine_ext/libuv/src/ares/ares_version.c +11 -0
  89. data/ext/asyncengine_ext/libuv/src/ares/ares_writev.c +79 -0
  90. data/ext/asyncengine_ext/libuv/src/ares/ares_writev.h +36 -0
  91. data/ext/asyncengine_ext/libuv/src/ares/bitncmp.c +59 -0
  92. data/ext/asyncengine_ext/libuv/src/ares/bitncmp.h +26 -0
  93. data/ext/asyncengine_ext/libuv/src/ares/config_cygwin/ares_config.h +512 -0
  94. data/ext/asyncengine_ext/libuv/src/ares/config_darwin/ares_config.h +512 -0
  95. data/ext/asyncengine_ext/libuv/src/ares/config_freebsd/ares_config.h +512 -0
  96. data/ext/asyncengine_ext/libuv/src/ares/config_linux/ares_config.h +512 -0
  97. data/ext/asyncengine_ext/libuv/src/ares/config_netbsd/ares_config.h +512 -0
  98. data/ext/asyncengine_ext/libuv/src/ares/config_openbsd/ares_config.h +512 -0
  99. data/ext/asyncengine_ext/libuv/src/ares/config_sunos/ares_config.h +512 -0
  100. data/ext/asyncengine_ext/libuv/src/ares/config_win32/ares_config.h +369 -0
  101. data/ext/asyncengine_ext/libuv/src/ares/get_ver.awk +35 -0
  102. data/ext/asyncengine_ext/libuv/src/ares/inet_net_pton.c +451 -0
  103. data/ext/asyncengine_ext/libuv/src/ares/inet_net_pton.h +31 -0
  104. data/ext/asyncengine_ext/libuv/src/ares/inet_ntop.c +208 -0
  105. data/ext/asyncengine_ext/libuv/src/ares/inet_ntop.h +26 -0
  106. data/ext/asyncengine_ext/libuv/src/ares/nameser.h +203 -0
  107. data/ext/asyncengine_ext/libuv/src/ares/setup_once.h +504 -0
  108. data/ext/asyncengine_ext/libuv/src/ares/windows_port.c +22 -0
  109. data/ext/asyncengine_ext/libuv/src/unix/async.c +58 -0
  110. data/ext/asyncengine_ext/libuv/src/unix/cares.c +194 -0
  111. data/ext/asyncengine_ext/libuv/src/unix/check.c +80 -0
  112. data/ext/asyncengine_ext/libuv/src/unix/core.c +588 -0
  113. data/ext/asyncengine_ext/libuv/src/unix/cygwin.c +84 -0
  114. data/ext/asyncengine_ext/libuv/src/unix/darwin.c +341 -0
  115. data/ext/asyncengine_ext/libuv/src/unix/dl.c +91 -0
  116. data/ext/asyncengine_ext/libuv/src/unix/eio/Changes +63 -0
  117. data/ext/asyncengine_ext/libuv/src/unix/eio/LICENSE +36 -0
  118. data/ext/asyncengine_ext/libuv/src/unix/eio/Makefile.am +15 -0
  119. data/ext/asyncengine_ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
  120. data/ext/asyncengine_ext/libuv/src/unix/eio/autogen.sh +3 -0
  121. data/ext/asyncengine_ext/libuv/src/unix/eio/config.h.in +86 -0
  122. data/ext/asyncengine_ext/libuv/src/unix/eio/config_cygwin.h +80 -0
  123. data/ext/asyncengine_ext/libuv/src/unix/eio/config_darwin.h +141 -0
  124. data/ext/asyncengine_ext/libuv/src/unix/eio/config_freebsd.h +81 -0
  125. data/ext/asyncengine_ext/libuv/src/unix/eio/config_linux.h +94 -0
  126. data/ext/asyncengine_ext/libuv/src/unix/eio/config_netbsd.h +81 -0
  127. data/ext/asyncengine_ext/libuv/src/unix/eio/config_openbsd.h +137 -0
  128. data/ext/asyncengine_ext/libuv/src/unix/eio/config_sunos.h +84 -0
  129. data/ext/asyncengine_ext/libuv/src/unix/eio/configure.ac +22 -0
  130. data/ext/asyncengine_ext/libuv/src/unix/eio/demo.c +194 -0
  131. data/ext/asyncengine_ext/libuv/src/unix/eio/ecb.h +370 -0
  132. data/ext/asyncengine_ext/libuv/src/unix/eio/eio.3 +3428 -0
  133. data/ext/asyncengine_ext/libuv/src/unix/eio/eio.c +2593 -0
  134. data/ext/asyncengine_ext/libuv/src/unix/eio/eio.pod +969 -0
  135. data/ext/asyncengine_ext/libuv/src/unix/eio/libeio.m4 +195 -0
  136. data/ext/asyncengine_ext/libuv/src/unix/eio/xthread.h +164 -0
  137. data/ext/asyncengine_ext/libuv/src/unix/error.c +98 -0
  138. data/ext/asyncengine_ext/libuv/src/unix/ev/Changes +388 -0
  139. data/ext/asyncengine_ext/libuv/src/unix/ev/LICENSE +36 -0
  140. data/ext/asyncengine_ext/libuv/src/unix/ev/Makefile.am +18 -0
  141. data/ext/asyncengine_ext/libuv/src/unix/ev/Makefile.in +771 -0
  142. data/ext/asyncengine_ext/libuv/src/unix/ev/README +58 -0
  143. data/ext/asyncengine_ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
  144. data/ext/asyncengine_ext/libuv/src/unix/ev/autogen.sh +6 -0
  145. data/ext/asyncengine_ext/libuv/src/unix/ev/config.guess +1526 -0
  146. data/ext/asyncengine_ext/libuv/src/unix/ev/config.h.in +125 -0
  147. data/ext/asyncengine_ext/libuv/src/unix/ev/config.sub +1658 -0
  148. data/ext/asyncengine_ext/libuv/src/unix/ev/config_cygwin.h +123 -0
  149. data/ext/asyncengine_ext/libuv/src/unix/ev/config_darwin.h +122 -0
  150. data/ext/asyncengine_ext/libuv/src/unix/ev/config_freebsd.h +120 -0
  151. data/ext/asyncengine_ext/libuv/src/unix/ev/config_linux.h +141 -0
  152. data/ext/asyncengine_ext/libuv/src/unix/ev/config_netbsd.h +120 -0
  153. data/ext/asyncengine_ext/libuv/src/unix/ev/config_openbsd.h +126 -0
  154. data/ext/asyncengine_ext/libuv/src/unix/ev/config_sunos.h +122 -0
  155. data/ext/asyncengine_ext/libuv/src/unix/ev/configure +13037 -0
  156. data/ext/asyncengine_ext/libuv/src/unix/ev/configure.ac +18 -0
  157. data/ext/asyncengine_ext/libuv/src/unix/ev/depcomp +630 -0
  158. data/ext/asyncengine_ext/libuv/src/unix/ev/ev++.h +816 -0
  159. data/ext/asyncengine_ext/libuv/src/unix/ev/ev.3 +5311 -0
  160. data/ext/asyncengine_ext/libuv/src/unix/ev/ev.c +3921 -0
  161. data/ext/asyncengine_ext/libuv/src/unix/ev/ev.pod +5243 -0
  162. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_epoll.c +266 -0
  163. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
  164. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_poll.c +148 -0
  165. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_port.c +179 -0
  166. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_select.c +310 -0
  167. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_vars.h +203 -0
  168. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_win32.c +153 -0
  169. data/ext/asyncengine_ext/libuv/src/unix/ev/ev_wrap.h +196 -0
  170. data/ext/asyncengine_ext/libuv/src/unix/ev/event.c +402 -0
  171. data/ext/asyncengine_ext/libuv/src/unix/ev/event.h +170 -0
  172. data/ext/asyncengine_ext/libuv/src/unix/ev/install-sh +294 -0
  173. data/ext/asyncengine_ext/libuv/src/unix/ev/libev.m4 +39 -0
  174. data/ext/asyncengine_ext/libuv/src/unix/ev/ltmain.sh +8413 -0
  175. data/ext/asyncengine_ext/libuv/src/unix/ev/missing +336 -0
  176. data/ext/asyncengine_ext/libuv/src/unix/ev/mkinstalldirs +111 -0
  177. data/ext/asyncengine_ext/libuv/src/unix/freebsd.c +312 -0
  178. data/ext/asyncengine_ext/libuv/src/unix/fs.c +707 -0
  179. data/ext/asyncengine_ext/libuv/src/unix/idle.c +79 -0
  180. data/ext/asyncengine_ext/libuv/src/unix/internal.h +161 -0
  181. data/ext/asyncengine_ext/libuv/src/unix/kqueue.c +127 -0
  182. data/ext/asyncengine_ext/libuv/src/unix/linux/core.c +474 -0
  183. data/ext/asyncengine_ext/libuv/src/unix/linux/inotify.c +211 -0
  184. data/ext/asyncengine_ext/libuv/src/unix/linux/syscalls.c +230 -0
  185. data/ext/asyncengine_ext/libuv/src/unix/linux/syscalls.h +87 -0
  186. data/ext/asyncengine_ext/libuv/src/unix/loop.c +58 -0
  187. data/ext/asyncengine_ext/libuv/src/unix/netbsd.c +108 -0
  188. data/ext/asyncengine_ext/libuv/src/unix/openbsd.c +295 -0
  189. data/ext/asyncengine_ext/libuv/src/unix/pipe.c +266 -0
  190. data/ext/asyncengine_ext/libuv/src/unix/prepare.c +79 -0
  191. data/ext/asyncengine_ext/libuv/src/unix/process.c +369 -0
  192. data/ext/asyncengine_ext/libuv/src/unix/stream.c +1033 -0
  193. data/ext/asyncengine_ext/libuv/src/unix/sunos.c +466 -0
  194. data/ext/asyncengine_ext/libuv/src/unix/tcp.c +327 -0
  195. data/ext/asyncengine_ext/libuv/src/unix/thread.c +154 -0
  196. data/ext/asyncengine_ext/libuv/src/unix/timer.c +127 -0
  197. data/ext/asyncengine_ext/libuv/src/unix/tty.c +146 -0
  198. data/ext/asyncengine_ext/libuv/src/unix/udp.c +670 -0
  199. data/ext/asyncengine_ext/libuv/src/unix/uv-eio.c +124 -0
  200. data/ext/asyncengine_ext/libuv/src/unix/uv-eio.h +13 -0
  201. data/ext/asyncengine_ext/libuv/src/uv-common.c +354 -0
  202. data/ext/asyncengine_ext/libuv/src/uv-common.h +87 -0
  203. data/ext/asyncengine_ext/libuv/src/win/async.c +127 -0
  204. data/ext/asyncengine_ext/libuv/src/win/cares.c +290 -0
  205. data/ext/asyncengine_ext/libuv/src/win/core.c +270 -0
  206. data/ext/asyncengine_ext/libuv/src/win/dl.c +82 -0
  207. data/ext/asyncengine_ext/libuv/src/win/error.c +132 -0
  208. data/ext/asyncengine_ext/libuv/src/win/fs-event.c +514 -0
  209. data/ext/asyncengine_ext/libuv/src/win/fs.c +1576 -0
  210. data/ext/asyncengine_ext/libuv/src/win/getaddrinfo.c +372 -0
  211. data/ext/asyncengine_ext/libuv/src/win/handle.c +225 -0
  212. data/ext/asyncengine_ext/libuv/src/win/internal.h +352 -0
  213. data/ext/asyncengine_ext/libuv/src/win/loop-watcher.c +131 -0
  214. data/ext/asyncengine_ext/libuv/src/win/pipe.c +1661 -0
  215. data/ext/asyncengine_ext/libuv/src/win/process.c +1140 -0
  216. data/ext/asyncengine_ext/libuv/src/win/req.c +174 -0
  217. data/ext/asyncengine_ext/libuv/src/win/stream.c +201 -0
  218. data/ext/asyncengine_ext/libuv/src/win/tcp.c +1282 -0
  219. data/ext/asyncengine_ext/libuv/src/win/thread.c +332 -0
  220. data/ext/asyncengine_ext/libuv/src/win/threadpool.c +73 -0
  221. data/ext/asyncengine_ext/libuv/src/win/timer.c +276 -0
  222. data/ext/asyncengine_ext/libuv/src/win/tty.c +1795 -0
  223. data/ext/asyncengine_ext/libuv/src/win/udp.c +709 -0
  224. data/ext/asyncengine_ext/libuv/src/win/util.c +719 -0
  225. data/ext/asyncengine_ext/libuv/src/win/winapi.c +117 -0
  226. data/ext/asyncengine_ext/libuv/src/win/winapi.h +4419 -0
  227. data/ext/asyncengine_ext/libuv/src/win/winsock.c +470 -0
  228. data/ext/asyncengine_ext/libuv/src/win/winsock.h +138 -0
  229. data/ext/asyncengine_ext/libuv/test/benchmark-ares.c +118 -0
  230. data/ext/asyncengine_ext/libuv/test/benchmark-getaddrinfo.c +94 -0
  231. data/ext/asyncengine_ext/libuv/test/benchmark-list.h +105 -0
  232. data/ext/asyncengine_ext/libuv/test/benchmark-ping-pongs.c +213 -0
  233. data/ext/asyncengine_ext/libuv/test/benchmark-pound.c +324 -0
  234. data/ext/asyncengine_ext/libuv/test/benchmark-pump.c +462 -0
  235. data/ext/asyncengine_ext/libuv/test/benchmark-sizes.c +40 -0
  236. data/ext/asyncengine_ext/libuv/test/benchmark-spawn.c +156 -0
  237. data/ext/asyncengine_ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
  238. data/ext/asyncengine_ext/libuv/test/benchmark-thread.c +64 -0
  239. data/ext/asyncengine_ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
  240. data/ext/asyncengine_ext/libuv/test/blackhole-server.c +118 -0
  241. data/ext/asyncengine_ext/libuv/test/dns-server.c +321 -0
  242. data/ext/asyncengine_ext/libuv/test/echo-server.c +370 -0
  243. data/ext/asyncengine_ext/libuv/test/fixtures/empty_file +0 -0
  244. data/ext/asyncengine_ext/libuv/test/fixtures/load_error.node +1 -0
  245. data/ext/asyncengine_ext/libuv/test/run-benchmarks.c +64 -0
  246. data/ext/asyncengine_ext/libuv/test/run-tests.c +108 -0
  247. data/ext/asyncengine_ext/libuv/test/runner-unix.c +315 -0
  248. data/ext/asyncengine_ext/libuv/test/runner-unix.h +36 -0
  249. data/ext/asyncengine_ext/libuv/test/runner-win.c +343 -0
  250. data/ext/asyncengine_ext/libuv/test/runner-win.h +42 -0
  251. data/ext/asyncengine_ext/libuv/test/runner.c +317 -0
  252. data/ext/asyncengine_ext/libuv/test/runner.h +159 -0
  253. data/ext/asyncengine_ext/libuv/test/task.h +117 -0
  254. data/ext/asyncengine_ext/libuv/test/test-async.c +216 -0
  255. data/ext/asyncengine_ext/libuv/test/test-callback-stack.c +203 -0
  256. data/ext/asyncengine_ext/libuv/test/test-connection-fail.c +148 -0
  257. data/ext/asyncengine_ext/libuv/test/test-counters-init.c +216 -0
  258. data/ext/asyncengine_ext/libuv/test/test-cwd-and-chdir.c +64 -0
  259. data/ext/asyncengine_ext/libuv/test/test-delayed-accept.c +197 -0
  260. data/ext/asyncengine_ext/libuv/test/test-dlerror.c +49 -0
  261. data/ext/asyncengine_ext/libuv/test/test-eio-overflow.c +90 -0
  262. data/ext/asyncengine_ext/libuv/test/test-error.c +59 -0
  263. data/ext/asyncengine_ext/libuv/test/test-fail-always.c +29 -0
  264. data/ext/asyncengine_ext/libuv/test/test-fs-event.c +442 -0
  265. data/ext/asyncengine_ext/libuv/test/test-fs.c +1731 -0
  266. data/ext/asyncengine_ext/libuv/test/test-get-currentexe.c +63 -0
  267. data/ext/asyncengine_ext/libuv/test/test-get-loadavg.c +36 -0
  268. data/ext/asyncengine_ext/libuv/test/test-get-memory.c +38 -0
  269. data/ext/asyncengine_ext/libuv/test/test-getaddrinfo.c +122 -0
  270. data/ext/asyncengine_ext/libuv/test/test-gethostbyname.c +189 -0
  271. data/ext/asyncengine_ext/libuv/test/test-getsockname.c +342 -0
  272. data/ext/asyncengine_ext/libuv/test/test-hrtime.c +51 -0
  273. data/ext/asyncengine_ext/libuv/test/test-idle.c +81 -0
  274. data/ext/asyncengine_ext/libuv/test/test-ipc-send-recv.c +209 -0
  275. data/ext/asyncengine_ext/libuv/test/test-ipc.c +614 -0
  276. data/ext/asyncengine_ext/libuv/test/test-list.h +371 -0
  277. data/ext/asyncengine_ext/libuv/test/test-loop-handles.c +359 -0
  278. data/ext/asyncengine_ext/libuv/test/test-multiple-listen.c +102 -0
  279. data/ext/asyncengine_ext/libuv/test/test-mutexes.c +63 -0
  280. data/ext/asyncengine_ext/libuv/test/test-pass-always.c +28 -0
  281. data/ext/asyncengine_ext/libuv/test/test-ping-pong.c +253 -0
  282. data/ext/asyncengine_ext/libuv/test/test-pipe-bind-error.c +140 -0
  283. data/ext/asyncengine_ext/libuv/test/test-pipe-connect-error.c +96 -0
  284. data/ext/asyncengine_ext/libuv/test/test-platform-output.c +87 -0
  285. data/ext/asyncengine_ext/libuv/test/test-process-title.c +42 -0
  286. data/ext/asyncengine_ext/libuv/test/test-ref.c +322 -0
  287. data/ext/asyncengine_ext/libuv/test/test-run-once.c +44 -0
  288. data/ext/asyncengine_ext/libuv/test/test-shutdown-close.c +103 -0
  289. data/ext/asyncengine_ext/libuv/test/test-shutdown-eof.c +183 -0
  290. data/ext/asyncengine_ext/libuv/test/test-spawn.c +499 -0
  291. data/ext/asyncengine_ext/libuv/test/test-stdio-over-pipes.c +256 -0
  292. data/ext/asyncengine_ext/libuv/test/test-tcp-bind-error.c +191 -0
  293. data/ext/asyncengine_ext/libuv/test/test-tcp-bind6-error.c +154 -0
  294. data/ext/asyncengine_ext/libuv/test/test-tcp-close.c +129 -0
  295. data/ext/asyncengine_ext/libuv/test/test-tcp-connect-error.c +70 -0
  296. data/ext/asyncengine_ext/libuv/test/test-tcp-connect6-error.c +68 -0
  297. data/ext/asyncengine_ext/libuv/test/test-tcp-flags.c +51 -0
  298. data/ext/asyncengine_ext/libuv/test/test-tcp-write-error.c +168 -0
  299. data/ext/asyncengine_ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
  300. data/ext/asyncengine_ext/libuv/test/test-tcp-writealot.c +195 -0
  301. data/ext/asyncengine_ext/libuv/test/test-thread.c +183 -0
  302. data/ext/asyncengine_ext/libuv/test/test-threadpool.c +57 -0
  303. data/ext/asyncengine_ext/libuv/test/test-timer-again.c +141 -0
  304. data/ext/asyncengine_ext/libuv/test/test-timer.c +130 -0
  305. data/ext/asyncengine_ext/libuv/test/test-tty.c +110 -0
  306. data/ext/asyncengine_ext/libuv/test/test-udp-dgram-too-big.c +86 -0
  307. data/ext/asyncengine_ext/libuv/test/test-udp-ipv6.c +156 -0
  308. data/ext/asyncengine_ext/libuv/test/test-udp-multicast-join.c +139 -0
  309. data/ext/asyncengine_ext/libuv/test/test-udp-multicast-ttl.c +86 -0
  310. data/ext/asyncengine_ext/libuv/test/test-udp-options.c +86 -0
  311. data/ext/asyncengine_ext/libuv/test/test-udp-send-and-recv.c +208 -0
  312. data/ext/asyncengine_ext/libuv/test/test-util.c +97 -0
  313. data/ext/asyncengine_ext/libuv/uv.gyp +435 -0
  314. data/ext/asyncengine_ext/libuv/vcbuild.bat +105 -0
  315. data/lib/asyncengine/version.rb +3 -0
  316. data/lib/asyncengine.rb +41 -0
  317. metadata +384 -0
@@ -0,0 +1,1731 @@
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
+ /* FIXME we shouldn't need to branch in this file */
23
+ #define UNIX (defined(__unix__) || defined(__POSIX__) || defined(__APPLE__))
24
+
25
+ #include "uv.h"
26
+ #include "task.h"
27
+
28
+ #include <errno.h>
29
+ #include <string.h> /* memset */
30
+ #include <fcntl.h>
31
+ #include <sys/stat.h>
32
+
33
+
34
+ #if UNIX
35
+ #include <unistd.h> /* unlink, rmdir, etc. */
36
+ #else
37
+ # include <direct.h>
38
+ # include <io.h>
39
+ # define unlink _unlink
40
+ # define rmdir _rmdir
41
+ # define stat _stati64
42
+ # define open _open
43
+ # define write _write
44
+ # define lseek _lseek
45
+ # define close _close
46
+ #endif
47
+
48
+ #define TOO_LONG_NAME_LENGTH 65536
49
+
50
+ typedef struct {
51
+ const char* path;
52
+ double atime;
53
+ double mtime;
54
+ } utime_check_t;
55
+
56
+
57
+ static int close_cb_count;
58
+ static int create_cb_count;
59
+ static int open_cb_count;
60
+ static int read_cb_count;
61
+ static int write_cb_count;
62
+ static int unlink_cb_count;
63
+ static int mkdir_cb_count;
64
+ static int rmdir_cb_count;
65
+ static int readdir_cb_count;
66
+ static int stat_cb_count;
67
+ static int rename_cb_count;
68
+ static int fsync_cb_count;
69
+ static int fdatasync_cb_count;
70
+ static int ftruncate_cb_count;
71
+ static int sendfile_cb_count;
72
+ static int fstat_cb_count;
73
+ static int chmod_cb_count;
74
+ static int fchmod_cb_count;
75
+ static int chown_cb_count;
76
+ static int fchown_cb_count;
77
+ static int link_cb_count;
78
+ static int symlink_cb_count;
79
+ static int readlink_cb_count;
80
+ static int utime_cb_count;
81
+ static int futime_cb_count;
82
+
83
+ static uv_loop_t* loop;
84
+
85
+ static uv_fs_t open_req1;
86
+ static uv_fs_t open_req2;
87
+ static uv_fs_t read_req;
88
+ static uv_fs_t write_req;
89
+ static uv_fs_t unlink_req;
90
+ static uv_fs_t close_req;
91
+ static uv_fs_t mkdir_req;
92
+ static uv_fs_t rmdir_req;
93
+ static uv_fs_t readdir_req;
94
+ static uv_fs_t stat_req;
95
+ static uv_fs_t rename_req;
96
+ static uv_fs_t fsync_req;
97
+ static uv_fs_t fdatasync_req;
98
+ static uv_fs_t ftruncate_req;
99
+ static uv_fs_t sendfile_req;
100
+ static uv_fs_t utime_req;
101
+ static uv_fs_t futime_req;
102
+
103
+ static char buf[32];
104
+ static char test_buf[] = "test-buffer\n";
105
+
106
+
107
+ void check_permission(const char* filename, int mode) {
108
+ int r;
109
+ uv_fs_t req;
110
+ struct stat* s;
111
+
112
+ r = uv_fs_stat(uv_default_loop(), &req, filename, NULL);
113
+ ASSERT(r == 0);
114
+ ASSERT(req.result == 0);
115
+
116
+ s = req.ptr;
117
+ #ifdef _WIN32
118
+ /*
119
+ * On Windows, chmod can only modify S_IWUSR (_S_IWRITE) bit,
120
+ * so only testing for the specified flags.
121
+ */
122
+ ASSERT((s->st_mode & 0777) & mode);
123
+ #else
124
+ ASSERT((s->st_mode & 0777) == mode);
125
+ #endif
126
+
127
+ uv_fs_req_cleanup(&req);
128
+ }
129
+
130
+
131
+ static void link_cb(uv_fs_t* req) {
132
+ ASSERT(req->fs_type == UV_FS_LINK);
133
+ ASSERT(req->result == 0);
134
+ link_cb_count++;
135
+ uv_fs_req_cleanup(req);
136
+ }
137
+
138
+
139
+ static void symlink_cb(uv_fs_t* req) {
140
+ ASSERT(req->fs_type == UV_FS_SYMLINK);
141
+ ASSERT(req->result == 0);
142
+ symlink_cb_count++;
143
+ uv_fs_req_cleanup(req);
144
+ }
145
+
146
+ static void readlink_cb(uv_fs_t* req) {
147
+ ASSERT(req->fs_type == UV_FS_READLINK);
148
+ ASSERT(req->result == 0);
149
+ ASSERT(strcmp(req->ptr, "test_file_symlink2") == 0);
150
+ readlink_cb_count++;
151
+ uv_fs_req_cleanup(req);
152
+ }
153
+
154
+ static void fchmod_cb(uv_fs_t* req) {
155
+ ASSERT(req->fs_type == UV_FS_FCHMOD);
156
+ ASSERT(req->result == 0);
157
+ fchmod_cb_count++;
158
+ uv_fs_req_cleanup(req);
159
+ check_permission("test_file", *(int*)req->data);
160
+ }
161
+
162
+
163
+ static void chmod_cb(uv_fs_t* req) {
164
+ ASSERT(req->fs_type == UV_FS_CHMOD);
165
+ ASSERT(req->result == 0);
166
+ chmod_cb_count++;
167
+ uv_fs_req_cleanup(req);
168
+ check_permission("test_file", *(int*)req->data);
169
+ }
170
+
171
+
172
+ static void fchown_cb(uv_fs_t* req) {
173
+ ASSERT(req->fs_type == UV_FS_FCHOWN);
174
+ ASSERT(req->result == 0);
175
+ fchown_cb_count++;
176
+ uv_fs_req_cleanup(req);
177
+ }
178
+
179
+
180
+ static void chown_cb(uv_fs_t* req) {
181
+ ASSERT(req->fs_type == UV_FS_CHOWN);
182
+ ASSERT(req->result == 0);
183
+ chown_cb_count++;
184
+ uv_fs_req_cleanup(req);
185
+ }
186
+
187
+ static void chown_root_cb(uv_fs_t* req) {
188
+ ASSERT(req->fs_type == UV_FS_CHOWN);
189
+ #ifdef _WIN32
190
+ /* On windows, chown is a no-op and always succeeds. */
191
+ ASSERT(req->result == 0);
192
+ #else
193
+ /* On unix, chown'ing the root directory is not allowed. */
194
+ ASSERT(req->result == -1);
195
+ ASSERT(req->errorno == UV_EPERM);
196
+ #endif
197
+ chown_cb_count++;
198
+ uv_fs_req_cleanup(req);
199
+ }
200
+
201
+ static void unlink_cb(uv_fs_t* req) {
202
+ ASSERT(req == &unlink_req);
203
+ ASSERT(req->fs_type == UV_FS_UNLINK);
204
+ ASSERT(req->result != -1);
205
+ unlink_cb_count++;
206
+ uv_fs_req_cleanup(req);
207
+ }
208
+
209
+ static void fstat_cb(uv_fs_t* req) {
210
+ struct stat* s = req->ptr;
211
+ ASSERT(req->fs_type == UV_FS_FSTAT);
212
+ ASSERT(req->result == 0);
213
+ ASSERT(s->st_size == sizeof(test_buf));
214
+ uv_fs_req_cleanup(req);
215
+ fstat_cb_count++;
216
+ }
217
+
218
+
219
+ static void close_cb(uv_fs_t* req) {
220
+ int r;
221
+ ASSERT(req == &close_req);
222
+ ASSERT(req->fs_type == UV_FS_CLOSE);
223
+ ASSERT(req->result != -1);
224
+ close_cb_count++;
225
+ uv_fs_req_cleanup(req);
226
+ if (close_cb_count == 3) {
227
+ r = uv_fs_unlink(loop, &unlink_req, "test_file2", unlink_cb);
228
+ ASSERT(r == 0);
229
+ }
230
+ }
231
+
232
+
233
+ static void ftruncate_cb(uv_fs_t* req) {
234
+ int r;
235
+ ASSERT(req == &ftruncate_req);
236
+ ASSERT(req->fs_type == UV_FS_FTRUNCATE);
237
+ ASSERT(req->result != -1);
238
+ ftruncate_cb_count++;
239
+ uv_fs_req_cleanup(req);
240
+ r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
241
+ ASSERT(r == 0);
242
+ }
243
+
244
+
245
+ static void read_cb(uv_fs_t* req) {
246
+ int r;
247
+ ASSERT(req == &read_req);
248
+ ASSERT(req->fs_type == UV_FS_READ);
249
+ ASSERT(req->result != -1);
250
+ read_cb_count++;
251
+ uv_fs_req_cleanup(req);
252
+ if (read_cb_count == 1) {
253
+ ASSERT(strcmp(buf, test_buf) == 0);
254
+ r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7,
255
+ ftruncate_cb);
256
+ } else {
257
+ ASSERT(strcmp(buf, "test-bu") == 0);
258
+ r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
259
+ }
260
+ ASSERT(r == 0);
261
+ }
262
+
263
+
264
+ static void open_cb(uv_fs_t* req) {
265
+ int r;
266
+ ASSERT(req == &open_req1);
267
+ ASSERT(req->fs_type == UV_FS_OPEN);
268
+ if (req->result < 0) {
269
+ /* TODO get error with uv_last_error() */
270
+ fprintf(stderr, "async open error: %d\n", req->errorno);
271
+ ASSERT(0);
272
+ }
273
+ open_cb_count++;
274
+ ASSERT(req->path);
275
+ ASSERT(memcmp(req->path, "test_file2\0", 11) == 0);
276
+ uv_fs_req_cleanup(req);
277
+ memset(buf, 0, sizeof(buf));
278
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
279
+ read_cb);
280
+ ASSERT(r == 0);
281
+ }
282
+
283
+
284
+ static void open_cb_simple(uv_fs_t* req) {
285
+ ASSERT(req->fs_type == UV_FS_OPEN);
286
+ if (req->result < 0) {
287
+ /* TODO get error with uv_last_error() */
288
+ fprintf(stderr, "async open error: %d\n", req->errorno);
289
+ ASSERT(0);
290
+ }
291
+ open_cb_count++;
292
+ ASSERT(req->path);
293
+ uv_fs_req_cleanup(req);
294
+ }
295
+
296
+
297
+ static void fsync_cb(uv_fs_t* req) {
298
+ int r;
299
+ ASSERT(req == &fsync_req);
300
+ ASSERT(req->fs_type == UV_FS_FSYNC);
301
+ ASSERT(req->result != -1);
302
+ fsync_cb_count++;
303
+ uv_fs_req_cleanup(req);
304
+ r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
305
+ ASSERT(r == 0);
306
+ }
307
+
308
+
309
+ static void fdatasync_cb(uv_fs_t* req) {
310
+ int r;
311
+ ASSERT(req == &fdatasync_req);
312
+ ASSERT(req->fs_type == UV_FS_FDATASYNC);
313
+ ASSERT(req->result != -1);
314
+ fdatasync_cb_count++;
315
+ uv_fs_req_cleanup(req);
316
+ r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb);
317
+ ASSERT(r == 0);
318
+ }
319
+
320
+
321
+ static void write_cb(uv_fs_t* req) {
322
+ int r;
323
+ ASSERT(req == &write_req);
324
+ ASSERT(req->fs_type == UV_FS_WRITE);
325
+ ASSERT(req->result != -1);
326
+ write_cb_count++;
327
+ uv_fs_req_cleanup(req);
328
+ r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb);
329
+ ASSERT(r == 0);
330
+ }
331
+
332
+
333
+ static void create_cb(uv_fs_t* req) {
334
+ int r;
335
+ ASSERT(req == &open_req1);
336
+ ASSERT(req->fs_type == UV_FS_OPEN);
337
+ ASSERT(req->result != -1);
338
+ create_cb_count++;
339
+ uv_fs_req_cleanup(req);
340
+ r = uv_fs_write(loop, &write_req, req->result, test_buf, sizeof(test_buf),
341
+ -1, write_cb);
342
+ ASSERT(r == 0);
343
+ }
344
+
345
+
346
+ static void rename_cb(uv_fs_t* req) {
347
+ ASSERT(req == &rename_req);
348
+ ASSERT(req->fs_type == UV_FS_RENAME);
349
+ ASSERT(req->result != -1);
350
+ rename_cb_count++;
351
+ uv_fs_req_cleanup(req);
352
+ }
353
+
354
+
355
+ static void mkdir_cb(uv_fs_t* req) {
356
+ ASSERT(req == &mkdir_req);
357
+ ASSERT(req->fs_type == UV_FS_MKDIR);
358
+ ASSERT(req->result != -1);
359
+ mkdir_cb_count++;
360
+ ASSERT(req->path);
361
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
362
+ uv_fs_req_cleanup(req);
363
+ }
364
+
365
+
366
+ static void rmdir_cb(uv_fs_t* req) {
367
+ ASSERT(req == &rmdir_req);
368
+ ASSERT(req->fs_type == UV_FS_RMDIR);
369
+ ASSERT(req->result != -1);
370
+ rmdir_cb_count++;
371
+ ASSERT(req->path);
372
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
373
+ uv_fs_req_cleanup(req);
374
+ }
375
+
376
+
377
+ static void readdir_cb(uv_fs_t* req) {
378
+ ASSERT(req == &readdir_req);
379
+ ASSERT(req->fs_type == UV_FS_READDIR);
380
+ ASSERT(req->result == 2);
381
+ ASSERT(req->ptr);
382
+ ASSERT(memcmp(req->ptr, "file1\0file2\0", 12) == 0
383
+ || memcmp(req->ptr, "file2\0file1\0", 12) == 0);
384
+ readdir_cb_count++;
385
+ ASSERT(req->path);
386
+ ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
387
+ uv_fs_req_cleanup(req);
388
+ ASSERT(!req->ptr);
389
+ }
390
+
391
+
392
+ static void empty_readdir_cb(uv_fs_t* req) {
393
+ ASSERT(req == &readdir_req);
394
+ ASSERT(req->fs_type == UV_FS_READDIR);
395
+ ASSERT(req->result == 0);
396
+ ASSERT(req->ptr == NULL);
397
+ uv_fs_req_cleanup(req);
398
+ readdir_cb_count++;
399
+ }
400
+
401
+
402
+ static void file_readdir_cb(uv_fs_t* req) {
403
+ ASSERT(req == &readdir_req);
404
+ ASSERT(req->fs_type == UV_FS_READDIR);
405
+ ASSERT(req->result == -1);
406
+ ASSERT(req->ptr == NULL);
407
+ ASSERT(uv_last_error(req->loop).code == UV_ENOTDIR);
408
+ uv_fs_req_cleanup(req);
409
+ readdir_cb_count++;
410
+ }
411
+
412
+
413
+ static void stat_cb(uv_fs_t* req) {
414
+ ASSERT(req == &stat_req);
415
+ ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
416
+ ASSERT(req->result != -1);
417
+ ASSERT(req->ptr);
418
+ stat_cb_count++;
419
+ uv_fs_req_cleanup(req);
420
+ ASSERT(!req->ptr);
421
+ }
422
+
423
+
424
+ static void sendfile_cb(uv_fs_t* req) {
425
+ ASSERT(req == &sendfile_req);
426
+ ASSERT(req->fs_type == UV_FS_SENDFILE);
427
+ ASSERT(req->result == 65546);
428
+ sendfile_cb_count++;
429
+ uv_fs_req_cleanup(req);
430
+ }
431
+
432
+
433
+ static void open_noent_cb(uv_fs_t* req) {
434
+ ASSERT(req->fs_type == UV_FS_OPEN);
435
+ ASSERT(req->errorno == UV_ENOENT);
436
+ ASSERT(req->result == -1);
437
+ open_cb_count++;
438
+ uv_fs_req_cleanup(req);
439
+ }
440
+
441
+ static void open_nametoolong_cb(uv_fs_t* req) {
442
+ ASSERT(req->fs_type == UV_FS_OPEN);
443
+ ASSERT(req->errorno == UV_ENAMETOOLONG);
444
+ ASSERT(req->result == -1);
445
+ open_cb_count++;
446
+ uv_fs_req_cleanup(req);
447
+ }
448
+
449
+ static void open_loop_cb(uv_fs_t* req) {
450
+ ASSERT(req->fs_type == UV_FS_OPEN);
451
+ ASSERT(req->errorno == UV_ELOOP);
452
+ ASSERT(req->result == -1);
453
+ open_cb_count++;
454
+ uv_fs_req_cleanup(req);
455
+ }
456
+
457
+
458
+ TEST_IMPL(fs_file_noent) {
459
+ uv_fs_t req;
460
+ int r;
461
+
462
+ loop = uv_default_loop();
463
+
464
+ r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, NULL);
465
+ ASSERT(r == -1);
466
+ ASSERT(req.result == -1);
467
+ ASSERT(uv_last_error(loop).code == UV_ENOENT);
468
+ uv_fs_req_cleanup(&req);
469
+
470
+ r = uv_fs_open(loop, &req, "does_not_exist", O_RDONLY, 0, open_noent_cb);
471
+ ASSERT(r == 0);
472
+
473
+ ASSERT(open_cb_count == 0);
474
+ uv_run(loop);
475
+ ASSERT(open_cb_count == 1);
476
+
477
+ /* TODO add EACCES test */
478
+
479
+ return 0;
480
+ }
481
+
482
+ TEST_IMPL(fs_file_nametoolong) {
483
+ uv_fs_t req;
484
+ int r;
485
+ char name[TOO_LONG_NAME_LENGTH + 1];
486
+
487
+ loop = uv_default_loop();
488
+
489
+ memset(name, 'a', TOO_LONG_NAME_LENGTH);
490
+ name[TOO_LONG_NAME_LENGTH] = 0;
491
+
492
+ r = uv_fs_open(loop, &req, name, O_RDONLY, 0, NULL);
493
+ ASSERT(r == -1);
494
+ ASSERT(req.result == -1);
495
+ ASSERT(uv_last_error(loop).code == UV_ENAMETOOLONG);
496
+ uv_fs_req_cleanup(&req);
497
+
498
+ r = uv_fs_open(loop, &req, name, O_RDONLY, 0, open_nametoolong_cb);
499
+ ASSERT(r == 0);
500
+
501
+ ASSERT(open_cb_count == 0);
502
+ uv_run(loop);
503
+ ASSERT(open_cb_count == 1);
504
+
505
+ return 0;
506
+ }
507
+
508
+ TEST_IMPL(fs_file_loop) {
509
+ uv_fs_t req;
510
+ int r;
511
+
512
+ loop = uv_default_loop();
513
+
514
+ unlink("test_symlink");
515
+ uv_fs_symlink(loop, &req, "test_symlink", "test_symlink", 0, NULL);
516
+ uv_fs_req_cleanup(&req);
517
+
518
+ r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, NULL);
519
+ ASSERT(r == -1);
520
+ ASSERT(req.result == -1);
521
+ ASSERT(uv_last_error(loop).code == UV_ELOOP);
522
+ uv_fs_req_cleanup(&req);
523
+
524
+ r = uv_fs_open(loop, &req, "test_symlink", O_RDONLY, 0, open_loop_cb);
525
+ ASSERT(r == 0);
526
+
527
+ ASSERT(open_cb_count == 0);
528
+ uv_run(loop);
529
+ ASSERT(open_cb_count == 1);
530
+
531
+ unlink("test_symlink");
532
+
533
+ return 0;
534
+ }
535
+
536
+ static void check_utime(const char* path, double atime, double mtime) {
537
+ struct stat* s;
538
+ uv_fs_t req;
539
+ int r;
540
+
541
+ r = uv_fs_stat(loop, &req, path, NULL);
542
+ ASSERT(r == 0);
543
+
544
+ ASSERT(req.result == 0);
545
+ s = req.ptr;
546
+
547
+ #if _WIN32
548
+ ASSERT(s->st_atime == atime);
549
+ ASSERT(s->st_mtime == mtime);
550
+ #elif !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
551
+ ASSERT(s->st_atimespec.tv_sec == atime);
552
+ ASSERT(s->st_mtimespec.tv_sec == mtime);
553
+ #else
554
+ ASSERT(s->st_atim.tv_sec == atime);
555
+ ASSERT(s->st_mtim.tv_sec == mtime);
556
+ #endif
557
+
558
+ uv_fs_req_cleanup(&req);
559
+ }
560
+
561
+
562
+ static void utime_cb(uv_fs_t* req) {
563
+ utime_check_t* c;
564
+
565
+ ASSERT(req == &utime_req);
566
+ ASSERT(req->result == 0);
567
+ ASSERT(req->fs_type == UV_FS_UTIME);
568
+
569
+ c = req->data;
570
+ check_utime(c->path, c->atime, c->mtime);
571
+
572
+ uv_fs_req_cleanup(req);
573
+ utime_cb_count++;
574
+ }
575
+
576
+
577
+ static void futime_cb(uv_fs_t* req) {
578
+ utime_check_t* c;
579
+
580
+ ASSERT(req == &futime_req);
581
+ ASSERT(req->result == 0);
582
+ ASSERT(req->fs_type == UV_FS_FUTIME);
583
+
584
+ c = req->data;
585
+ check_utime(c->path, c->atime, c->mtime);
586
+
587
+ uv_fs_req_cleanup(req);
588
+ futime_cb_count++;
589
+ }
590
+
591
+
592
+ TEST_IMPL(fs_file_async) {
593
+ int r;
594
+
595
+ /* Setup. */
596
+ unlink("test_file");
597
+ unlink("test_file2");
598
+
599
+ loop = uv_default_loop();
600
+
601
+ r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
602
+ S_IREAD | S_IWRITE, create_cb);
603
+ ASSERT(r == 0);
604
+ uv_run(loop);
605
+
606
+ ASSERT(create_cb_count == 1);
607
+ ASSERT(write_cb_count == 1);
608
+ ASSERT(fsync_cb_count == 1);
609
+ ASSERT(fdatasync_cb_count == 1);
610
+ ASSERT(close_cb_count == 1);
611
+
612
+ r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", rename_cb);
613
+ ASSERT(r == 0);
614
+
615
+ uv_run(loop);
616
+ ASSERT(create_cb_count == 1);
617
+ ASSERT(write_cb_count == 1);
618
+ ASSERT(close_cb_count == 1);
619
+ ASSERT(rename_cb_count == 1);
620
+
621
+ r = uv_fs_open(loop, &open_req1, "test_file2", O_RDWR, 0, open_cb);
622
+ ASSERT(r == 0);
623
+
624
+ uv_run(loop);
625
+ ASSERT(open_cb_count == 1);
626
+ ASSERT(read_cb_count == 1);
627
+ ASSERT(close_cb_count == 2);
628
+ ASSERT(rename_cb_count == 1);
629
+ ASSERT(create_cb_count == 1);
630
+ ASSERT(write_cb_count == 1);
631
+ ASSERT(ftruncate_cb_count == 1);
632
+
633
+ r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, open_cb);
634
+ ASSERT(r == 0);
635
+
636
+ uv_run(loop);
637
+ ASSERT(open_cb_count == 2);
638
+ ASSERT(read_cb_count == 2);
639
+ ASSERT(close_cb_count == 3);
640
+ ASSERT(rename_cb_count == 1);
641
+ ASSERT(unlink_cb_count == 1);
642
+ ASSERT(create_cb_count == 1);
643
+ ASSERT(write_cb_count == 1);
644
+ ASSERT(ftruncate_cb_count == 1);
645
+
646
+ /* Cleanup. */
647
+ unlink("test_file");
648
+ unlink("test_file2");
649
+
650
+ return 0;
651
+ }
652
+
653
+
654
+ TEST_IMPL(fs_file_sync) {
655
+ int r;
656
+
657
+ /* Setup. */
658
+ unlink("test_file");
659
+ unlink("test_file2");
660
+
661
+ loop = uv_default_loop();
662
+
663
+ r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
664
+ S_IWRITE | S_IREAD, NULL);
665
+ ASSERT(r != -1);
666
+ ASSERT(open_req1.result != -1);
667
+ uv_fs_req_cleanup(&open_req1);
668
+
669
+ r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
670
+ sizeof(test_buf), -1, NULL);
671
+ ASSERT(r != -1);
672
+ ASSERT(write_req.result != -1);
673
+ uv_fs_req_cleanup(&write_req);
674
+
675
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
676
+ ASSERT(r != -1);
677
+ ASSERT(close_req.result != -1);
678
+ uv_fs_req_cleanup(&close_req);
679
+
680
+ r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
681
+ ASSERT(r != -1);
682
+ ASSERT(open_req1.result != -1);
683
+ uv_fs_req_cleanup(&open_req1);
684
+
685
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
686
+ NULL);
687
+ ASSERT(r != -1);
688
+ ASSERT(read_req.result != -1);
689
+ ASSERT(strcmp(buf, test_buf) == 0);
690
+ uv_fs_req_cleanup(&read_req);
691
+
692
+ r = uv_fs_ftruncate(loop, &ftruncate_req, open_req1.result, 7, NULL);
693
+ ASSERT(r != -1);
694
+ ASSERT(ftruncate_req.result != -1);
695
+ uv_fs_req_cleanup(&ftruncate_req);
696
+
697
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
698
+ ASSERT(r != -1);
699
+ ASSERT(close_req.result != -1);
700
+ uv_fs_req_cleanup(&close_req);
701
+
702
+ r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
703
+ ASSERT(r != -1);
704
+ ASSERT(rename_req.result != -1);
705
+ uv_fs_req_cleanup(&rename_req);
706
+
707
+ r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
708
+ ASSERT(r != -1);
709
+ ASSERT(open_req1.result != -1);
710
+ uv_fs_req_cleanup(&open_req1);
711
+
712
+ memset(buf, 0, sizeof(buf));
713
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
714
+ NULL);
715
+ ASSERT(r != -1);
716
+ ASSERT(read_req.result != -1);
717
+ ASSERT(strcmp(buf, "test-bu") == 0);
718
+ uv_fs_req_cleanup(&read_req);
719
+
720
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
721
+ ASSERT(r != -1);
722
+ ASSERT(close_req.result != -1);
723
+ uv_fs_req_cleanup(&close_req);
724
+
725
+ r = uv_fs_unlink(loop, &unlink_req, "test_file2", NULL);
726
+ ASSERT(r != -1);
727
+ ASSERT(unlink_req.result != -1);
728
+ uv_fs_req_cleanup(&unlink_req);
729
+
730
+ /* Cleanup */
731
+ unlink("test_file");
732
+ unlink("test_file2");
733
+
734
+ return 0;
735
+ }
736
+
737
+
738
+ TEST_IMPL(fs_async_dir) {
739
+ int r;
740
+
741
+ /* Setup */
742
+ unlink("test_dir/file1");
743
+ unlink("test_dir/file2");
744
+ rmdir("test_dir");
745
+
746
+ loop = uv_default_loop();
747
+
748
+ r = uv_fs_mkdir(loop, &mkdir_req, "test_dir", 0755, mkdir_cb);
749
+ ASSERT(r == 0);
750
+
751
+ uv_run(loop);
752
+ ASSERT(mkdir_cb_count == 1);
753
+
754
+ /* Create 2 files synchronously. */
755
+ r = uv_fs_open(loop, &open_req1, "test_dir/file1", O_WRONLY | O_CREAT,
756
+ S_IWRITE | S_IREAD, NULL);
757
+ ASSERT(r != -1);
758
+ uv_fs_req_cleanup(&open_req1);
759
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
760
+ ASSERT(r == 0);
761
+ uv_fs_req_cleanup(&close_req);
762
+
763
+ r = uv_fs_open(loop, &open_req1, "test_dir/file2", O_WRONLY | O_CREAT,
764
+ S_IWRITE | S_IREAD, NULL);
765
+ ASSERT(r != -1);
766
+ uv_fs_req_cleanup(&open_req1);
767
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
768
+ ASSERT(r == 0);
769
+ uv_fs_req_cleanup(&close_req);
770
+
771
+ r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, readdir_cb);
772
+ ASSERT(r == 0);
773
+
774
+ uv_run(loop);
775
+ ASSERT(readdir_cb_count == 1);
776
+
777
+ /* sync uv_fs_readdir */
778
+ r = uv_fs_readdir(loop, &readdir_req, "test_dir", 0, NULL);
779
+ ASSERT(r == 2);
780
+ ASSERT(readdir_req.result == 2);
781
+ ASSERT(readdir_req.ptr);
782
+ ASSERT(memcmp(readdir_req.ptr, "file1\0file2\0", 12) == 0
783
+ || memcmp(readdir_req.ptr, "file2\0file1\0", 12) == 0);
784
+ uv_fs_req_cleanup(&readdir_req);
785
+ ASSERT(!readdir_req.ptr);
786
+
787
+ r = uv_fs_stat(loop, &stat_req, "test_dir", stat_cb);
788
+ ASSERT(r == 0);
789
+ uv_run(loop);
790
+
791
+ r = uv_fs_stat(loop, &stat_req, "test_dir\\", stat_cb);
792
+ ASSERT(r == 0);
793
+ uv_run(loop);
794
+
795
+ r = uv_fs_lstat(loop, &stat_req, "test_dir", stat_cb);
796
+ ASSERT(r == 0);
797
+ uv_run(loop);
798
+
799
+ r = uv_fs_lstat(loop, &stat_req, "test_dir\\", stat_cb);
800
+ ASSERT(r == 0);
801
+ uv_run(loop);
802
+
803
+ ASSERT(stat_cb_count == 4);
804
+
805
+ r = uv_fs_unlink(loop, &unlink_req, "test_dir/file1", unlink_cb);
806
+ ASSERT(r == 0);
807
+ uv_run(loop);
808
+ ASSERT(unlink_cb_count == 1);
809
+
810
+ r = uv_fs_unlink(loop, &unlink_req, "test_dir/file2", unlink_cb);
811
+ ASSERT(r == 0);
812
+ uv_run(loop);
813
+ ASSERT(unlink_cb_count == 2);
814
+
815
+ r = uv_fs_rmdir(loop, &rmdir_req, "test_dir", rmdir_cb);
816
+ ASSERT(r == 0);
817
+ uv_run(loop);
818
+ ASSERT(rmdir_cb_count == 1);
819
+
820
+ /* Cleanup */
821
+ unlink("test_dir/file1");
822
+ unlink("test_dir/file2");
823
+ rmdir("test_dir");
824
+
825
+ return 0;
826
+ }
827
+
828
+
829
+ TEST_IMPL(fs_async_sendfile) {
830
+ int f, r;
831
+ struct stat s1, s2;
832
+
833
+ loop = uv_default_loop();
834
+
835
+ /* Setup. */
836
+ unlink("test_file");
837
+ unlink("test_file2");
838
+
839
+ f = open("test_file", O_WRONLY | O_CREAT, S_IWRITE | S_IREAD);
840
+ ASSERT(f != -1);
841
+
842
+ r = write(f, "begin\n", 6);
843
+ ASSERT(r == 6);
844
+
845
+ r = lseek(f, 65536, SEEK_CUR);
846
+ ASSERT(r == 65542);
847
+
848
+ r = write(f, "end\n", 4);
849
+ ASSERT(r != -1);
850
+
851
+ r = close(f);
852
+ ASSERT(r == 0);
853
+
854
+ /* Test starts here. */
855
+ r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR, 0, NULL);
856
+ ASSERT(r != -1);
857
+ ASSERT(open_req1.result != -1);
858
+ uv_fs_req_cleanup(&open_req1);
859
+
860
+ r = uv_fs_open(loop, &open_req2, "test_file2", O_WRONLY | O_CREAT,
861
+ S_IWRITE | S_IREAD, NULL);
862
+ ASSERT(r != -1);
863
+ ASSERT(open_req2.result != -1);
864
+ uv_fs_req_cleanup(&open_req2);
865
+
866
+ r = uv_fs_sendfile(loop, &sendfile_req, open_req2.result, open_req1.result,
867
+ 0, 131072, sendfile_cb);
868
+ ASSERT(r == 0);
869
+ uv_run(loop);
870
+
871
+ ASSERT(sendfile_cb_count == 1);
872
+
873
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
874
+ ASSERT(r == 0);
875
+ uv_fs_req_cleanup(&close_req);
876
+ r = uv_fs_close(loop, &close_req, open_req2.result, NULL);
877
+ ASSERT(r == 0);
878
+ uv_fs_req_cleanup(&close_req);
879
+
880
+ stat("test_file", &s1);
881
+ stat("test_file2", &s2);
882
+ ASSERT(65546 == s2.st_size && s1.st_size == s2.st_size);
883
+
884
+ /* Cleanup. */
885
+ unlink("test_file");
886
+ unlink("test_file2");
887
+
888
+ return 0;
889
+ }
890
+
891
+
892
+ TEST_IMPL(fs_fstat) {
893
+ int r;
894
+ uv_fs_t req;
895
+ uv_file file;
896
+ struct stat* s;
897
+
898
+ /* Setup. */
899
+ unlink("test_file");
900
+
901
+ loop = uv_default_loop();
902
+
903
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
904
+ S_IWRITE | S_IREAD, NULL);
905
+ ASSERT(r != -1);
906
+ ASSERT(req.result != -1);
907
+ file = req.result;
908
+ uv_fs_req_cleanup(&req);
909
+
910
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
911
+ ASSERT(r == sizeof(test_buf));
912
+ ASSERT(req.result == sizeof(test_buf));
913
+ uv_fs_req_cleanup(&req);
914
+
915
+ r = uv_fs_fstat(loop, &req, file, NULL);
916
+ ASSERT(r == 0);
917
+ ASSERT(req.result == 0);
918
+ s = req.ptr;
919
+ ASSERT(s->st_size == sizeof(test_buf));
920
+ uv_fs_req_cleanup(&req);
921
+
922
+ /* Now do the uv_fs_fstat call asynchronously */
923
+ r = uv_fs_fstat(loop, &req, file, fstat_cb);
924
+ ASSERT(r == 0);
925
+ uv_run(loop);
926
+ ASSERT(fstat_cb_count == 1);
927
+
928
+
929
+ r = uv_fs_close(loop, &req, file, NULL);
930
+ ASSERT(r == 0);
931
+ ASSERT(req.result == 0);
932
+ uv_fs_req_cleanup(&req);
933
+
934
+ /*
935
+ * Run the loop just to check we don't have make any extraneous uv_ref()
936
+ * calls. This should drop out immediately.
937
+ */
938
+ uv_run(loop);
939
+
940
+ /* Cleanup. */
941
+ unlink("test_file");
942
+
943
+ return 0;
944
+ }
945
+
946
+
947
+ TEST_IMPL(fs_chmod) {
948
+ int r;
949
+ uv_fs_t req;
950
+ uv_file file;
951
+
952
+ /* Setup. */
953
+ unlink("test_file");
954
+
955
+ loop = uv_default_loop();
956
+
957
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
958
+ S_IWRITE | S_IREAD, NULL);
959
+ ASSERT(r != -1);
960
+ ASSERT(req.result != -1);
961
+ file = req.result;
962
+ uv_fs_req_cleanup(&req);
963
+
964
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
965
+ ASSERT(r == sizeof(test_buf));
966
+ ASSERT(req.result == sizeof(test_buf));
967
+ uv_fs_req_cleanup(&req);
968
+
969
+ #ifndef _WIN32
970
+ /* Make the file write-only */
971
+ r = uv_fs_chmod(loop, &req, "test_file", 0200, NULL);
972
+ ASSERT(r == 0);
973
+ ASSERT(req.result == 0);
974
+ uv_fs_req_cleanup(&req);
975
+
976
+ check_permission("test_file", 0200);
977
+ #endif
978
+
979
+ /* Make the file read-only */
980
+ r = uv_fs_chmod(loop, &req, "test_file", 0400, NULL);
981
+ ASSERT(r == 0);
982
+ ASSERT(req.result == 0);
983
+ uv_fs_req_cleanup(&req);
984
+
985
+ check_permission("test_file", 0400);
986
+
987
+ /* Make the file read+write with sync uv_fs_fchmod */
988
+ r = uv_fs_fchmod(loop, &req, file, 0600, NULL);
989
+ ASSERT(r == 0);
990
+ ASSERT(req.result == 0);
991
+ uv_fs_req_cleanup(&req);
992
+
993
+ check_permission("test_file", 0600);
994
+
995
+ #ifndef _WIN32
996
+ /* async chmod */
997
+ {
998
+ static int mode = 0200;
999
+ req.data = &mode;
1000
+ }
1001
+ r = uv_fs_chmod(loop, &req, "test_file", 0200, chmod_cb);
1002
+ ASSERT(r == 0);
1003
+ uv_run(loop);
1004
+ ASSERT(chmod_cb_count == 1);
1005
+ chmod_cb_count = 0; /* reset for the next test */
1006
+ #endif
1007
+
1008
+ /* async chmod */
1009
+ {
1010
+ static int mode = 0400;
1011
+ req.data = &mode;
1012
+ }
1013
+ r = uv_fs_chmod(loop, &req, "test_file", 0400, chmod_cb);
1014
+ ASSERT(r == 0);
1015
+ uv_run(loop);
1016
+ ASSERT(chmod_cb_count == 1);
1017
+
1018
+ /* async fchmod */
1019
+ {
1020
+ static int mode = 0600;
1021
+ req.data = &mode;
1022
+ }
1023
+ r = uv_fs_fchmod(loop, &req, file, 0600, fchmod_cb);
1024
+ ASSERT(r == 0);
1025
+ uv_run(loop);
1026
+ ASSERT(fchmod_cb_count == 1);
1027
+
1028
+ close(file);
1029
+
1030
+ /*
1031
+ * Run the loop just to check we don't have make any extraneous uv_ref()
1032
+ * calls. This should drop out immediately.
1033
+ */
1034
+ uv_run(loop);
1035
+
1036
+ /* Cleanup. */
1037
+ unlink("test_file");
1038
+
1039
+ return 0;
1040
+ }
1041
+
1042
+
1043
+ TEST_IMPL(fs_chown) {
1044
+ int r;
1045
+ uv_fs_t req;
1046
+ uv_file file;
1047
+
1048
+ /* Setup. */
1049
+ unlink("test_file");
1050
+
1051
+ loop = uv_default_loop();
1052
+
1053
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
1054
+ S_IWRITE | S_IREAD, NULL);
1055
+ ASSERT(r != -1);
1056
+ ASSERT(req.result != -1);
1057
+ file = req.result;
1058
+ uv_fs_req_cleanup(&req);
1059
+
1060
+ /* sync chown */
1061
+ r = uv_fs_chown(loop, &req, "test_file", -1, -1, NULL);
1062
+ ASSERT(r == 0);
1063
+ ASSERT(req.result == 0);
1064
+ uv_fs_req_cleanup(&req);
1065
+
1066
+ /* sync fchown */
1067
+ r = uv_fs_fchown(loop, &req, file, -1, -1, NULL);
1068
+ ASSERT(r == 0);
1069
+ ASSERT(req.result == 0);
1070
+ uv_fs_req_cleanup(&req);
1071
+
1072
+ /* async chown */
1073
+ r = uv_fs_chown(loop, &req, "test_file", -1, -1, chown_cb);
1074
+ ASSERT(r == 0);
1075
+ uv_run(loop);
1076
+ ASSERT(chown_cb_count == 1);
1077
+
1078
+ /* chown to root (fail) */
1079
+ chown_cb_count = 0;
1080
+ r = uv_fs_chown(loop, &req, "test_file", 0, 0, chown_root_cb);
1081
+ uv_run(loop);
1082
+ ASSERT(chown_cb_count == 1);
1083
+
1084
+ /* async fchown */
1085
+ r = uv_fs_fchown(loop, &req, file, -1, -1, fchown_cb);
1086
+ ASSERT(r == 0);
1087
+ uv_run(loop);
1088
+ ASSERT(fchown_cb_count == 1);
1089
+
1090
+ close(file);
1091
+
1092
+ /*
1093
+ * Run the loop just to check we don't have make any extraneous uv_ref()
1094
+ * calls. This should drop out immediately.
1095
+ */
1096
+ uv_run(loop);
1097
+
1098
+ /* Cleanup. */
1099
+ unlink("test_file");
1100
+
1101
+ return 0;
1102
+ }
1103
+
1104
+
1105
+ TEST_IMPL(fs_link) {
1106
+ int r;
1107
+ uv_fs_t req;
1108
+ uv_file file;
1109
+ uv_file link;
1110
+
1111
+ /* Setup. */
1112
+ unlink("test_file");
1113
+ unlink("test_file_link");
1114
+ unlink("test_file_link2");
1115
+
1116
+ loop = uv_default_loop();
1117
+
1118
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
1119
+ S_IWRITE | S_IREAD, NULL);
1120
+ ASSERT(r != -1);
1121
+ ASSERT(req.result != -1);
1122
+ file = req.result;
1123
+ uv_fs_req_cleanup(&req);
1124
+
1125
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
1126
+ ASSERT(r == sizeof(test_buf));
1127
+ ASSERT(req.result == sizeof(test_buf));
1128
+ uv_fs_req_cleanup(&req);
1129
+
1130
+ close(file);
1131
+
1132
+ /* sync link */
1133
+ r = uv_fs_link(loop, &req, "test_file", "test_file_link", NULL);
1134
+ ASSERT(r == 0);
1135
+ ASSERT(req.result == 0);
1136
+ uv_fs_req_cleanup(&req);
1137
+
1138
+ r = uv_fs_open(loop, &req, "test_file_link", O_RDWR, 0, NULL);
1139
+ ASSERT(r != -1);
1140
+ ASSERT(req.result != -1);
1141
+ link = req.result;
1142
+ uv_fs_req_cleanup(&req);
1143
+
1144
+ memset(buf, 0, sizeof(buf));
1145
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1146
+ ASSERT(r != -1);
1147
+ ASSERT(req.result != -1);
1148
+ ASSERT(strcmp(buf, test_buf) == 0);
1149
+
1150
+ close(link);
1151
+
1152
+ /* async link */
1153
+ r = uv_fs_link(loop, &req, "test_file", "test_file_link2", link_cb);
1154
+ ASSERT(r == 0);
1155
+ uv_run(loop);
1156
+ ASSERT(link_cb_count == 1);
1157
+
1158
+ r = uv_fs_open(loop, &req, "test_file_link2", O_RDWR, 0, NULL);
1159
+ ASSERT(r != -1);
1160
+ ASSERT(req.result != -1);
1161
+ link = req.result;
1162
+ uv_fs_req_cleanup(&req);
1163
+
1164
+ memset(buf, 0, sizeof(buf));
1165
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1166
+ ASSERT(r != -1);
1167
+ ASSERT(req.result != -1);
1168
+ ASSERT(strcmp(buf, test_buf) == 0);
1169
+
1170
+ close(link);
1171
+
1172
+ /*
1173
+ * Run the loop just to check we don't have make any extraneous uv_ref()
1174
+ * calls. This should drop out immediately.
1175
+ */
1176
+ uv_run(loop);
1177
+
1178
+ /* Cleanup. */
1179
+ unlink("test_file");
1180
+ unlink("test_file_link");
1181
+ unlink("test_file_link2");
1182
+
1183
+ return 0;
1184
+ }
1185
+
1186
+
1187
+ TEST_IMPL(fs_symlink) {
1188
+ int r;
1189
+ uv_fs_t req;
1190
+ uv_file file;
1191
+ uv_file link;
1192
+
1193
+ /* Setup. */
1194
+ unlink("test_file");
1195
+ unlink("test_file_symlink");
1196
+ unlink("test_file_symlink2");
1197
+ unlink("test_file_symlink_symlink");
1198
+ unlink("test_file_symlink2_symlink");
1199
+
1200
+ loop = uv_default_loop();
1201
+
1202
+ r = uv_fs_open(loop, &req, "test_file", O_RDWR | O_CREAT,
1203
+ S_IWRITE | S_IREAD, NULL);
1204
+ ASSERT(r != -1);
1205
+ ASSERT(req.result != -1);
1206
+ file = req.result;
1207
+ uv_fs_req_cleanup(&req);
1208
+
1209
+ r = uv_fs_write(loop, &req, file, test_buf, sizeof(test_buf), -1, NULL);
1210
+ ASSERT(r == sizeof(test_buf));
1211
+ ASSERT(req.result == sizeof(test_buf));
1212
+ uv_fs_req_cleanup(&req);
1213
+
1214
+ close(file);
1215
+
1216
+ /* sync symlink */
1217
+ r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink", 0, NULL);
1218
+ #ifdef _WIN32
1219
+ if (r == -1) {
1220
+ if (uv_last_error(loop).code == UV_ENOTSUP) {
1221
+ /*
1222
+ * Windows doesn't support symlinks on older versions.
1223
+ * We just pass the test and bail out early if we get ENOTSUP.
1224
+ */
1225
+ return 0;
1226
+ } else if (uv_last_error(loop).sys_errno_ == ERROR_PRIVILEGE_NOT_HELD) {
1227
+ /*
1228
+ * Creating a symlink is only allowed when running elevated.
1229
+ * We pass the test and bail out early if we get ERROR_PRIVILEGE_NOT_HELD.
1230
+ */
1231
+ return 0;
1232
+ }
1233
+ }
1234
+ #endif
1235
+ ASSERT(r == 0);
1236
+ ASSERT(req.result == 0);
1237
+ uv_fs_req_cleanup(&req);
1238
+
1239
+ r = uv_fs_open(loop, &req, "test_file_symlink", O_RDWR, 0, NULL);
1240
+ ASSERT(r != -1);
1241
+ ASSERT(req.result != -1);
1242
+ link = req.result;
1243
+ uv_fs_req_cleanup(&req);
1244
+
1245
+ memset(buf, 0, sizeof(buf));
1246
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1247
+ ASSERT(r != -1);
1248
+ ASSERT(req.result != -1);
1249
+ ASSERT(strcmp(buf, test_buf) == 0);
1250
+
1251
+ close(link);
1252
+
1253
+ r = uv_fs_symlink(loop, &req, "test_file_symlink", "test_file_symlink_symlink", 0, NULL);
1254
+ ASSERT(r != -1);
1255
+ r = uv_fs_readlink(loop, &req, "test_file_symlink_symlink", NULL);
1256
+ ASSERT(r != -1);
1257
+ ASSERT(strcmp(req.ptr, "test_file_symlink") == 0);
1258
+ uv_fs_req_cleanup(&req);
1259
+
1260
+ /* async link */
1261
+ r = uv_fs_symlink(loop, &req, "test_file", "test_file_symlink2", 0, symlink_cb);
1262
+ ASSERT(r == 0);
1263
+ uv_run(loop);
1264
+ ASSERT(symlink_cb_count == 1);
1265
+
1266
+ r = uv_fs_open(loop, &req, "test_file_symlink2", O_RDWR, 0, NULL);
1267
+ ASSERT(r != -1);
1268
+ ASSERT(req.result != -1);
1269
+ link = req.result;
1270
+ uv_fs_req_cleanup(&req);
1271
+
1272
+ memset(buf, 0, sizeof(buf));
1273
+ r = uv_fs_read(loop, &req, link, buf, sizeof(buf), 0, NULL);
1274
+ ASSERT(r != -1);
1275
+ ASSERT(req.result != -1);
1276
+ ASSERT(strcmp(buf, test_buf) == 0);
1277
+
1278
+ close(link);
1279
+
1280
+ r = uv_fs_symlink(loop, &req, "test_file_symlink2", "test_file_symlink2_symlink", 0, NULL);
1281
+ ASSERT(r != -1);
1282
+ r = uv_fs_readlink(loop, &req, "test_file_symlink2_symlink", readlink_cb);
1283
+ ASSERT(r != -1);
1284
+ uv_run(loop);
1285
+ ASSERT(readlink_cb_count == 1);
1286
+
1287
+ /*
1288
+ * Run the loop just to check we don't have make any extraneous uv_ref()
1289
+ * calls. This should drop out immediately.
1290
+ */
1291
+ uv_run(loop);
1292
+
1293
+ /* Cleanup. */
1294
+ unlink("test_file");
1295
+ unlink("test_file_symlink");
1296
+ unlink("test_file_symlink_symlink");
1297
+ unlink("test_file_symlink2");
1298
+ unlink("test_file_symlink2_symlink");
1299
+
1300
+ return 0;
1301
+ }
1302
+
1303
+
1304
+ TEST_IMPL(fs_utime) {
1305
+ utime_check_t checkme;
1306
+ const char* path = "test_file";
1307
+ double atime;
1308
+ double mtime;
1309
+ uv_fs_t req;
1310
+ int r;
1311
+
1312
+ /* Setup. */
1313
+ loop = uv_default_loop();
1314
+ unlink(path);
1315
+ r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
1316
+ S_IWRITE | S_IREAD, NULL);
1317
+ ASSERT(r != -1);
1318
+ ASSERT(req.result != -1);
1319
+ uv_fs_req_cleanup(&req);
1320
+ close(r);
1321
+
1322
+ atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
1323
+
1324
+ r = uv_fs_utime(loop, &req, path, atime, mtime, NULL);
1325
+ ASSERT(r == 0);
1326
+ ASSERT(req.result == 0);
1327
+ uv_fs_req_cleanup(&req);
1328
+
1329
+ r = uv_fs_stat(loop, &req, path, NULL);
1330
+ ASSERT(r == 0);
1331
+ ASSERT(req.result == 0);
1332
+ check_utime(path, atime, mtime);
1333
+ uv_fs_req_cleanup(&req);
1334
+
1335
+ atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
1336
+ checkme.path = path;
1337
+ checkme.atime = atime;
1338
+ checkme.mtime = mtime;
1339
+
1340
+ /* async utime */
1341
+ utime_req.data = &checkme;
1342
+ r = uv_fs_utime(loop, &utime_req, path, atime, mtime, utime_cb);
1343
+ ASSERT(r == 0);
1344
+ uv_run(loop);
1345
+ ASSERT(utime_cb_count == 1);
1346
+
1347
+ /* Cleanup. */
1348
+ unlink(path);
1349
+
1350
+ return 0;
1351
+ }
1352
+
1353
+
1354
+ #ifdef _WIN32
1355
+ TEST_IMPL(fs_stat_root) {
1356
+ int r;
1357
+ uv_loop_t* loop = uv_default_loop();
1358
+
1359
+ r = uv_fs_stat(loop, &stat_req, "\\", NULL);
1360
+ ASSERT(r == 0);
1361
+
1362
+ r = uv_fs_stat(loop, &stat_req, "..\\..\\..\\..\\..\\..\\..", NULL);
1363
+ ASSERT(r == 0);
1364
+
1365
+ r = uv_fs_stat(loop, &stat_req, "..", NULL);
1366
+ ASSERT(r == 0);
1367
+
1368
+ r = uv_fs_stat(loop, &stat_req, "..\\", NULL);
1369
+ ASSERT(r == 0);
1370
+
1371
+ /* stats the current directory on c: */
1372
+ r = uv_fs_stat(loop, &stat_req, "c:", NULL);
1373
+ ASSERT(r == 0);
1374
+
1375
+ r = uv_fs_stat(loop, &stat_req, "c:\\", NULL);
1376
+ ASSERT(r == 0);
1377
+
1378
+ r = uv_fs_stat(loop, &stat_req, "\\\\?\\C:\\", NULL);
1379
+ ASSERT(r == 0);
1380
+
1381
+ return 0;
1382
+ }
1383
+ #endif
1384
+
1385
+
1386
+ TEST_IMPL(fs_futime) {
1387
+ utime_check_t checkme;
1388
+ const char* path = "test_file";
1389
+ double atime;
1390
+ double mtime;
1391
+ uv_file file;
1392
+ uv_fs_t req;
1393
+ int r;
1394
+
1395
+ /* Setup. */
1396
+ loop = uv_default_loop();
1397
+ unlink(path);
1398
+ r = uv_fs_open(loop, &req, path, O_RDWR | O_CREAT,
1399
+ S_IWRITE | S_IREAD, NULL);
1400
+ ASSERT(r != -1);
1401
+ ASSERT(req.result != -1);
1402
+ uv_fs_req_cleanup(&req);
1403
+ close(r);
1404
+
1405
+ atime = mtime = 400497753; /* 1982-09-10 11:22:33 */
1406
+
1407
+ r = uv_fs_open(loop, &req, path, O_RDWR, 0, NULL);
1408
+ ASSERT(r != -1);
1409
+ ASSERT(req.result != -1);
1410
+ file = req.result; /* FIXME probably not how it's supposed to be used */
1411
+ uv_fs_req_cleanup(&req);
1412
+
1413
+ r = uv_fs_futime(loop, &req, file, atime, mtime, NULL);
1414
+ ASSERT(r == 0);
1415
+ ASSERT(req.result == 0);
1416
+ uv_fs_req_cleanup(&req);
1417
+
1418
+ r = uv_fs_stat(loop, &req, path, NULL);
1419
+ ASSERT(r == 0);
1420
+ ASSERT(req.result == 0);
1421
+ check_utime(path, atime, mtime);
1422
+ uv_fs_req_cleanup(&req);
1423
+
1424
+ atime = mtime = 1291404900; /* 2010-12-03 20:35:00 - mees <3 */
1425
+
1426
+ checkme.atime = atime;
1427
+ checkme.mtime = mtime;
1428
+ checkme.path = path;
1429
+
1430
+ /* async futime */
1431
+ futime_req.data = &checkme;
1432
+ r = uv_fs_futime(loop, &futime_req, file, atime, mtime, futime_cb);
1433
+ ASSERT(r == 0);
1434
+ uv_run(loop);
1435
+ ASSERT(futime_cb_count == 1);
1436
+
1437
+ /* Cleanup. */
1438
+ unlink(path);
1439
+
1440
+ return 0;
1441
+ }
1442
+
1443
+
1444
+ TEST_IMPL(fs_stat_missing_path) {
1445
+ uv_fs_t req;
1446
+ int r;
1447
+
1448
+ loop = uv_default_loop();
1449
+
1450
+ r = uv_fs_stat(loop, &req, "non_existent_file", NULL);
1451
+ ASSERT(r == -1);
1452
+ ASSERT(req.result == -1);
1453
+ ASSERT(uv_last_error(loop).code == UV_ENOENT);
1454
+ uv_fs_req_cleanup(&req);
1455
+
1456
+ return 0;
1457
+ }
1458
+
1459
+
1460
+ TEST_IMPL(fs_readdir_empty_dir) {
1461
+ const char* path;
1462
+ uv_fs_t req;
1463
+ int r;
1464
+
1465
+ path = "./empty_dir/";
1466
+ loop = uv_default_loop();
1467
+
1468
+ uv_fs_mkdir(loop, &req, path, 0777, NULL);
1469
+ uv_fs_req_cleanup(&req);
1470
+
1471
+ r = uv_fs_readdir(loop, &req, path, 0, NULL);
1472
+ ASSERT(r == 0);
1473
+ ASSERT(req.result == 0);
1474
+ ASSERT(req.ptr == NULL);
1475
+ uv_fs_req_cleanup(&req);
1476
+
1477
+ r = uv_fs_readdir(loop, &readdir_req, path, 0, empty_readdir_cb);
1478
+ ASSERT(r == 0);
1479
+
1480
+ ASSERT(readdir_cb_count == 0);
1481
+ uv_run(loop);
1482
+ ASSERT(readdir_cb_count == 1);
1483
+
1484
+ uv_fs_rmdir(loop, &req, path, NULL);
1485
+ uv_fs_req_cleanup(&req);
1486
+
1487
+ return 0;
1488
+ }
1489
+
1490
+
1491
+ TEST_IMPL(fs_readdir_file) {
1492
+ const char* path;
1493
+ int r;
1494
+
1495
+ path = "test/fixtures/empty_file";
1496
+ loop = uv_default_loop();
1497
+
1498
+ r = uv_fs_readdir(loop, &readdir_req, path, 0, NULL);
1499
+ ASSERT(r == -1);
1500
+ ASSERT(uv_last_error(loop).code == UV_ENOTDIR);
1501
+
1502
+ r = uv_fs_readdir(loop, &readdir_req, path, 0, file_readdir_cb);
1503
+ ASSERT(r == 0);
1504
+
1505
+ ASSERT(readdir_cb_count == 0);
1506
+ uv_run(loop);
1507
+ ASSERT(readdir_cb_count == 1);
1508
+
1509
+ return 0;
1510
+ }
1511
+
1512
+
1513
+ TEST_IMPL(fs_open_dir) {
1514
+ const char* path;
1515
+ uv_fs_t req;
1516
+ int r, file;
1517
+
1518
+ path = ".";
1519
+ loop = uv_default_loop();
1520
+
1521
+ r = uv_fs_open(loop, &req, path, O_RDONLY, 0, NULL);
1522
+ ASSERT(r != -1);
1523
+ ASSERT(req.result != -1);
1524
+ ASSERT(req.ptr == NULL);
1525
+ file = r;
1526
+ uv_fs_req_cleanup(&req);
1527
+
1528
+ r = uv_fs_close(loop, &req, file, NULL);
1529
+ ASSERT(r == 0);
1530
+
1531
+ r = uv_fs_open(loop, &req, path, O_RDONLY, 0, open_cb_simple);
1532
+ ASSERT(r == 0);
1533
+
1534
+ ASSERT(open_cb_count == 0);
1535
+ uv_run(loop);
1536
+ ASSERT(open_cb_count == 1);
1537
+
1538
+ return 0;
1539
+ }
1540
+
1541
+
1542
+ TEST_IMPL(fs_file_open_append) {
1543
+ int r;
1544
+
1545
+ /* Setup. */
1546
+ unlink("test_file");
1547
+
1548
+ loop = uv_default_loop();
1549
+
1550
+ r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
1551
+ S_IWRITE | S_IREAD, NULL);
1552
+ ASSERT(r != -1);
1553
+ ASSERT(open_req1.result != -1);
1554
+ uv_fs_req_cleanup(&open_req1);
1555
+
1556
+ r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
1557
+ sizeof(test_buf), -1, NULL);
1558
+ ASSERT(r != -1);
1559
+ ASSERT(write_req.result != -1);
1560
+ uv_fs_req_cleanup(&write_req);
1561
+
1562
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1563
+ ASSERT(r != -1);
1564
+ ASSERT(close_req.result != -1);
1565
+ uv_fs_req_cleanup(&close_req);
1566
+
1567
+ r = uv_fs_open(loop, &open_req1, "test_file", O_RDWR | O_APPEND, 0, NULL);
1568
+ ASSERT(r != -1);
1569
+ ASSERT(open_req1.result != -1);
1570
+ uv_fs_req_cleanup(&open_req1);
1571
+
1572
+ r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
1573
+ sizeof(test_buf), -1, NULL);
1574
+ ASSERT(r != -1);
1575
+ ASSERT(write_req.result != -1);
1576
+ uv_fs_req_cleanup(&write_req);
1577
+
1578
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1579
+ ASSERT(r != -1);
1580
+ ASSERT(close_req.result != -1);
1581
+ uv_fs_req_cleanup(&close_req);
1582
+
1583
+ r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, S_IREAD, NULL);
1584
+ ASSERT(r != -1);
1585
+ ASSERT(open_req1.result != -1);
1586
+ uv_fs_req_cleanup(&open_req1);
1587
+
1588
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
1589
+ NULL);
1590
+ printf("read = %d\n", r);
1591
+ ASSERT(r == 26);
1592
+ ASSERT(read_req.result == 26);
1593
+ ASSERT(memcmp(buf,
1594
+ "test-buffer\n\0test-buffer\n\0",
1595
+ sizeof("test-buffer\n\0test-buffer\n\0") - 1) == 0);
1596
+ uv_fs_req_cleanup(&read_req);
1597
+
1598
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1599
+ ASSERT(r != -1);
1600
+ ASSERT(close_req.result != -1);
1601
+ uv_fs_req_cleanup(&close_req);
1602
+
1603
+ /* Cleanup */
1604
+ unlink("test_file");
1605
+
1606
+ return 0;
1607
+ }
1608
+
1609
+
1610
+ TEST_IMPL(fs_rename_to_existing_file) {
1611
+ int r;
1612
+
1613
+ /* Setup. */
1614
+ unlink("test_file");
1615
+ unlink("test_file2");
1616
+
1617
+ loop = uv_default_loop();
1618
+
1619
+ r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
1620
+ S_IWRITE | S_IREAD, NULL);
1621
+ ASSERT(r != -1);
1622
+ ASSERT(open_req1.result != -1);
1623
+ uv_fs_req_cleanup(&open_req1);
1624
+
1625
+ r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
1626
+ sizeof(test_buf), -1, NULL);
1627
+ ASSERT(r != -1);
1628
+ ASSERT(write_req.result != -1);
1629
+ uv_fs_req_cleanup(&write_req);
1630
+
1631
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1632
+ ASSERT(r != -1);
1633
+ ASSERT(close_req.result != -1);
1634
+ uv_fs_req_cleanup(&close_req);
1635
+
1636
+ r = uv_fs_open(loop, &open_req1, "test_file2", O_WRONLY | O_CREAT,
1637
+ S_IWRITE | S_IREAD, NULL);
1638
+ ASSERT(r != -1);
1639
+ ASSERT(open_req1.result != -1);
1640
+ uv_fs_req_cleanup(&open_req1);
1641
+
1642
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1643
+ ASSERT(r != -1);
1644
+ ASSERT(close_req.result != -1);
1645
+ uv_fs_req_cleanup(&close_req);
1646
+
1647
+ r = uv_fs_rename(loop, &rename_req, "test_file", "test_file2", NULL);
1648
+ ASSERT(r != -1);
1649
+ ASSERT(rename_req.result != -1);
1650
+ uv_fs_req_cleanup(&rename_req);
1651
+
1652
+ r = uv_fs_open(loop, &open_req1, "test_file2", O_RDONLY, 0, NULL);
1653
+ ASSERT(r != -1);
1654
+ ASSERT(open_req1.result != -1);
1655
+ uv_fs_req_cleanup(&open_req1);
1656
+
1657
+ memset(buf, 0, sizeof(buf));
1658
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
1659
+ NULL);
1660
+ ASSERT(r != -1);
1661
+ ASSERT(read_req.result != -1);
1662
+ ASSERT(strcmp(buf, test_buf) == 0);
1663
+ uv_fs_req_cleanup(&read_req);
1664
+
1665
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1666
+ ASSERT(r != -1);
1667
+ ASSERT(close_req.result != -1);
1668
+ uv_fs_req_cleanup(&close_req);
1669
+
1670
+ /* Cleanup */
1671
+ unlink("test_file");
1672
+ unlink("test_file2");
1673
+
1674
+ return 0;
1675
+ }
1676
+
1677
+
1678
+ TEST_IMPL(fs_read_file_eof) {
1679
+ int r;
1680
+
1681
+ /* Setup. */
1682
+ unlink("test_file");
1683
+
1684
+ loop = uv_default_loop();
1685
+
1686
+ r = uv_fs_open(loop, &open_req1, "test_file", O_WRONLY | O_CREAT,
1687
+ S_IWRITE | S_IREAD, NULL);
1688
+ ASSERT(r != -1);
1689
+ ASSERT(open_req1.result != -1);
1690
+ uv_fs_req_cleanup(&open_req1);
1691
+
1692
+ r = uv_fs_write(loop, &write_req, open_req1.result, test_buf,
1693
+ sizeof(test_buf), -1, NULL);
1694
+ ASSERT(r != -1);
1695
+ ASSERT(write_req.result != -1);
1696
+ uv_fs_req_cleanup(&write_req);
1697
+
1698
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1699
+ ASSERT(r != -1);
1700
+ ASSERT(close_req.result != -1);
1701
+ uv_fs_req_cleanup(&close_req);
1702
+
1703
+ r = uv_fs_open(loop, &open_req1, "test_file", O_RDONLY, 0, NULL);
1704
+ ASSERT(r != -1);
1705
+ ASSERT(open_req1.result != -1);
1706
+ uv_fs_req_cleanup(&open_req1);
1707
+
1708
+ memset(buf, 0, sizeof(buf));
1709
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf), -1,
1710
+ NULL);
1711
+ ASSERT(r != -1);
1712
+ ASSERT(read_req.result != -1);
1713
+ ASSERT(strcmp(buf, test_buf) == 0);
1714
+ uv_fs_req_cleanup(&read_req);
1715
+
1716
+ r = uv_fs_read(loop, &read_req, open_req1.result, buf, sizeof(buf),
1717
+ read_req.result, NULL);
1718
+ ASSERT(r == 0);
1719
+ ASSERT(read_req.result == 0);
1720
+ uv_fs_req_cleanup(&read_req);
1721
+
1722
+ r = uv_fs_close(loop, &close_req, open_req1.result, NULL);
1723
+ ASSERT(r != -1);
1724
+ ASSERT(close_req.result != -1);
1725
+ uv_fs_req_cleanup(&close_req);
1726
+
1727
+ /* Cleanup */
1728
+ unlink("test_file");
1729
+
1730
+ return 0;
1731
+ }