racer 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (336) hide show
  1. data/LICENSE +22 -0
  2. data/bin/racer +33 -0
  3. data/ext/libuv/AUTHORS +45 -0
  4. data/ext/libuv/LICENSE +42 -0
  5. data/ext/libuv/Makefile +119 -0
  6. data/ext/libuv/README.md +88 -0
  7. data/ext/libuv/build/gcc_version.py +20 -0
  8. data/ext/libuv/common.gypi +176 -0
  9. data/ext/libuv/config-mingw.mk +61 -0
  10. data/ext/libuv/config-unix.mk +171 -0
  11. data/ext/libuv/gyp_uv +64 -0
  12. data/ext/libuv/include/ares.h +591 -0
  13. data/ext/libuv/include/ares_version.h +24 -0
  14. data/ext/libuv/include/uv-private/eio.h +403 -0
  15. data/ext/libuv/include/uv-private/ev.h +838 -0
  16. data/ext/libuv/include/uv-private/ngx-queue.h +108 -0
  17. data/ext/libuv/include/uv-private/tree.h +768 -0
  18. data/ext/libuv/include/uv-private/uv-unix.h +310 -0
  19. data/ext/libuv/include/uv-private/uv-win.h +510 -0
  20. data/ext/libuv/include/uv.h +1796 -0
  21. data/ext/libuv/src/ares/AUTHORS +37 -0
  22. data/ext/libuv/src/ares/CHANGES +1218 -0
  23. data/ext/libuv/src/ares/CMakeLists.txt +22 -0
  24. data/ext/libuv/src/ares/NEWS +21 -0
  25. data/ext/libuv/src/ares/README +60 -0
  26. data/ext/libuv/src/ares/README.cares +13 -0
  27. data/ext/libuv/src/ares/README.msvc +142 -0
  28. data/ext/libuv/src/ares/README.node +21 -0
  29. data/ext/libuv/src/ares/RELEASE-NOTES +26 -0
  30. data/ext/libuv/src/ares/TODO +23 -0
  31. data/ext/libuv/src/ares/ares__close_sockets.c +66 -0
  32. data/ext/libuv/src/ares/ares__get_hostent.c +263 -0
  33. data/ext/libuv/src/ares/ares__read_line.c +71 -0
  34. data/ext/libuv/src/ares/ares__timeval.c +111 -0
  35. data/ext/libuv/src/ares/ares_cancel.c +63 -0
  36. data/ext/libuv/src/ares/ares_data.c +190 -0
  37. data/ext/libuv/src/ares/ares_data.h +65 -0
  38. data/ext/libuv/src/ares/ares_destroy.c +105 -0
  39. data/ext/libuv/src/ares/ares_dns.h +90 -0
  40. data/ext/libuv/src/ares/ares_expand_name.c +200 -0
  41. data/ext/libuv/src/ares/ares_expand_string.c +75 -0
  42. data/ext/libuv/src/ares/ares_fds.c +63 -0
  43. data/ext/libuv/src/ares/ares_free_hostent.c +42 -0
  44. data/ext/libuv/src/ares/ares_free_string.c +25 -0
  45. data/ext/libuv/src/ares/ares_getenv.c +30 -0
  46. data/ext/libuv/src/ares/ares_getenv.h +26 -0
  47. data/ext/libuv/src/ares/ares_gethostbyaddr.c +301 -0
  48. data/ext/libuv/src/ares/ares_gethostbyname.c +523 -0
  49. data/ext/libuv/src/ares/ares_getnameinfo.c +427 -0
  50. data/ext/libuv/src/ares/ares_getopt.c +122 -0
  51. data/ext/libuv/src/ares/ares_getopt.h +53 -0
  52. data/ext/libuv/src/ares/ares_getsock.c +72 -0
  53. data/ext/libuv/src/ares/ares_init.c +1809 -0
  54. data/ext/libuv/src/ares/ares_iphlpapi.h +221 -0
  55. data/ext/libuv/src/ares/ares_ipv6.h +78 -0
  56. data/ext/libuv/src/ares/ares_library_init.c +142 -0
  57. data/ext/libuv/src/ares/ares_library_init.h +42 -0
  58. data/ext/libuv/src/ares/ares_llist.c +86 -0
  59. data/ext/libuv/src/ares/ares_llist.h +42 -0
  60. data/ext/libuv/src/ares/ares_mkquery.c +195 -0
  61. data/ext/libuv/src/ares/ares_nowarn.c +181 -0
  62. data/ext/libuv/src/ares/ares_nowarn.h +55 -0
  63. data/ext/libuv/src/ares/ares_options.c +248 -0
  64. data/ext/libuv/src/ares/ares_parse_a_reply.c +263 -0
  65. data/ext/libuv/src/ares/ares_parse_aaaa_reply.c +259 -0
  66. data/ext/libuv/src/ares/ares_parse_mx_reply.c +170 -0
  67. data/ext/libuv/src/ares/ares_parse_ns_reply.c +182 -0
  68. data/ext/libuv/src/ares/ares_parse_ptr_reply.c +217 -0
  69. data/ext/libuv/src/ares/ares_parse_srv_reply.c +179 -0
  70. data/ext/libuv/src/ares/ares_parse_txt_reply.c +201 -0
  71. data/ext/libuv/src/ares/ares_platform.c +11035 -0
  72. data/ext/libuv/src/ares/ares_platform.h +43 -0
  73. data/ext/libuv/src/ares/ares_private.h +355 -0
  74. data/ext/libuv/src/ares/ares_process.c +1295 -0
  75. data/ext/libuv/src/ares/ares_query.c +183 -0
  76. data/ext/libuv/src/ares/ares_rules.h +144 -0
  77. data/ext/libuv/src/ares/ares_search.c +321 -0
  78. data/ext/libuv/src/ares/ares_send.c +134 -0
  79. data/ext/libuv/src/ares/ares_setup.h +199 -0
  80. data/ext/libuv/src/ares/ares_strcasecmp.c +66 -0
  81. data/ext/libuv/src/ares/ares_strcasecmp.h +30 -0
  82. data/ext/libuv/src/ares/ares_strdup.c +42 -0
  83. data/ext/libuv/src/ares/ares_strdup.h +26 -0
  84. data/ext/libuv/src/ares/ares_strerror.c +56 -0
  85. data/ext/libuv/src/ares/ares_timeout.c +80 -0
  86. data/ext/libuv/src/ares/ares_version.c +11 -0
  87. data/ext/libuv/src/ares/ares_writev.c +79 -0
  88. data/ext/libuv/src/ares/ares_writev.h +36 -0
  89. data/ext/libuv/src/ares/bitncmp.c +59 -0
  90. data/ext/libuv/src/ares/bitncmp.h +26 -0
  91. data/ext/libuv/src/ares/config_cygwin/ares_config.h +512 -0
  92. data/ext/libuv/src/ares/config_darwin/ares_config.h +512 -0
  93. data/ext/libuv/src/ares/config_freebsd/ares_config.h +512 -0
  94. data/ext/libuv/src/ares/config_linux/ares_config.h +512 -0
  95. data/ext/libuv/src/ares/config_netbsd/ares_config.h +512 -0
  96. data/ext/libuv/src/ares/config_openbsd/ares_config.h +512 -0
  97. data/ext/libuv/src/ares/config_sunos/ares_config.h +512 -0
  98. data/ext/libuv/src/ares/config_win32/ares_config.h +369 -0
  99. data/ext/libuv/src/ares/get_ver.awk +35 -0
  100. data/ext/libuv/src/ares/inet_net_pton.c +451 -0
  101. data/ext/libuv/src/ares/inet_net_pton.h +31 -0
  102. data/ext/libuv/src/ares/inet_ntop.c +208 -0
  103. data/ext/libuv/src/ares/inet_ntop.h +26 -0
  104. data/ext/libuv/src/ares/nameser.h +203 -0
  105. data/ext/libuv/src/ares/setup_once.h +504 -0
  106. data/ext/libuv/src/ares/windows_port.c +22 -0
  107. data/ext/libuv/src/cares.c +225 -0
  108. data/ext/libuv/src/fs-poll.c +237 -0
  109. data/ext/libuv/src/unix/async.c +119 -0
  110. data/ext/libuv/src/unix/core.c +647 -0
  111. data/ext/libuv/src/unix/cygwin.c +84 -0
  112. data/ext/libuv/src/unix/darwin.c +341 -0
  113. data/ext/libuv/src/unix/dl.c +83 -0
  114. data/ext/libuv/src/unix/eio/Changes +63 -0
  115. data/ext/libuv/src/unix/eio/LICENSE +36 -0
  116. data/ext/libuv/src/unix/eio/Makefile.am +15 -0
  117. data/ext/libuv/src/unix/eio/aclocal.m4 +8957 -0
  118. data/ext/libuv/src/unix/eio/autogen.sh +3 -0
  119. data/ext/libuv/src/unix/eio/config.h.in +86 -0
  120. data/ext/libuv/src/unix/eio/config_cygwin.h +80 -0
  121. data/ext/libuv/src/unix/eio/config_darwin.h +141 -0
  122. data/ext/libuv/src/unix/eio/config_freebsd.h +81 -0
  123. data/ext/libuv/src/unix/eio/config_linux.h +94 -0
  124. data/ext/libuv/src/unix/eio/config_netbsd.h +81 -0
  125. data/ext/libuv/src/unix/eio/config_openbsd.h +137 -0
  126. data/ext/libuv/src/unix/eio/config_sunos.h +84 -0
  127. data/ext/libuv/src/unix/eio/configure.ac +22 -0
  128. data/ext/libuv/src/unix/eio/demo.c +194 -0
  129. data/ext/libuv/src/unix/eio/ecb.h +370 -0
  130. data/ext/libuv/src/unix/eio/eio.3 +3428 -0
  131. data/ext/libuv/src/unix/eio/eio.c +2593 -0
  132. data/ext/libuv/src/unix/eio/eio.pod +969 -0
  133. data/ext/libuv/src/unix/eio/libeio.m4 +195 -0
  134. data/ext/libuv/src/unix/eio/xthread.h +164 -0
  135. data/ext/libuv/src/unix/error.c +104 -0
  136. data/ext/libuv/src/unix/ev/Changes +388 -0
  137. data/ext/libuv/src/unix/ev/LICENSE +36 -0
  138. data/ext/libuv/src/unix/ev/Makefile.am +18 -0
  139. data/ext/libuv/src/unix/ev/Makefile.in +771 -0
  140. data/ext/libuv/src/unix/ev/README +58 -0
  141. data/ext/libuv/src/unix/ev/aclocal.m4 +8957 -0
  142. data/ext/libuv/src/unix/ev/autogen.sh +6 -0
  143. data/ext/libuv/src/unix/ev/config.guess +1526 -0
  144. data/ext/libuv/src/unix/ev/config.h.in +125 -0
  145. data/ext/libuv/src/unix/ev/config.sub +1658 -0
  146. data/ext/libuv/src/unix/ev/config_cygwin.h +123 -0
  147. data/ext/libuv/src/unix/ev/config_darwin.h +122 -0
  148. data/ext/libuv/src/unix/ev/config_freebsd.h +120 -0
  149. data/ext/libuv/src/unix/ev/config_linux.h +141 -0
  150. data/ext/libuv/src/unix/ev/config_netbsd.h +120 -0
  151. data/ext/libuv/src/unix/ev/config_openbsd.h +126 -0
  152. data/ext/libuv/src/unix/ev/config_sunos.h +122 -0
  153. data/ext/libuv/src/unix/ev/configure +13037 -0
  154. data/ext/libuv/src/unix/ev/configure.ac +18 -0
  155. data/ext/libuv/src/unix/ev/depcomp +630 -0
  156. data/ext/libuv/src/unix/ev/ev++.h +816 -0
  157. data/ext/libuv/src/unix/ev/ev.3 +5311 -0
  158. data/ext/libuv/src/unix/ev/ev.c +3925 -0
  159. data/ext/libuv/src/unix/ev/ev.pod +5243 -0
  160. data/ext/libuv/src/unix/ev/ev_epoll.c +266 -0
  161. data/ext/libuv/src/unix/ev/ev_kqueue.c +235 -0
  162. data/ext/libuv/src/unix/ev/ev_poll.c +148 -0
  163. data/ext/libuv/src/unix/ev/ev_port.c +179 -0
  164. data/ext/libuv/src/unix/ev/ev_select.c +310 -0
  165. data/ext/libuv/src/unix/ev/ev_vars.h +203 -0
  166. data/ext/libuv/src/unix/ev/ev_win32.c +153 -0
  167. data/ext/libuv/src/unix/ev/ev_wrap.h +196 -0
  168. data/ext/libuv/src/unix/ev/event.c +402 -0
  169. data/ext/libuv/src/unix/ev/event.h +170 -0
  170. data/ext/libuv/src/unix/ev/install-sh +294 -0
  171. data/ext/libuv/src/unix/ev/libev.m4 +39 -0
  172. data/ext/libuv/src/unix/ev/ltmain.sh +8413 -0
  173. data/ext/libuv/src/unix/ev/missing +336 -0
  174. data/ext/libuv/src/unix/ev/mkinstalldirs +111 -0
  175. data/ext/libuv/src/unix/freebsd.c +312 -0
  176. data/ext/libuv/src/unix/fs.c +699 -0
  177. data/ext/libuv/src/unix/internal.h +180 -0
  178. data/ext/libuv/src/unix/kqueue.c +122 -0
  179. data/ext/libuv/src/unix/linux/core.c +474 -0
  180. data/ext/libuv/src/unix/linux/inotify.c +209 -0
  181. data/ext/libuv/src/unix/linux/syscalls.c +268 -0
  182. data/ext/libuv/src/unix/linux/syscalls.h +93 -0
  183. data/ext/libuv/src/unix/loop-watcher.c +63 -0
  184. data/ext/libuv/src/unix/loop.c +81 -0
  185. data/ext/libuv/src/unix/netbsd.c +108 -0
  186. data/ext/libuv/src/unix/openbsd.c +295 -0
  187. data/ext/libuv/src/unix/pipe.c +261 -0
  188. data/ext/libuv/src/unix/poll.c +116 -0
  189. data/ext/libuv/src/unix/process.c +447 -0
  190. data/ext/libuv/src/unix/stream.c +1026 -0
  191. data/ext/libuv/src/unix/sunos.c +483 -0
  192. data/ext/libuv/src/unix/tcp.c +328 -0
  193. data/ext/libuv/src/unix/thread.c +211 -0
  194. data/ext/libuv/src/unix/timer.c +138 -0
  195. data/ext/libuv/src/unix/tty.c +146 -0
  196. data/ext/libuv/src/unix/udp.c +661 -0
  197. data/ext/libuv/src/unix/uv-eio.c +107 -0
  198. data/ext/libuv/src/unix/uv-eio.h +13 -0
  199. data/ext/libuv/src/uv-common.c +384 -0
  200. data/ext/libuv/src/uv-common.h +171 -0
  201. data/ext/libuv/src/win/async.c +130 -0
  202. data/ext/libuv/src/win/core.c +283 -0
  203. data/ext/libuv/src/win/dl.c +86 -0
  204. data/ext/libuv/src/win/error.c +150 -0
  205. data/ext/libuv/src/win/fs-event.c +512 -0
  206. data/ext/libuv/src/win/fs.c +1856 -0
  207. data/ext/libuv/src/win/getaddrinfo.c +365 -0
  208. data/ext/libuv/src/win/handle-inl.h +145 -0
  209. data/ext/libuv/src/win/handle.c +150 -0
  210. data/ext/libuv/src/win/internal.h +337 -0
  211. data/ext/libuv/src/win/loop-watcher.c +123 -0
  212. data/ext/libuv/src/win/pipe.c +1675 -0
  213. data/ext/libuv/src/win/poll.c +618 -0
  214. data/ext/libuv/src/win/process-stdio.c +479 -0
  215. data/ext/libuv/src/win/process.c +1013 -0
  216. data/ext/libuv/src/win/req-inl.h +225 -0
  217. data/ext/libuv/src/win/req.c +25 -0
  218. data/ext/libuv/src/win/stream-inl.h +69 -0
  219. data/ext/libuv/src/win/stream.c +167 -0
  220. data/ext/libuv/src/win/tcp.c +1400 -0
  221. data/ext/libuv/src/win/thread.c +372 -0
  222. data/ext/libuv/src/win/threadpool.c +74 -0
  223. data/ext/libuv/src/win/timer.c +226 -0
  224. data/ext/libuv/src/win/tty.c +1801 -0
  225. data/ext/libuv/src/win/udp.c +718 -0
  226. data/ext/libuv/src/win/util.c +864 -0
  227. data/ext/libuv/src/win/winapi.c +132 -0
  228. data/ext/libuv/src/win/winapi.h +4443 -0
  229. data/ext/libuv/src/win/winsock.c +557 -0
  230. data/ext/libuv/src/win/winsock.h +171 -0
  231. data/ext/libuv/test/benchmark-ares.c +117 -0
  232. data/ext/libuv/test/benchmark-fs-stat.c +164 -0
  233. data/ext/libuv/test/benchmark-getaddrinfo.c +94 -0
  234. data/ext/libuv/test/benchmark-list.h +114 -0
  235. data/ext/libuv/test/benchmark-loop-count.c +88 -0
  236. data/ext/libuv/test/benchmark-million-timers.c +65 -0
  237. data/ext/libuv/test/benchmark-ping-pongs.c +213 -0
  238. data/ext/libuv/test/benchmark-pound.c +324 -0
  239. data/ext/libuv/test/benchmark-pump.c +462 -0
  240. data/ext/libuv/test/benchmark-sizes.c +42 -0
  241. data/ext/libuv/test/benchmark-spawn.c +162 -0
  242. data/ext/libuv/test/benchmark-tcp-write-batch.c +140 -0
  243. data/ext/libuv/test/benchmark-thread.c +64 -0
  244. data/ext/libuv/test/benchmark-udp-packet-storm.c +247 -0
  245. data/ext/libuv/test/blackhole-server.c +118 -0
  246. data/ext/libuv/test/dns-server.c +321 -0
  247. data/ext/libuv/test/echo-server.c +378 -0
  248. data/ext/libuv/test/fixtures/empty_file +0 -0
  249. data/ext/libuv/test/fixtures/load_error.node +1 -0
  250. data/ext/libuv/test/run-benchmarks.c +64 -0
  251. data/ext/libuv/test/run-tests.c +138 -0
  252. data/ext/libuv/test/runner-unix.c +290 -0
  253. data/ext/libuv/test/runner-unix.h +36 -0
  254. data/ext/libuv/test/runner-win.c +285 -0
  255. data/ext/libuv/test/runner-win.h +42 -0
  256. data/ext/libuv/test/runner.c +326 -0
  257. data/ext/libuv/test/runner.h +159 -0
  258. data/ext/libuv/test/task.h +109 -0
  259. data/ext/libuv/test/test-async.c +118 -0
  260. data/ext/libuv/test/test-callback-order.c +76 -0
  261. data/ext/libuv/test/test-callback-stack.c +203 -0
  262. data/ext/libuv/test/test-connection-fail.c +148 -0
  263. data/ext/libuv/test/test-counters-init.c +215 -0
  264. data/ext/libuv/test/test-cwd-and-chdir.c +64 -0
  265. data/ext/libuv/test/test-delayed-accept.c +197 -0
  266. data/ext/libuv/test/test-dlerror.c +58 -0
  267. data/ext/libuv/test/test-error.c +59 -0
  268. data/ext/libuv/test/test-fail-always.c +29 -0
  269. data/ext/libuv/test/test-fs-event.c +442 -0
  270. data/ext/libuv/test/test-fs-poll.c +146 -0
  271. data/ext/libuv/test/test-fs.c +1843 -0
  272. data/ext/libuv/test/test-get-currentexe.c +63 -0
  273. data/ext/libuv/test/test-get-loadavg.c +36 -0
  274. data/ext/libuv/test/test-get-memory.c +38 -0
  275. data/ext/libuv/test/test-getaddrinfo.c +122 -0
  276. data/ext/libuv/test/test-gethostbyname.c +189 -0
  277. data/ext/libuv/test/test-getsockname.c +342 -0
  278. data/ext/libuv/test/test-hrtime.c +54 -0
  279. data/ext/libuv/test/test-idle.c +81 -0
  280. data/ext/libuv/test/test-ipc-send-recv.c +209 -0
  281. data/ext/libuv/test/test-ipc.c +620 -0
  282. data/ext/libuv/test/test-list.h +421 -0
  283. data/ext/libuv/test/test-loop-handles.c +336 -0
  284. data/ext/libuv/test/test-multiple-listen.c +102 -0
  285. data/ext/libuv/test/test-mutexes.c +63 -0
  286. data/ext/libuv/test/test-pass-always.c +28 -0
  287. data/ext/libuv/test/test-ping-pong.c +253 -0
  288. data/ext/libuv/test/test-pipe-bind-error.c +140 -0
  289. data/ext/libuv/test/test-pipe-connect-error.c +96 -0
  290. data/ext/libuv/test/test-platform-output.c +87 -0
  291. data/ext/libuv/test/test-poll-close.c +77 -0
  292. data/ext/libuv/test/test-poll.c +573 -0
  293. data/ext/libuv/test/test-process-title.c +42 -0
  294. data/ext/libuv/test/test-ref.c +338 -0
  295. data/ext/libuv/test/test-run-once.c +48 -0
  296. data/ext/libuv/test/test-semaphore.c +111 -0
  297. data/ext/libuv/test/test-shutdown-close.c +103 -0
  298. data/ext/libuv/test/test-shutdown-eof.c +183 -0
  299. data/ext/libuv/test/test-spawn.c +847 -0
  300. data/ext/libuv/test/test-stdio-over-pipes.c +246 -0
  301. data/ext/libuv/test/test-tcp-bind-error.c +191 -0
  302. data/ext/libuv/test/test-tcp-bind6-error.c +154 -0
  303. data/ext/libuv/test/test-tcp-close-while-connecting.c +80 -0
  304. data/ext/libuv/test/test-tcp-close.c +129 -0
  305. data/ext/libuv/test/test-tcp-connect-error-after-write.c +95 -0
  306. data/ext/libuv/test/test-tcp-connect-error.c +70 -0
  307. data/ext/libuv/test/test-tcp-connect-timeout.c +85 -0
  308. data/ext/libuv/test/test-tcp-connect6-error.c +68 -0
  309. data/ext/libuv/test/test-tcp-flags.c +51 -0
  310. data/ext/libuv/test/test-tcp-shutdown-after-write.c +131 -0
  311. data/ext/libuv/test/test-tcp-write-error.c +168 -0
  312. data/ext/libuv/test/test-tcp-write-to-half-open-connection.c +135 -0
  313. data/ext/libuv/test/test-tcp-writealot.c +170 -0
  314. data/ext/libuv/test/test-thread.c +183 -0
  315. data/ext/libuv/test/test-threadpool.c +57 -0
  316. data/ext/libuv/test/test-timer-again.c +141 -0
  317. data/ext/libuv/test/test-timer.c +152 -0
  318. data/ext/libuv/test/test-tty.c +110 -0
  319. data/ext/libuv/test/test-udp-dgram-too-big.c +86 -0
  320. data/ext/libuv/test/test-udp-ipv6.c +156 -0
  321. data/ext/libuv/test/test-udp-multicast-join.c +139 -0
  322. data/ext/libuv/test/test-udp-multicast-ttl.c +86 -0
  323. data/ext/libuv/test/test-udp-options.c +86 -0
  324. data/ext/libuv/test/test-udp-send-and-recv.c +208 -0
  325. data/ext/libuv/test/test-util.c +97 -0
  326. data/ext/libuv/test/test-walk-handles.c +77 -0
  327. data/ext/libuv/uv.gyp +452 -0
  328. data/ext/libuv/vcbuild.bat +105 -0
  329. data/ext/racer/extconf.rb +20 -0
  330. data/ext/racer/http_parser.c +2059 -0
  331. data/ext/racer/http_parser.h +318 -0
  332. data/ext/racer/mkmf.log +22 -0
  333. data/ext/racer/racer.c +551 -0
  334. data/lib/racer.rb +2 -0
  335. data/lib/racer/version.rb +3 -0
  336. metadata +382 -0
@@ -0,0 +1,1796 @@
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
+ /* See uv_loop_new for an introduction. */
23
+
24
+ #ifndef UV_H
25
+ #define UV_H
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ #ifdef _WIN32
31
+ /* Windows - set up dll import/export decorators. */
32
+ # if defined(BUILDING_UV_SHARED)
33
+ /* Building shared library. Export everything from c-ares as well. */
34
+ # define UV_EXTERN __declspec(dllexport)
35
+ # define CARES_BUILDING_LIBRARY 1
36
+ # elif defined(USING_UV_SHARED)
37
+ /* Using shared library. Use shared c-ares as well. */
38
+ # define UV_EXTERN __declspec(dllimport)
39
+ # else
40
+ /* Building static library. Build c-ares statically as well. */
41
+ # define UV_EXTERN /* nothing */
42
+ # define CARES_STATICLIB 1
43
+ # endif
44
+ #elif __GNUC__ >= 4
45
+ # define UV_EXTERN __attribute__((visibility("default")))
46
+ #else
47
+ # define UV_EXTERN /* nothing */
48
+ #endif
49
+
50
+
51
+ #define UV_VERSION_MAJOR 0
52
+ #define UV_VERSION_MINOR 8
53
+
54
+
55
+ #include <stdint.h> /* int64_t */
56
+ #include <sys/types.h> /* size_t */
57
+
58
+ #include "ares.h"
59
+
60
+ #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
61
+ typedef intptr_t ssize_t;
62
+ # define _SSIZE_T_
63
+ # define _SSIZE_T_DEFINED
64
+ #endif
65
+
66
+ #if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__)
67
+ # include "uv-private/uv-unix.h"
68
+ #else
69
+ # include "uv-private/uv-win.h"
70
+ #endif
71
+
72
+ /* Expand this list if necessary. */
73
+ #define UV_ERRNO_MAP(XX) \
74
+ XX( -1, UNKNOWN, "unknown error") \
75
+ XX( 0, OK, "success") \
76
+ XX( 1, EOF, "end of file") \
77
+ XX( 2, EADDRINFO, "getaddrinfo error") \
78
+ XX( 3, EACCES, "permission denied") \
79
+ XX( 4, EAGAIN, "no more processes") \
80
+ XX( 5, EADDRINUSE, "address already in use") \
81
+ XX( 6, EADDRNOTAVAIL, "") \
82
+ XX( 7, EAFNOSUPPORT, "") \
83
+ XX( 8, EALREADY, "") \
84
+ XX( 9, EBADF, "bad file descriptor") \
85
+ XX( 10, EBUSY, "resource busy or locked") \
86
+ XX( 11, ECONNABORTED, "software caused connection abort") \
87
+ XX( 12, ECONNREFUSED, "connection refused") \
88
+ XX( 13, ECONNRESET, "connection reset by peer") \
89
+ XX( 14, EDESTADDRREQ, "destination address required") \
90
+ XX( 15, EFAULT, "bad address in system call argument") \
91
+ XX( 16, EHOSTUNREACH, "host is unreachable") \
92
+ XX( 17, EINTR, "interrupted system call") \
93
+ XX( 18, EINVAL, "invalid argument") \
94
+ XX( 19, EISCONN, "socket is already connected") \
95
+ XX( 20, EMFILE, "too many open files") \
96
+ XX( 21, EMSGSIZE, "message too long") \
97
+ XX( 22, ENETDOWN, "network is down") \
98
+ XX( 23, ENETUNREACH, "network is unreachable") \
99
+ XX( 24, ENFILE, "file table overflow") \
100
+ XX( 25, ENOBUFS, "no buffer space available") \
101
+ XX( 26, ENOMEM, "not enough memory") \
102
+ XX( 27, ENOTDIR, "not a directory") \
103
+ XX( 28, EISDIR, "illegal operation on a directory") \
104
+ XX( 29, ENONET, "machine is not on the network") \
105
+ XX( 31, ENOTCONN, "socket is not connected") \
106
+ XX( 32, ENOTSOCK, "socket operation on non-socket") \
107
+ XX( 33, ENOTSUP, "operation not supported on socket") \
108
+ XX( 34, ENOENT, "no such file or directory") \
109
+ XX( 35, ENOSYS, "function not implemented") \
110
+ XX( 36, EPIPE, "broken pipe") \
111
+ XX( 37, EPROTO, "protocol error") \
112
+ XX( 38, EPROTONOSUPPORT, "protocol not supported") \
113
+ XX( 39, EPROTOTYPE, "protocol wrong type for socket") \
114
+ XX( 40, ETIMEDOUT, "connection timed out") \
115
+ XX( 41, ECHARSET, "") \
116
+ XX( 42, EAIFAMNOSUPPORT, "") \
117
+ XX( 44, EAISERVICE, "") \
118
+ XX( 45, EAISOCKTYPE, "") \
119
+ XX( 46, ESHUTDOWN, "") \
120
+ XX( 47, EEXIST, "file already exists") \
121
+ XX( 48, ESRCH, "no such process") \
122
+ XX( 49, ENAMETOOLONG, "name too long") \
123
+ XX( 50, EPERM, "operation not permitted") \
124
+ XX( 51, ELOOP, "too many symbolic links encountered") \
125
+ XX( 52, EXDEV, "cross-device link not permitted") \
126
+ XX( 53, ENOTEMPTY, "directory not empty") \
127
+ XX( 54, ENOSPC, "no space left on device") \
128
+ XX( 55, EIO, "i/o error") \
129
+ XX( 56, EROFS, "read-only file system" )
130
+
131
+
132
+ #define UV_ERRNO_GEN(val, name, s) UV_##name = val,
133
+ typedef enum {
134
+ UV_ERRNO_MAP(UV_ERRNO_GEN)
135
+ UV_MAX_ERRORS
136
+ } uv_err_code;
137
+ #undef UV_ERRNO_GEN
138
+
139
+ #define UV_HANDLE_TYPE_MAP(XX) \
140
+ XX(ASYNC, async) \
141
+ XX(CHECK, check) \
142
+ XX(FS_EVENT, fs_event) \
143
+ XX(FS_POLL, fs_poll) \
144
+ XX(IDLE, idle) \
145
+ XX(NAMED_PIPE, pipe) \
146
+ XX(POLL, poll) \
147
+ XX(PREPARE, prepare) \
148
+ XX(PROCESS, process) \
149
+ XX(TCP, tcp) \
150
+ XX(TIMER, timer) \
151
+ XX(TTY, tty) \
152
+ XX(UDP, udp) \
153
+
154
+ #define UV_REQ_TYPE_MAP(XX) \
155
+ XX(CONNECT, connect) \
156
+ XX(WRITE, write) \
157
+ XX(SHUTDOWN, shutdown) \
158
+ XX(UDP_SEND, udp_send) \
159
+ XX(FS, fs) \
160
+ XX(WORK, work) \
161
+ XX(GETADDRINFO, getaddrinfo) \
162
+
163
+ typedef enum {
164
+ UV_UNKNOWN_HANDLE = 0,
165
+ #define XX(uc, lc) UV_##uc,
166
+ UV_HANDLE_TYPE_MAP(XX)
167
+ #undef XX
168
+ UV_ARES_TASK,
169
+ UV_FILE,
170
+ UV_HANDLE_TYPE_MAX
171
+ } uv_handle_type;
172
+
173
+ typedef enum {
174
+ UV_UNKNOWN_REQ = 0,
175
+ #define XX(uc, lc) UV_##uc,
176
+ UV_REQ_TYPE_MAP(XX)
177
+ #undef XX
178
+ UV_REQ_TYPE_PRIVATE
179
+ UV_REQ_TYPE_MAX
180
+ } uv_req_type;
181
+
182
+
183
+
184
+ typedef struct uv_loop_s uv_loop_t;
185
+ typedef struct uv_ares_task_s uv_ares_task_t;
186
+ typedef struct uv_err_s uv_err_t;
187
+ typedef struct uv_handle_s uv_handle_t;
188
+ typedef struct uv_stream_s uv_stream_t;
189
+ typedef struct uv_tcp_s uv_tcp_t;
190
+ typedef struct uv_udp_s uv_udp_t;
191
+ typedef struct uv_pipe_s uv_pipe_t;
192
+ typedef struct uv_tty_s uv_tty_t;
193
+ typedef struct uv_poll_s uv_poll_t;
194
+ typedef struct uv_timer_s uv_timer_t;
195
+ typedef struct uv_prepare_s uv_prepare_t;
196
+ typedef struct uv_check_s uv_check_t;
197
+ typedef struct uv_idle_s uv_idle_t;
198
+ typedef struct uv_async_s uv_async_t;
199
+ typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
200
+ typedef struct uv_process_s uv_process_t;
201
+ typedef struct uv_counters_s uv_counters_t;
202
+ typedef struct uv_cpu_info_s uv_cpu_info_t;
203
+ typedef struct uv_interface_address_s uv_interface_address_t;
204
+ /* Request types */
205
+ typedef struct uv_req_s uv_req_t;
206
+ typedef struct uv_shutdown_s uv_shutdown_t;
207
+ typedef struct uv_write_s uv_write_t;
208
+ typedef struct uv_connect_s uv_connect_t;
209
+ typedef struct uv_udp_send_s uv_udp_send_t;
210
+ typedef struct uv_fs_s uv_fs_t;
211
+ /* uv_fs_event_t is a subclass of uv_handle_t. */
212
+ typedef struct uv_fs_event_s uv_fs_event_t;
213
+ typedef struct uv_fs_poll_s uv_fs_poll_t;
214
+ typedef struct uv_work_s uv_work_t;
215
+
216
+
217
+ /*
218
+ * This function must be called before any other functions in libuv.
219
+ *
220
+ * All functions besides uv_run() are non-blocking.
221
+ *
222
+ * All callbacks in libuv are made asynchronously. That is they are never
223
+ * made by the function that takes them as a parameter.
224
+ */
225
+ UV_EXTERN uv_loop_t* uv_loop_new(void);
226
+ UV_EXTERN void uv_loop_delete(uv_loop_t*);
227
+
228
+ /*
229
+ * Returns the default loop.
230
+ */
231
+ UV_EXTERN uv_loop_t* uv_default_loop(void);
232
+
233
+ /*
234
+ * This function starts the event loop. It blocks until the reference count
235
+ * of the loop drops to zero. Always returns zero.
236
+ */
237
+ UV_EXTERN int uv_run(uv_loop_t*);
238
+
239
+ /*
240
+ * Poll for new events once. Note that this function blocks if there are no
241
+ * pending events. Returns zero when done (no active handles or requests left),
242
+ * or non-zero if more events are expected (meaning you should call
243
+ * uv_run_once() again sometime in the future).
244
+ */
245
+ UV_EXTERN int uv_run_once(uv_loop_t*);
246
+
247
+ /*
248
+ * Manually modify the event loop's reference count. Useful if the user wants
249
+ * to have a handle or timeout that doesn't keep the loop alive.
250
+ */
251
+ UV_EXTERN void uv_ref(uv_handle_t*);
252
+ UV_EXTERN void uv_unref(uv_handle_t*);
253
+
254
+ UV_EXTERN void uv_update_time(uv_loop_t*);
255
+ UV_EXTERN int64_t uv_now(uv_loop_t*);
256
+
257
+
258
+ /*
259
+ * Should return a buffer that libuv can use to read data into.
260
+ *
261
+ * `suggested_size` is a hint. Returning a buffer that is smaller is perfectly
262
+ * okay as long as `buf.len > 0`.
263
+ */
264
+ typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size);
265
+
266
+ /*
267
+ * `nread` is > 0 if there is data available, 0 if libuv is done reading for now
268
+ * or -1 on error.
269
+ *
270
+ * Error details can be obtained by calling uv_last_error(). UV_EOF indicates
271
+ * that the stream has been closed.
272
+ *
273
+ * The callee is responsible for closing the stream when an error happens.
274
+ * Trying to read from the stream again is undefined.
275
+ *
276
+ * The callee is responsible for freeing the buffer, libuv does not reuse it.
277
+ */
278
+ typedef void (*uv_read_cb)(uv_stream_t* stream, ssize_t nread, uv_buf_t buf);
279
+
280
+ /*
281
+ * Just like the uv_read_cb except that if the pending parameter is true
282
+ * then you can use uv_accept() to pull the new handle into the process.
283
+ * If no handle is pending then pending will be UV_UNKNOWN_HANDLE.
284
+ */
285
+ typedef void (*uv_read2_cb)(uv_pipe_t* pipe, ssize_t nread, uv_buf_t buf,
286
+ uv_handle_type pending);
287
+
288
+ typedef void (*uv_write_cb)(uv_write_t* req, int status);
289
+ typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
290
+ typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
291
+ typedef void (*uv_connection_cb)(uv_stream_t* server, int status);
292
+ typedef void (*uv_close_cb)(uv_handle_t* handle);
293
+ typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events);
294
+ typedef void (*uv_timer_cb)(uv_timer_t* handle, int status);
295
+ /* TODO: do these really need a status argument? */
296
+ typedef void (*uv_async_cb)(uv_async_t* handle, int status);
297
+ typedef void (*uv_prepare_cb)(uv_prepare_t* handle, int status);
298
+ typedef void (*uv_check_cb)(uv_check_t* handle, int status);
299
+ typedef void (*uv_idle_cb)(uv_idle_t* handle, int status);
300
+ typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* handle, int status,
301
+ struct addrinfo* res);
302
+ typedef void (*uv_exit_cb)(uv_process_t*, int exit_status, int term_signal);
303
+ typedef void (*uv_fs_cb)(uv_fs_t* req);
304
+ typedef void (*uv_work_cb)(uv_work_t* req);
305
+ typedef void (*uv_after_work_cb)(uv_work_t* req);
306
+ typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
307
+
308
+ /*
309
+ * This will be called repeatedly after the uv_fs_event_t is initialized.
310
+ * If uv_fs_event_t was initialized with a directory the filename parameter
311
+ * will be a relative path to a file contained in the directory.
312
+ * The events parameter is an ORed mask of enum uv_fs_event elements.
313
+ */
314
+ typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename,
315
+ int events, int status);
316
+
317
+ typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
318
+ int status,
319
+ const uv_statbuf_t* prev,
320
+ const uv_statbuf_t* curr);
321
+
322
+ typedef enum {
323
+ UV_LEAVE_GROUP = 0,
324
+ UV_JOIN_GROUP
325
+ } uv_membership;
326
+
327
+
328
+ struct uv_err_s {
329
+ /* read-only */
330
+ uv_err_code code;
331
+ /* private */
332
+ int sys_errno_;
333
+ };
334
+
335
+
336
+ /*
337
+ * Most functions return boolean: 0 for success and -1 for failure.
338
+ * On error the user should then call uv_last_error() to determine
339
+ * the error code.
340
+ */
341
+ UV_EXTERN uv_err_t uv_last_error(uv_loop_t*);
342
+ UV_EXTERN const char* uv_strerror(uv_err_t err);
343
+ UV_EXTERN const char* uv_err_name(uv_err_t err);
344
+
345
+
346
+ #define UV_REQ_FIELDS \
347
+ /* public */ \
348
+ void* data; \
349
+ /* private */ \
350
+ ngx_queue_t active_queue; \
351
+ UV_REQ_PRIVATE_FIELDS \
352
+ /* read-only */ \
353
+ uv_req_type type; \
354
+
355
+ /* Abstract base class of all requests. */
356
+ struct uv_req_s {
357
+ UV_REQ_FIELDS
358
+ };
359
+
360
+
361
+ /* Platform-specific request types */
362
+ UV_PRIVATE_REQ_TYPES
363
+
364
+
365
+ /*
366
+ * uv_shutdown_t is a subclass of uv_req_t
367
+ *
368
+ * Shutdown the outgoing (write) side of a duplex stream. It waits for
369
+ * pending write requests to complete. The handle should refer to a
370
+ * initialized stream. req should be an uninitialized shutdown request
371
+ * struct. The cb is called after shutdown is complete.
372
+ */
373
+ UV_EXTERN int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle,
374
+ uv_shutdown_cb cb);
375
+
376
+ struct uv_shutdown_s {
377
+ UV_REQ_FIELDS
378
+ uv_stream_t* handle;
379
+ uv_shutdown_cb cb;
380
+ UV_SHUTDOWN_PRIVATE_FIELDS
381
+ };
382
+
383
+
384
+ #define UV_HANDLE_FIELDS \
385
+ /* read-only */ \
386
+ uv_loop_t* loop; \
387
+ /* public */ \
388
+ uv_close_cb close_cb; \
389
+ void* data; \
390
+ /* read-only */ \
391
+ uv_handle_type type; \
392
+ /* private */ \
393
+ ngx_queue_t handle_queue; \
394
+ UV_HANDLE_PRIVATE_FIELDS \
395
+
396
+ /* The abstract base class of all handles. */
397
+ struct uv_handle_s {
398
+ UV_HANDLE_FIELDS
399
+ };
400
+
401
+ /*
402
+ * Returns size of various handle types, useful for FFI
403
+ * bindings to allocate correct memory without copying struct
404
+ * definitions
405
+ */
406
+ UV_EXTERN size_t uv_handle_size(uv_handle_type type);
407
+
408
+ /*
409
+ * Returns size of request types, useful for dynamic lookup with FFI
410
+ */
411
+ UV_EXTERN size_t uv_req_size(uv_req_type type);
412
+
413
+ /*
414
+ * Returns 1 if the prepare/check/idle/timer handle has been started, 0
415
+ * otherwise. For other handle types this always returns 1.
416
+ */
417
+ UV_EXTERN int uv_is_active(const uv_handle_t* handle);
418
+
419
+ /*
420
+ * Walk the list of open handles.
421
+ */
422
+ UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
423
+
424
+
425
+ /*
426
+ * Request handle to be closed. close_cb will be called asynchronously after
427
+ * this call. This MUST be called on each handle before memory is released.
428
+ *
429
+ * Note that handles that wrap file descriptors are closed immediately but
430
+ * close_cb will still be deferred to the next iteration of the event loop.
431
+ * It gives you a chance to free up any resources associated with the handle.
432
+ */
433
+ UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
434
+
435
+
436
+ /*
437
+ * Constructor for uv_buf_t.
438
+ * Due to platform differences the user cannot rely on the ordering of the
439
+ * base and len members of the uv_buf_t struct. The user is responsible for
440
+ * freeing base after the uv_buf_t is done. Return struct passed by value.
441
+ */
442
+ UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
443
+
444
+
445
+ /*
446
+ * Utility function. Copies up to `size` characters from `src` to `dst`
447
+ * and ensures that `dst` is properly NUL terminated unless `size` is zero.
448
+ */
449
+ UV_EXTERN size_t uv_strlcpy(char* dst, const char* src, size_t size);
450
+
451
+ /*
452
+ * Utility function. Appends `src` to `dst` and ensures that `dst` is
453
+ * properly NUL terminated unless `size` is zero or `dst` does not
454
+ * contain a NUL byte. `size` is the total length of `dst` so at most
455
+ * `size - strlen(dst) - 1` characters will be copied from `src`.
456
+ */
457
+ UV_EXTERN size_t uv_strlcat(char* dst, const char* src, size_t size);
458
+
459
+
460
+ #define UV_STREAM_FIELDS \
461
+ /* number of bytes queued for writing */ \
462
+ size_t write_queue_size; \
463
+ uv_alloc_cb alloc_cb; \
464
+ uv_read_cb read_cb; \
465
+ uv_read2_cb read2_cb; \
466
+ /* private */ \
467
+ UV_STREAM_PRIVATE_FIELDS
468
+
469
+ /*
470
+ * uv_stream_t is a subclass of uv_handle_t
471
+ *
472
+ * uv_stream is an abstract class.
473
+ *
474
+ * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t, uv_tty_t, and
475
+ * soon uv_file_t.
476
+ */
477
+ struct uv_stream_s {
478
+ UV_HANDLE_FIELDS
479
+ UV_STREAM_FIELDS
480
+ };
481
+
482
+ UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
483
+
484
+ /*
485
+ * This call is used in conjunction with uv_listen() to accept incoming
486
+ * connections. Call uv_accept after receiving a uv_connection_cb to accept
487
+ * the connection. Before calling uv_accept use uv_*_init() must be
488
+ * called on the client. Non-zero return value indicates an error.
489
+ *
490
+ * When the uv_connection_cb is called it is guaranteed that uv_accept will
491
+ * complete successfully the first time. If you attempt to use it more than
492
+ * once, it may fail. It is suggested to only call uv_accept once per
493
+ * uv_connection_cb call.
494
+ */
495
+ UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
496
+
497
+ /*
498
+ * Read data from an incoming stream. The callback will be made several
499
+ * several times until there is no more data to read or uv_read_stop is
500
+ * called. When we've reached EOF nread will be set to -1 and the error is
501
+ * set to UV_EOF. When nread == -1 the buf parameter might not point to a
502
+ * valid buffer; in that case buf.len and buf.base are both set to 0.
503
+ * Note that nread might also be 0, which does *not* indicate an error or
504
+ * eof; it happens when libuv requested a buffer through the alloc callback
505
+ * but then decided that it didn't need that buffer.
506
+ */
507
+ UV_EXTERN int uv_read_start(uv_stream_t*, uv_alloc_cb alloc_cb,
508
+ uv_read_cb read_cb);
509
+
510
+ UV_EXTERN int uv_read_stop(uv_stream_t*);
511
+
512
+ /*
513
+ * Extended read methods for receiving handles over a pipe. The pipe must be
514
+ * initialized with ipc == 1.
515
+ */
516
+ UV_EXTERN int uv_read2_start(uv_stream_t*, uv_alloc_cb alloc_cb,
517
+ uv_read2_cb read_cb);
518
+
519
+
520
+ /*
521
+ * Write data to stream. Buffers are written in order. Example:
522
+ *
523
+ * uv_buf_t a[] = {
524
+ * { .base = "1", .len = 1 },
525
+ * { .base = "2", .len = 1 }
526
+ * };
527
+ *
528
+ * uv_buf_t b[] = {
529
+ * { .base = "3", .len = 1 },
530
+ * { .base = "4", .len = 1 }
531
+ * };
532
+ *
533
+ * // writes "1234"
534
+ * uv_write(req, stream, a, 2);
535
+ * uv_write(req, stream, b, 2);
536
+ *
537
+ */
538
+ UV_EXTERN int uv_write(uv_write_t* req, uv_stream_t* handle,
539
+ uv_buf_t bufs[], int bufcnt, uv_write_cb cb);
540
+
541
+ /*
542
+ * Extended write function for sending handles over a pipe. The pipe must be
543
+ * initialized with ipc == 1.
544
+ * send_handle must be a TCP socket or pipe, which is a server or a connection
545
+ * (listening or connected state). Bound sockets or pipes will be assumed to
546
+ * be servers.
547
+ */
548
+ UV_EXTERN int uv_write2(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[],
549
+ int bufcnt, uv_stream_t* send_handle, uv_write_cb cb);
550
+
551
+ /* uv_write_t is a subclass of uv_req_t */
552
+ struct uv_write_s {
553
+ UV_REQ_FIELDS
554
+ uv_write_cb cb;
555
+ uv_stream_t* send_handle;
556
+ uv_stream_t* handle;
557
+ UV_WRITE_PRIVATE_FIELDS
558
+ };
559
+
560
+
561
+ /*
562
+ * Used to determine whether a stream is readable or writable.
563
+ */
564
+ UV_EXTERN int uv_is_readable(const uv_stream_t* handle);
565
+ UV_EXTERN int uv_is_writable(const uv_stream_t* handle);
566
+
567
+
568
+ /*
569
+ * Used to determine whether a stream is closing or closed.
570
+ *
571
+ * N.B. is only valid between the initialization of the handle
572
+ * and the arrival of the close callback, and cannot be used
573
+ * to validate the handle.
574
+ */
575
+ UV_EXTERN int uv_is_closing(const uv_handle_t* handle);
576
+
577
+
578
+ /*
579
+ * uv_tcp_t is a subclass of uv_stream_t
580
+ *
581
+ * Represents a TCP stream or TCP server.
582
+ */
583
+ struct uv_tcp_s {
584
+ UV_HANDLE_FIELDS
585
+ UV_STREAM_FIELDS
586
+ UV_TCP_PRIVATE_FIELDS
587
+ };
588
+
589
+ UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
590
+
591
+ /* Enable/disable Nagle's algorithm. */
592
+ UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
593
+
594
+ /* Enable/disable TCP keep-alive.
595
+ *
596
+ * `ms` is the initial delay in seconds, ignored when `enable` is zero.
597
+ */
598
+ UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle, int enable,
599
+ unsigned int delay);
600
+
601
+ /*
602
+ * This setting applies to Windows only.
603
+ * Enable/disable simultaneous asynchronous accept requests that are
604
+ * queued by the operating system when listening for new tcp connections.
605
+ * This setting is used to tune a tcp server for the desired performance.
606
+ * Having simultaneous accepts can significantly improve the rate of
607
+ * accepting connections (which is why it is enabled by default).
608
+ */
609
+ UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
610
+
611
+ UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in);
612
+ UV_EXTERN int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6);
613
+ UV_EXTERN int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name,
614
+ int* namelen);
615
+ UV_EXTERN int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name,
616
+ int* namelen);
617
+
618
+ /*
619
+ * uv_tcp_connect, uv_tcp_connect6
620
+ * These functions establish IPv4 and IPv6 TCP connections. Provide an
621
+ * initialized TCP handle and an uninitialized uv_connect_t*. The callback
622
+ * will be made when the connection is established.
623
+ */
624
+ UV_EXTERN int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle,
625
+ struct sockaddr_in address, uv_connect_cb cb);
626
+ UV_EXTERN int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle,
627
+ struct sockaddr_in6 address, uv_connect_cb cb);
628
+
629
+ /* uv_connect_t is a subclass of uv_req_t */
630
+ struct uv_connect_s {
631
+ UV_REQ_FIELDS
632
+ uv_connect_cb cb;
633
+ uv_stream_t* handle;
634
+ UV_CONNECT_PRIVATE_FIELDS
635
+ };
636
+
637
+
638
+ /*
639
+ * UDP support.
640
+ */
641
+
642
+ enum uv_udp_flags {
643
+ /* Disables dual stack mode. Used with uv_udp_bind6(). */
644
+ UV_UDP_IPV6ONLY = 1,
645
+ /*
646
+ * Indicates message was truncated because read buffer was too small. The
647
+ * remainder was discarded by the OS. Used in uv_udp_recv_cb.
648
+ */
649
+ UV_UDP_PARTIAL = 2
650
+ };
651
+
652
+ /*
653
+ * Called after a uv_udp_send() or uv_udp_send6(). status 0 indicates
654
+ * success otherwise error.
655
+ */
656
+ typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
657
+
658
+ /*
659
+ * Callback that is invoked when a new UDP datagram is received.
660
+ *
661
+ * handle UDP handle.
662
+ * nread Number of bytes that have been received.
663
+ * 0 if there is no more data to read. You may
664
+ * discard or repurpose the read buffer.
665
+ * -1 if a transmission error was detected.
666
+ * buf uv_buf_t with the received data.
667
+ * addr struct sockaddr_in or struct sockaddr_in6.
668
+ * Valid for the duration of the callback only.
669
+ * flags One or more OR'ed UV_UDP_* constants.
670
+ * Right now only UV_UDP_PARTIAL is used.
671
+ */
672
+ typedef void (*uv_udp_recv_cb)(uv_udp_t* handle, ssize_t nread, uv_buf_t buf,
673
+ struct sockaddr* addr, unsigned flags);
674
+
675
+ /* uv_udp_t is a subclass of uv_handle_t */
676
+ struct uv_udp_s {
677
+ UV_HANDLE_FIELDS
678
+ UV_UDP_PRIVATE_FIELDS
679
+ };
680
+
681
+ /* uv_udp_send_t is a subclass of uv_req_t */
682
+ struct uv_udp_send_s {
683
+ UV_REQ_FIELDS
684
+ uv_udp_t* handle;
685
+ uv_udp_send_cb cb;
686
+ UV_UDP_SEND_PRIVATE_FIELDS
687
+ };
688
+
689
+ /*
690
+ * Initialize a new UDP handle. The actual socket is created lazily.
691
+ * Returns 0 on success.
692
+ */
693
+ UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
694
+
695
+ /*
696
+ * Bind to a IPv4 address and port.
697
+ *
698
+ * Arguments:
699
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
700
+ * addr struct sockaddr_in with the address and port to bind to.
701
+ * flags Unused.
702
+ *
703
+ * Returns:
704
+ * 0 on success, -1 on error.
705
+ */
706
+ UV_EXTERN int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr,
707
+ unsigned flags);
708
+
709
+ /*
710
+ * Bind to a IPv6 address and port.
711
+ *
712
+ * Arguments:
713
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
714
+ * addr struct sockaddr_in with the address and port to bind to.
715
+ * flags Should be 0 or UV_UDP_IPV6ONLY.
716
+ *
717
+ * Returns:
718
+ * 0 on success, -1 on error.
719
+ */
720
+ UV_EXTERN int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr,
721
+ unsigned flags);
722
+ UV_EXTERN int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
723
+ int* namelen);
724
+
725
+ /*
726
+ * Set membership for a multicast address
727
+ *
728
+ * Arguments:
729
+ * handle UDP handle. Should have been initialized with
730
+ * `uv_udp_init`.
731
+ * multicast_addr multicast address to set membership for
732
+ * interface_addr interface address
733
+ * membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP
734
+ *
735
+ * Returns:
736
+ * 0 on success, -1 on error.
737
+ */
738
+ UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
739
+ const char* multicast_addr, const char* interface_addr,
740
+ uv_membership membership);
741
+
742
+ /*
743
+ * Set IP multicast loop flag. Makes multicast packets loop back to
744
+ * local sockets.
745
+ *
746
+ * Arguments:
747
+ * handle UDP handle. Should have been initialized with
748
+ * `uv_udp_init`.
749
+ * on 1 for on, 0 for off
750
+ *
751
+ * Returns:
752
+ * 0 on success, -1 on error.
753
+ */
754
+ UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
755
+
756
+ /*
757
+ * Set the multicast ttl
758
+ *
759
+ * Arguments:
760
+ * handle UDP handle. Should have been initialized with
761
+ * `uv_udp_init`.
762
+ * ttl 1 through 255
763
+ *
764
+ * Returns:
765
+ * 0 on success, -1 on error.
766
+ */
767
+ UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
768
+
769
+ /*
770
+ * Set broadcast on or off
771
+ *
772
+ * Arguments:
773
+ * handle UDP handle. Should have been initialized with
774
+ * `uv_udp_init`.
775
+ * on 1 for on, 0 for off
776
+ *
777
+ * Returns:
778
+ * 0 on success, -1 on error.
779
+ */
780
+ UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
781
+
782
+ /*
783
+ * Set the time to live
784
+ *
785
+ * Arguments:
786
+ * handle UDP handle. Should have been initialized with
787
+ * `uv_udp_init`.
788
+ * ttl 1 through 255
789
+ *
790
+ * Returns:
791
+ * 0 on success, -1 on error.
792
+ */
793
+ UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
794
+
795
+ /*
796
+ * Send data. If the socket has not previously been bound with `uv_udp_bind`
797
+ * or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
798
+ * and a random port number.
799
+ *
800
+ * Arguments:
801
+ * req UDP request handle. Need not be initialized.
802
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
803
+ * bufs List of buffers to send.
804
+ * bufcnt Number of buffers in `bufs`.
805
+ * addr Address of the remote peer. See `uv_ip4_addr`.
806
+ * send_cb Callback to invoke when the data has been sent out.
807
+ *
808
+ * Returns:
809
+ * 0 on success, -1 on error.
810
+ */
811
+ UV_EXTERN int uv_udp_send(uv_udp_send_t* req, uv_udp_t* handle,
812
+ uv_buf_t bufs[], int bufcnt, struct sockaddr_in addr,
813
+ uv_udp_send_cb send_cb);
814
+
815
+ /*
816
+ * Send data. If the socket has not previously been bound with `uv_udp_bind6`,
817
+ * it is bound to ::0 (the "all interfaces" address) and a random port number.
818
+ *
819
+ * Arguments:
820
+ * req UDP request handle. Need not be initialized.
821
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
822
+ * bufs List of buffers to send.
823
+ * bufcnt Number of buffers in `bufs`.
824
+ * addr Address of the remote peer. See `uv_ip6_addr`.
825
+ * send_cb Callback to invoke when the data has been sent out.
826
+ *
827
+ * Returns:
828
+ * 0 on success, -1 on error.
829
+ */
830
+ UV_EXTERN int uv_udp_send6(uv_udp_send_t* req, uv_udp_t* handle,
831
+ uv_buf_t bufs[], int bufcnt, struct sockaddr_in6 addr,
832
+ uv_udp_send_cb send_cb);
833
+
834
+ /*
835
+ * Receive data. If the socket has not previously been bound with `uv_udp_bind`
836
+ * or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
837
+ * and a random port number.
838
+ *
839
+ * Arguments:
840
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
841
+ * alloc_cb Callback to invoke when temporary storage is needed.
842
+ * recv_cb Callback to invoke with received data.
843
+ *
844
+ * Returns:
845
+ * 0 on success, -1 on error.
846
+ */
847
+ UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb,
848
+ uv_udp_recv_cb recv_cb);
849
+
850
+ /*
851
+ * Stop listening for incoming datagrams.
852
+ *
853
+ * Arguments:
854
+ * handle UDP handle. Should have been initialized with `uv_udp_init`.
855
+ *
856
+ * Returns:
857
+ * 0 on success, -1 on error.
858
+ */
859
+ UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
860
+
861
+
862
+ /*
863
+ * uv_tty_t is a subclass of uv_stream_t
864
+ *
865
+ * Representing a stream for the console.
866
+ */
867
+ struct uv_tty_s {
868
+ UV_HANDLE_FIELDS
869
+ UV_STREAM_FIELDS
870
+ UV_TTY_PRIVATE_FIELDS
871
+ };
872
+
873
+ /*
874
+ * Initialize a new TTY stream with the given file descriptor. Usually the
875
+ * file descriptor will be
876
+ * 0 = stdin
877
+ * 1 = stdout
878
+ * 2 = stderr
879
+ * The last argument, readable, specifies if you plan on calling
880
+ * uv_read_start with this stream. stdin is readable, stdout is not.
881
+ *
882
+ * TTY streams which are not readable have blocking writes.
883
+ */
884
+ UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
885
+
886
+ /*
887
+ * Set mode. 0 for normal, 1 for raw.
888
+ */
889
+ UV_EXTERN int uv_tty_set_mode(uv_tty_t*, int mode);
890
+
891
+ /*
892
+ * To be called when the program exits. Resets TTY settings to default
893
+ * values for the next process to take over.
894
+ */
895
+ UV_EXTERN void uv_tty_reset_mode(void);
896
+
897
+ /*
898
+ * Gets the current Window size. On success zero is returned.
899
+ */
900
+ UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);
901
+
902
+ /*
903
+ * Used to detect what type of stream should be used with a given file
904
+ * descriptor. Usually this will be used during initialization to guess the
905
+ * type of the stdio streams.
906
+ * For isatty() functionality use this function and test for UV_TTY.
907
+ */
908
+ UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
909
+
910
+ /*
911
+ * uv_pipe_t is a subclass of uv_stream_t
912
+ *
913
+ * Representing a pipe stream or pipe server. On Windows this is a Named
914
+ * Pipe. On Unix this is a UNIX domain socket.
915
+ */
916
+ struct uv_pipe_s {
917
+ UV_HANDLE_FIELDS
918
+ UV_STREAM_FIELDS
919
+ UV_PIPE_PRIVATE_FIELDS
920
+ int ipc; /* non-zero if this pipe is used for passing handles */
921
+ };
922
+
923
+ /*
924
+ * Initialize a pipe. The last argument is a boolean to indicate if
925
+ * this pipe will be used for handle passing between processes.
926
+ */
927
+ UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
928
+
929
+ /*
930
+ * Opens an existing file descriptor or HANDLE as a pipe.
931
+ */
932
+ UV_EXTERN void uv_pipe_open(uv_pipe_t*, uv_file file);
933
+
934
+ UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
935
+
936
+ UV_EXTERN void uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle,
937
+ const char* name, uv_connect_cb cb);
938
+
939
+ /*
940
+ * This setting applies to Windows only.
941
+ * Set the number of pending pipe instance handles when the pipe server
942
+ * is waiting for connections.
943
+ */
944
+ UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
945
+
946
+
947
+ /*
948
+ * uv_poll_t is a subclass of uv_handle_t.
949
+ *
950
+ * The uv_poll watcher is used to watch file descriptors for readability and
951
+ * writability, similar to the purpose of poll(2).
952
+ *
953
+ * The purpose of uv_poll is to enable integrating external libraries that
954
+ * rely on the event loop to signal it about the socket status changes, like
955
+ * c-ares or libssh2. Using uv_poll_t for any other other purpose is not
956
+ * recommended; uv_tcp_t, uv_udp_t, etc. provide an implementation that is
957
+ * much faster and more scalable than what can be achieved with uv_poll_t,
958
+ * especially on Windows.
959
+ *
960
+ * It is possible that uv_poll occasionally signals that a file descriptor is
961
+ * readable or writable even when it isn't. The user should therefore always
962
+ * be prepared to handle EAGAIN or equivalent when it attempts to read from or
963
+ * write to the fd.
964
+ *
965
+ * It is not okay to have multiple active uv_poll watchers for the same socket.
966
+ * This can cause libuv to busyloop or otherwise malfunction.
967
+ *
968
+ * The user should not close a file descriptor while it is being polled by an
969
+ * active uv_poll watcher. This can cause the poll watcher to report an error,
970
+ * but it might also start polling another socket. However the fd can be safely
971
+ * closed immediately after a call to uv_poll_stop() or uv_close().
972
+ *
973
+ * On windows only sockets can be polled with uv_poll. On unix any file
974
+ * descriptor that would be accepted by poll(2) can be used with uv_poll.
975
+ */
976
+ struct uv_poll_s {
977
+ UV_HANDLE_FIELDS
978
+ uv_poll_cb poll_cb;
979
+ UV_POLL_PRIVATE_FIELDS
980
+ };
981
+
982
+ enum uv_poll_event {
983
+ UV_READABLE = 1,
984
+ UV_WRITABLE = 2
985
+ };
986
+
987
+ /* Initialize the poll watcher using a file descriptor. */
988
+ UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
989
+
990
+ /* Initialize the poll watcher using a socket descriptor. On unix this is */
991
+ /* identical to uv_poll_init. On windows it takes a SOCKET handle. */
992
+ UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
993
+ uv_os_sock_t socket);
994
+
995
+ /*
996
+ * Starts polling the file descriptor. `events` is a bitmask consisting made up
997
+ * of UV_READABLE and UV_WRITABLE. As soon as an event is detected the callback
998
+ * will be called with `status` set to 0, and the detected events set en the
999
+ * `events` field.
1000
+ *
1001
+ * If an error happens while polling status may be set to -1 and the error
1002
+ * code can be retrieved with uv_last_error. The user should not close the
1003
+ * socket while uv_poll is active. If the user does that anyway, the callback
1004
+ * *may* be called reporting an error status, but this is not guaranteed.
1005
+ *
1006
+ * Calling uv_poll_start on an uv_poll watcher that is already active is fine.
1007
+ * Doing so will update the events mask that is being watched for.
1008
+ */
1009
+ UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb);
1010
+
1011
+ /* Stops polling the file descriptor. */
1012
+ UV_EXTERN int uv_poll_stop(uv_poll_t* handle);
1013
+
1014
+
1015
+ /*
1016
+ * uv_prepare_t is a subclass of uv_handle_t.
1017
+ *
1018
+ * libev wrapper. Every active prepare handle gets its callback called
1019
+ * exactly once per loop iteration, just before the system blocks to wait
1020
+ * for completed i/o.
1021
+ */
1022
+ struct uv_prepare_s {
1023
+ UV_HANDLE_FIELDS
1024
+ UV_PREPARE_PRIVATE_FIELDS
1025
+ };
1026
+
1027
+ UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
1028
+
1029
+ UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
1030
+
1031
+ UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare);
1032
+
1033
+
1034
+ /*
1035
+ * uv_check_t is a subclass of uv_handle_t.
1036
+ *
1037
+ * libev wrapper. Every active check handle gets its callback called exactly
1038
+ * once per loop iteration, just after the system returns from blocking.
1039
+ */
1040
+ struct uv_check_s {
1041
+ UV_HANDLE_FIELDS
1042
+ UV_CHECK_PRIVATE_FIELDS
1043
+ };
1044
+
1045
+ UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check);
1046
+
1047
+ UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb);
1048
+
1049
+ UV_EXTERN int uv_check_stop(uv_check_t* check);
1050
+
1051
+
1052
+ /*
1053
+ * uv_idle_t is a subclass of uv_handle_t.
1054
+ *
1055
+ * libev wrapper. Every active idle handle gets its callback called
1056
+ * repeatedly until it is stopped. This happens after all other types of
1057
+ * callbacks are processed. When there are multiple "idle" handles active,
1058
+ * their callbacks are called in turn.
1059
+ */
1060
+ struct uv_idle_s {
1061
+ UV_HANDLE_FIELDS
1062
+ UV_IDLE_PRIVATE_FIELDS
1063
+ };
1064
+
1065
+ UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle);
1066
+
1067
+ UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);
1068
+
1069
+ UV_EXTERN int uv_idle_stop(uv_idle_t* idle);
1070
+
1071
+
1072
+ /*
1073
+ * uv_async_t is a subclass of uv_handle_t.
1074
+ *
1075
+ * libev wrapper. uv_async_send wakes up the event
1076
+ * loop and calls the async handle's callback There is no guarantee that
1077
+ * every uv_async_send call leads to exactly one invocation of the callback;
1078
+ * The only guarantee is that the callback function is called at least once
1079
+ * after the call to async_send. Unlike all other libuv functions,
1080
+ * uv_async_send can be called from another thread.
1081
+ */
1082
+ struct uv_async_s {
1083
+ UV_HANDLE_FIELDS
1084
+ UV_ASYNC_PRIVATE_FIELDS
1085
+ };
1086
+
1087
+ UV_EXTERN int uv_async_init(uv_loop_t*, uv_async_t* async,
1088
+ uv_async_cb async_cb);
1089
+
1090
+ /*
1091
+ * This can be called from other threads to wake up a libuv thread.
1092
+ *
1093
+ * libuv is single threaded at the moment.
1094
+ */
1095
+ UV_EXTERN int uv_async_send(uv_async_t* async);
1096
+
1097
+
1098
+ /*
1099
+ * uv_timer_t is a subclass of uv_handle_t.
1100
+ *
1101
+ * Wraps libev's ev_timer watcher. Used to get woken up at a specified time
1102
+ * in the future.
1103
+ */
1104
+ struct uv_timer_s {
1105
+ UV_HANDLE_FIELDS
1106
+ UV_TIMER_PRIVATE_FIELDS
1107
+ };
1108
+
1109
+ UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* timer);
1110
+
1111
+ UV_EXTERN int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb,
1112
+ int64_t timeout, int64_t repeat);
1113
+
1114
+ UV_EXTERN int uv_timer_stop(uv_timer_t* timer);
1115
+
1116
+ /*
1117
+ * Stop the timer, and if it is repeating restart it using the repeat value
1118
+ * as the timeout. If the timer has never been started before it returns -1 and
1119
+ * sets the error to UV_EINVAL.
1120
+ */
1121
+ UV_EXTERN int uv_timer_again(uv_timer_t* timer);
1122
+
1123
+ /*
1124
+ * Set the repeat value. Note that if the repeat value is set from a timer
1125
+ * callback it does not immediately take effect. If the timer was non-repeating
1126
+ * before, it will have been stopped. If it was repeating, then the old repeat
1127
+ * value will have been used to schedule the next timeout.
1128
+ */
1129
+ UV_EXTERN void uv_timer_set_repeat(uv_timer_t* timer, int64_t repeat);
1130
+
1131
+ UV_EXTERN int64_t uv_timer_get_repeat(uv_timer_t* timer);
1132
+
1133
+
1134
+ /* c-ares integration initialize and terminate */
1135
+ UV_EXTERN int uv_ares_init_options(uv_loop_t*,
1136
+ ares_channel *channelptr, struct ares_options *options, int optmask);
1137
+
1138
+ /* TODO remove the loop argument from this function? */
1139
+ UV_EXTERN void uv_ares_destroy(uv_loop_t*, ares_channel channel);
1140
+
1141
+
1142
+ /*
1143
+ * uv_getaddrinfo_t is a subclass of uv_req_t
1144
+ *
1145
+ * Request object for uv_getaddrinfo.
1146
+ */
1147
+ struct uv_getaddrinfo_s {
1148
+ UV_REQ_FIELDS
1149
+ /* read-only */
1150
+ uv_loop_t* loop;
1151
+ UV_GETADDRINFO_PRIVATE_FIELDS
1152
+ };
1153
+
1154
+
1155
+ /*
1156
+ * Asynchronous getaddrinfo(3).
1157
+ *
1158
+ * Return code 0 means that request is accepted and callback will be called
1159
+ * with result. Other return codes mean that there will not be a callback.
1160
+ * Input arguments may be released after return from this call.
1161
+ *
1162
+ * uv_freeaddrinfo() must be called after completion to free the addrinfo
1163
+ * structure.
1164
+ *
1165
+ * On error NXDOMAIN the status code will be non-zero and UV_ENOENT returned.
1166
+ */
1167
+ UV_EXTERN int uv_getaddrinfo(uv_loop_t*, uv_getaddrinfo_t* handle,
1168
+ uv_getaddrinfo_cb getaddrinfo_cb, const char* node, const char* service,
1169
+ const struct addrinfo* hints);
1170
+
1171
+ UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
1172
+
1173
+ /* uv_spawn() options */
1174
+ typedef enum {
1175
+ UV_IGNORE = 0x00,
1176
+ UV_CREATE_PIPE = 0x01,
1177
+ UV_INHERIT_FD = 0x02,
1178
+ UV_INHERIT_STREAM = 0x04,
1179
+
1180
+ /* When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
1181
+ * determine the direction of flow, from the child process' perspective. Both
1182
+ * flags may be specified to create a duplex data stream.
1183
+ */
1184
+ UV_READABLE_PIPE = 0x10,
1185
+ UV_WRITABLE_PIPE = 0x20
1186
+ } uv_stdio_flags;
1187
+
1188
+ typedef struct uv_stdio_container_s {
1189
+ uv_stdio_flags flags;
1190
+
1191
+ union {
1192
+ uv_stream_t* stream;
1193
+ int fd;
1194
+ } data;
1195
+ } uv_stdio_container_t;
1196
+
1197
+ typedef struct uv_process_options_s {
1198
+ uv_exit_cb exit_cb; /* Called after the process exits. */
1199
+ const char* file; /* Path to program to execute. */
1200
+ /*
1201
+ * Command line arguments. args[0] should be the path to the program. On
1202
+ * Windows this uses CreateProcess which concatenates the arguments into a
1203
+ * string this can cause some strange errors. See the note at
1204
+ * windows_verbatim_arguments.
1205
+ */
1206
+ char** args;
1207
+ /*
1208
+ * This will be set as the environ variable in the subprocess. If this is
1209
+ * NULL then the parents environ will be used.
1210
+ */
1211
+ char** env;
1212
+ /*
1213
+ * If non-null this represents a directory the subprocess should execute
1214
+ * in. Stands for current working directory.
1215
+ */
1216
+ char* cwd;
1217
+ /*
1218
+ * Various flags that control how uv_spawn() behaves. See the definition of
1219
+ * `enum uv_process_flags` below.
1220
+ */
1221
+ unsigned int flags;
1222
+ /*
1223
+ * Libuv can change the child process' user/group id. This happens only when
1224
+ * the appropriate bits are set in the flags fields. This is not supported on
1225
+ * windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
1226
+ */
1227
+ uv_uid_t uid;
1228
+ uv_gid_t gid;
1229
+
1230
+ /*
1231
+ * The `stdio` field points to an array of uv_stdio_container_t structs that
1232
+ * describe the file descriptors that will be made available to the child
1233
+ * process. The convention is that stdio[0] points to stdin, fd 1 is used for
1234
+ * stdout, and fd 2 is stderr.
1235
+ *
1236
+ * Note that on windows file descriptors greater than 2 are available to the
1237
+ * child process only if the child processes uses the MSVCRT runtime.
1238
+ */
1239
+ int stdio_count;
1240
+ uv_stdio_container_t* stdio;
1241
+ } uv_process_options_t;
1242
+
1243
+ /*
1244
+ * These are the flags that can be used for the uv_process_options.flags field.
1245
+ */
1246
+ enum uv_process_flags {
1247
+ /*
1248
+ * Set the child process' user id. The user id is supplied in the `uid` field
1249
+ * of the options struct. This does not work on windows; setting this flag
1250
+ * will cause uv_spawn() to fail.
1251
+ */
1252
+ UV_PROCESS_SETUID = (1 << 0),
1253
+ /*
1254
+ * Set the child process' group id. The user id is supplied in the `gid`
1255
+ * field of the options struct. This does not work on windows; setting this
1256
+ * flag will cause uv_spawn() to fail.
1257
+ */
1258
+ UV_PROCESS_SETGID = (1 << 1),
1259
+ /*
1260
+ * Do not wrap any arguments in quotes, or perform any other escaping, when
1261
+ * converting the argument list into a command line string. This option is
1262
+ * only meaningful on Windows systems. On unix it is silently ignored.
1263
+ */
1264
+ UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
1265
+ /*
1266
+ * Spawn the child process in a detached state - this will make it a process
1267
+ * group leader, and will effectively enable the child to keep running after
1268
+ * the parent exits. Note that the child process will still keep the
1269
+ * parent's event loop alive unless the parent process calls uv_unref() on
1270
+ * the child's process handle.
1271
+ */
1272
+ UV_PROCESS_DETACHED = (1 << 3)
1273
+ };
1274
+
1275
+ /*
1276
+ * uv_process_t is a subclass of uv_handle_t
1277
+ */
1278
+ struct uv_process_s {
1279
+ UV_HANDLE_FIELDS
1280
+ uv_exit_cb exit_cb;
1281
+ int pid;
1282
+ UV_PROCESS_PRIVATE_FIELDS
1283
+ };
1284
+
1285
+ /* Initializes uv_process_t and starts the process. */
1286
+ UV_EXTERN int uv_spawn(uv_loop_t*, uv_process_t*,
1287
+ uv_process_options_t options);
1288
+
1289
+
1290
+ /*
1291
+ * Kills the process with the specified signal. The user must still
1292
+ * call uv_close on the process.
1293
+ */
1294
+ UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
1295
+
1296
+
1297
+ /* Kills the process with the specified signal. */
1298
+ UV_EXTERN uv_err_t uv_kill(int pid, int signum);
1299
+
1300
+
1301
+ /*
1302
+ * uv_work_t is a subclass of uv_req_t
1303
+ */
1304
+ struct uv_work_s {
1305
+ UV_REQ_FIELDS
1306
+ uv_loop_t* loop;
1307
+ uv_work_cb work_cb;
1308
+ uv_after_work_cb after_work_cb;
1309
+ UV_WORK_PRIVATE_FIELDS
1310
+ };
1311
+
1312
+ /* Queues a work request to execute asynchronously on the thread pool. */
1313
+ UV_EXTERN int uv_queue_work(uv_loop_t* loop, uv_work_t* req,
1314
+ uv_work_cb work_cb, uv_after_work_cb after_work_cb);
1315
+
1316
+
1317
+ struct uv_cpu_info_s {
1318
+ char* model;
1319
+ int speed;
1320
+ struct uv_cpu_times_s {
1321
+ uint64_t user;
1322
+ uint64_t nice;
1323
+ uint64_t sys;
1324
+ uint64_t idle;
1325
+ uint64_t irq;
1326
+ } cpu_times;
1327
+ };
1328
+
1329
+ struct uv_interface_address_s {
1330
+ char* name;
1331
+ int is_internal;
1332
+ union {
1333
+ struct sockaddr_in address4;
1334
+ struct sockaddr_in6 address6;
1335
+ } address;
1336
+ };
1337
+
1338
+ UV_EXTERN char** uv_setup_args(int argc, char** argv);
1339
+ UV_EXTERN uv_err_t uv_get_process_title(char* buffer, size_t size);
1340
+ UV_EXTERN uv_err_t uv_set_process_title(const char* title);
1341
+ UV_EXTERN uv_err_t uv_resident_set_memory(size_t* rss);
1342
+ UV_EXTERN uv_err_t uv_uptime(double* uptime);
1343
+
1344
+ /*
1345
+ * This allocates cpu_infos array, and sets count. The array
1346
+ * is freed using uv_free_cpu_info().
1347
+ */
1348
+ UV_EXTERN uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1349
+ UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1350
+
1351
+ /*
1352
+ * This allocates addresses array, and sets count. The array
1353
+ * is freed using uv_free_interface_addresses().
1354
+ */
1355
+ UV_EXTERN uv_err_t uv_interface_addresses(uv_interface_address_t** addresses,
1356
+ int* count);
1357
+ UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1358
+ int count);
1359
+
1360
+ /*
1361
+ * File System Methods.
1362
+ *
1363
+ * The uv_fs_* functions execute a blocking system call asynchronously (in a
1364
+ * thread pool) and call the specified callback in the specified loop after
1365
+ * completion. If the user gives NULL as the callback the blocking system
1366
+ * call will be called synchronously. req should be a pointer to an
1367
+ * uninitialized uv_fs_t object.
1368
+ *
1369
+ * uv_fs_req_cleanup() must be called after completion of the uv_fs_
1370
+ * function to free any internal memory allocations associated with the
1371
+ * request.
1372
+ */
1373
+
1374
+ typedef enum {
1375
+ UV_FS_UNKNOWN = -1,
1376
+ UV_FS_CUSTOM,
1377
+ UV_FS_OPEN,
1378
+ UV_FS_CLOSE,
1379
+ UV_FS_READ,
1380
+ UV_FS_WRITE,
1381
+ UV_FS_SENDFILE,
1382
+ UV_FS_STAT,
1383
+ UV_FS_LSTAT,
1384
+ UV_FS_FSTAT,
1385
+ UV_FS_FTRUNCATE,
1386
+ UV_FS_UTIME,
1387
+ UV_FS_FUTIME,
1388
+ UV_FS_CHMOD,
1389
+ UV_FS_FCHMOD,
1390
+ UV_FS_FSYNC,
1391
+ UV_FS_FDATASYNC,
1392
+ UV_FS_UNLINK,
1393
+ UV_FS_RMDIR,
1394
+ UV_FS_MKDIR,
1395
+ UV_FS_RENAME,
1396
+ UV_FS_READDIR,
1397
+ UV_FS_LINK,
1398
+ UV_FS_SYMLINK,
1399
+ UV_FS_READLINK,
1400
+ UV_FS_CHOWN,
1401
+ UV_FS_FCHOWN
1402
+ } uv_fs_type;
1403
+
1404
+ /* uv_fs_t is a subclass of uv_req_t */
1405
+ struct uv_fs_s {
1406
+ UV_REQ_FIELDS
1407
+ uv_fs_type fs_type;
1408
+ uv_loop_t* loop;
1409
+ uv_fs_cb cb;
1410
+ ssize_t result;
1411
+ void* ptr;
1412
+ char* path;
1413
+ int errorno;
1414
+ UV_FS_PRIVATE_FIELDS
1415
+ };
1416
+
1417
+ UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1418
+
1419
+ UV_EXTERN int uv_fs_close(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1420
+ uv_fs_cb cb);
1421
+
1422
+ UV_EXTERN int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path,
1423
+ int flags, int mode, uv_fs_cb cb);
1424
+
1425
+ UV_EXTERN int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1426
+ void* buf, size_t length, int64_t offset, uv_fs_cb cb);
1427
+
1428
+ UV_EXTERN int uv_fs_unlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
1429
+ uv_fs_cb cb);
1430
+
1431
+ UV_EXTERN int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1432
+ void* buf, size_t length, int64_t offset, uv_fs_cb cb);
1433
+
1434
+ UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop, uv_fs_t* req, const char* path,
1435
+ int mode, uv_fs_cb cb);
1436
+
1437
+ UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop, uv_fs_t* req, const char* path,
1438
+ uv_fs_cb cb);
1439
+
1440
+ UV_EXTERN int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req,
1441
+ const char* path, int flags, uv_fs_cb cb);
1442
+
1443
+ UV_EXTERN int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path,
1444
+ uv_fs_cb cb);
1445
+
1446
+ UV_EXTERN int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1447
+ uv_fs_cb cb);
1448
+
1449
+ UV_EXTERN int uv_fs_rename(uv_loop_t* loop, uv_fs_t* req, const char* path,
1450
+ const char* new_path, uv_fs_cb cb);
1451
+
1452
+ UV_EXTERN int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1453
+ uv_fs_cb cb);
1454
+
1455
+ UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1456
+ uv_fs_cb cb);
1457
+
1458
+ UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1459
+ int64_t offset, uv_fs_cb cb);
1460
+
1461
+ UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd,
1462
+ uv_file in_fd, int64_t in_offset, size_t length, uv_fs_cb cb);
1463
+
1464
+ UV_EXTERN int uv_fs_chmod(uv_loop_t* loop, uv_fs_t* req, const char* path,
1465
+ int mode, uv_fs_cb cb);
1466
+
1467
+ UV_EXTERN int uv_fs_utime(uv_loop_t* loop, uv_fs_t* req, const char* path,
1468
+ double atime, double mtime, uv_fs_cb cb);
1469
+
1470
+ UV_EXTERN int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1471
+ double atime, double mtime, uv_fs_cb cb);
1472
+
1473
+ UV_EXTERN int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path,
1474
+ uv_fs_cb cb);
1475
+
1476
+ UV_EXTERN int uv_fs_link(uv_loop_t* loop, uv_fs_t* req, const char* path,
1477
+ const char* new_path, uv_fs_cb cb);
1478
+
1479
+ /*
1480
+ * This flag can be used with uv_fs_symlink on Windows
1481
+ * to specify whether path argument points to a directory.
1482
+ */
1483
+ #define UV_FS_SYMLINK_DIR 0x0001
1484
+
1485
+ /*
1486
+ * This flag can be used with uv_fs_symlink on Windows
1487
+ * to specify whether the symlink is to be created using junction points.
1488
+ */
1489
+ #define UV_FS_SYMLINK_JUNCTION 0x0002
1490
+
1491
+ UV_EXTERN int uv_fs_symlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
1492
+ const char* new_path, int flags, uv_fs_cb cb);
1493
+
1494
+ UV_EXTERN int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,
1495
+ uv_fs_cb cb);
1496
+
1497
+ UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1498
+ int mode, uv_fs_cb cb);
1499
+
1500
+ UV_EXTERN int uv_fs_chown(uv_loop_t* loop, uv_fs_t* req, const char* path,
1501
+ int uid, int gid, uv_fs_cb cb);
1502
+
1503
+ UV_EXTERN int uv_fs_fchown(uv_loop_t* loop, uv_fs_t* req, uv_file file,
1504
+ int uid, int gid, uv_fs_cb cb);
1505
+
1506
+
1507
+ enum uv_fs_event {
1508
+ UV_RENAME = 1,
1509
+ UV_CHANGE = 2
1510
+ };
1511
+
1512
+
1513
+ struct uv_fs_event_s {
1514
+ UV_HANDLE_FIELDS
1515
+ char* filename;
1516
+ UV_FS_EVENT_PRIVATE_FIELDS
1517
+ };
1518
+
1519
+
1520
+ /*
1521
+ * uv_fs_stat() based polling file watcher.
1522
+ */
1523
+ struct uv_fs_poll_s {
1524
+ UV_HANDLE_FIELDS
1525
+ /* Private, don't touch. */
1526
+ int busy_polling; /* TODO(bnoordhuis) Fold into flags field. */
1527
+ unsigned int interval;
1528
+ uint64_t start_time;
1529
+ char* path;
1530
+ uv_fs_poll_cb poll_cb;
1531
+ uv_timer_t timer_handle;
1532
+ uv_fs_t* fs_req;
1533
+ uv_statbuf_t statbuf;
1534
+ };
1535
+
1536
+ UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1537
+
1538
+ /*
1539
+ * Check the file at `path` for changes every `interval` milliseconds.
1540
+ *
1541
+ * Your callback i invoked with `status == -1` if `path` does not exist
1542
+ * or is inaccessible. The watcher is *not* stopped but your callback is
1543
+ * not called again until something changes (e.g. when the file is created
1544
+ * or the error reason changes).
1545
+ *
1546
+ * When `status == 0`, your callback receives pointers to the old and new
1547
+ * `uv_statbuf_t` structs. They are valid for the duration of the callback
1548
+ * only!
1549
+ *
1550
+ * For maximum portability, use multi-second intervals. Sub-second intervals
1551
+ * will not detect all changes on many file systems.
1552
+ */
1553
+ UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1554
+ uv_fs_poll_cb poll_cb,
1555
+ const char* path,
1556
+ unsigned int interval);
1557
+
1558
+ UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1559
+
1560
+ /*
1561
+ * Gets load avg
1562
+ * See: http://en.wikipedia.org/wiki/Load_(computing)
1563
+ * (Returns [0,0,0] for windows and cygwin)
1564
+ */
1565
+ UV_EXTERN void uv_loadavg(double avg[3]);
1566
+
1567
+
1568
+ /*
1569
+ * Flags to be passed to uv_fs_event_init.
1570
+ */
1571
+ enum uv_fs_event_flags {
1572
+ /*
1573
+ * By default, if the fs event watcher is given a directory name, we will
1574
+ * watch for all events in that directory. This flags overrides this behavior
1575
+ * and makes fs_event report only changes to the directory entry itself. This
1576
+ * flag does not affect individual files watched.
1577
+ * This flag is currently not implemented yet on any backend.
1578
+ */
1579
+ UV_FS_EVENT_WATCH_ENTRY = 1,
1580
+
1581
+ /*
1582
+ * By default uv_fs_event will try to use a kernel interface such as inotify
1583
+ * or kqueue to detect events. This may not work on remote filesystems such
1584
+ * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1585
+ * regular interval.
1586
+ * This flag is currently not implemented yet on any backend.
1587
+ */
1588
+ UV_FS_EVENT_STAT = 2
1589
+ };
1590
+
1591
+
1592
+ UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,
1593
+ const char* filename, uv_fs_event_cb cb, int flags);
1594
+
1595
+ /* Utility */
1596
+
1597
+ /* Convert string ip addresses to binary structures */
1598
+ UV_EXTERN struct sockaddr_in uv_ip4_addr(const char* ip, int port);
1599
+ UV_EXTERN struct sockaddr_in6 uv_ip6_addr(const char* ip, int port);
1600
+
1601
+ /* Convert binary addresses to strings */
1602
+ UV_EXTERN int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size);
1603
+ UV_EXTERN int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
1604
+
1605
+ /* Gets the executable path */
1606
+ UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1607
+
1608
+ /* Gets the current working directory */
1609
+ UV_EXTERN uv_err_t uv_cwd(char* buffer, size_t size);
1610
+
1611
+ /* Changes the current working directory */
1612
+ UV_EXTERN uv_err_t uv_chdir(const char* dir);
1613
+
1614
+ /* Gets memory info in bytes */
1615
+ UV_EXTERN uint64_t uv_get_free_memory(void);
1616
+ UV_EXTERN uint64_t uv_get_total_memory(void);
1617
+
1618
+ /*
1619
+ * Returns the current high-resolution real time. This is expressed in
1620
+ * nanoseconds. It is relative to an arbitrary time in the past. It is not
1621
+ * related to the time of day and therefore not subject to clock drift. The
1622
+ * primary use is for measuring performance between intervals.
1623
+ *
1624
+ * Note not every platform can support nanosecond resolution; however, this
1625
+ * value will always be in nanoseconds.
1626
+ */
1627
+ UV_EXTERN extern uint64_t uv_hrtime(void);
1628
+
1629
+
1630
+ /*
1631
+ * Disables inheritance for file descriptors / handles that this process
1632
+ * inherited from its parent. The effect is that child processes spawned by
1633
+ * this proces don't accidently inherit these handles.
1634
+ *
1635
+ * It is recommended to call this function as early in your program as possible,
1636
+ * before the inherited file descriptors can be closed or duplicated.
1637
+ *
1638
+ * Note that this function works on a best-effort basis: there is no guarantee
1639
+ * that libuv can discover all file descriptors that were inherited. In general
1640
+ * it does a better job on Windows than it does on unix.
1641
+ *
1642
+ * TODO(bb): insert snarky remark to annoy bnoordhuis and the folks at joyent.
1643
+ */
1644
+ UV_EXTERN void uv_disable_stdio_inheritance(void);
1645
+
1646
+ /*
1647
+ * Opens a shared library. The filename is in utf-8. Returns 0 on success and
1648
+ * -1 on error. Call `uv_dlerror(uv_lib_t*)` to get the error message.
1649
+ */
1650
+ UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1651
+
1652
+ /*
1653
+ * Close the shared libary.
1654
+ */
1655
+ UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1656
+
1657
+ /*
1658
+ * Retrieves a data pointer from a dynamic library. It is legal for a symbol to
1659
+ * map to NULL. Returns 0 on success and -1 if the symbol was not found.
1660
+ */
1661
+ UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1662
+
1663
+ /*
1664
+ * Returns the last uv_dlopen() or uv_dlsym() error message.
1665
+ */
1666
+ UV_EXTERN const char* uv_dlerror(uv_lib_t* lib);
1667
+
1668
+ /*
1669
+ * The mutex functions return 0 on success, -1 on error
1670
+ * (unless the return type is void, of course).
1671
+ */
1672
+ UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1673
+ UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1674
+ UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1675
+ UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1676
+ UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1677
+
1678
+ /*
1679
+ * Same goes for the read/write lock functions.
1680
+ */
1681
+ UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1682
+ UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1683
+ UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1684
+ UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1685
+ UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1686
+ UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1687
+ UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1688
+ UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1689
+
1690
+ /*
1691
+ * Same goes for the semaphore functions.
1692
+ */
1693
+ UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1694
+ UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1695
+ UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1696
+ UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1697
+ UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1698
+
1699
+ /* Runs a function once and only once. Concurrent calls to uv_once() with the
1700
+ * same guard will block all callers except one (it's unspecified which one).
1701
+ * The guard should be initialized statically with the UV_ONCE_INIT macro.
1702
+ */
1703
+ UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1704
+
1705
+ UV_EXTERN int uv_thread_create(uv_thread_t *tid,
1706
+ void (*entry)(void *arg), void *arg);
1707
+ UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1708
+
1709
+ /* the presence of these unions force similar struct layout */
1710
+ union uv_any_handle {
1711
+ uv_tcp_t tcp;
1712
+ uv_pipe_t pipe;
1713
+ uv_prepare_t prepare;
1714
+ uv_check_t check;
1715
+ uv_idle_t idle;
1716
+ uv_async_t async;
1717
+ uv_timer_t timer;
1718
+ uv_getaddrinfo_t getaddrinfo;
1719
+ uv_fs_event_t fs_event;
1720
+ };
1721
+
1722
+ union uv_any_req {
1723
+ uv_req_t req;
1724
+ uv_write_t write;
1725
+ uv_connect_t connect;
1726
+ uv_shutdown_t shutdown;
1727
+ uv_fs_t fs_req;
1728
+ uv_work_t work_req;
1729
+ };
1730
+
1731
+
1732
+ struct uv_counters_s {
1733
+ uint64_t async_init;
1734
+ uint64_t check_init;
1735
+ uint64_t eio_init;
1736
+ uint64_t fs_event_init;
1737
+ uint64_t fs_poll_init;
1738
+ uint64_t handle_init;
1739
+ uint64_t idle_init;
1740
+ uint64_t pipe_init;
1741
+ uint64_t poll_init;
1742
+ uint64_t prepare_init;
1743
+ uint64_t process_init;
1744
+ uint64_t req_init;
1745
+ uint64_t stream_init;
1746
+ uint64_t tcp_init;
1747
+ uint64_t timer_init;
1748
+ uint64_t tty_init;
1749
+ uint64_t udp_init;
1750
+ };
1751
+
1752
+
1753
+ struct uv_loop_s {
1754
+ UV_LOOP_PRIVATE_FIELDS
1755
+ ares_channel channel;
1756
+ /* While the channel is active this timer is called once per second to be */
1757
+ /* sure that we're always calling ares_process. See the warning above the */
1758
+ /* definition of ares_timeout(). */
1759
+ uv_timer_t ares_timer; \
1760
+ /* RB_HEAD(uv__ares_tasks, uv_ares_task_t) */
1761
+ struct uv__ares_tasks { uv_ares_task_t* rbh_root; } ares_handles;
1762
+ /* Diagnostic counters */
1763
+ uv_counters_t counters;
1764
+ /* The last error */
1765
+ uv_err_t last_err;
1766
+ /* Loop reference counting */
1767
+ unsigned int active_handles;
1768
+ ngx_queue_t handle_queue;
1769
+ ngx_queue_t active_reqs;
1770
+ /* User data - use this for whatever. */
1771
+ void* data;
1772
+ };
1773
+
1774
+
1775
+ /* Don't export the private CPP symbols. */
1776
+ #undef UV_HANDLE_TYPE_PRIVATE
1777
+ #undef UV_REQ_TYPE_PRIVATE
1778
+ #undef UV_REQ_PRIVATE_FIELDS
1779
+ #undef UV_STREAM_PRIVATE_FIELDS
1780
+ #undef UV_TCP_PRIVATE_FIELDS
1781
+ #undef UV_PREPARE_PRIVATE_FIELDS
1782
+ #undef UV_CHECK_PRIVATE_FIELDS
1783
+ #undef UV_IDLE_PRIVATE_FIELDS
1784
+ #undef UV_ASYNC_PRIVATE_FIELDS
1785
+ #undef UV_TIMER_PRIVATE_FIELDS
1786
+ #undef UV_GETADDRINFO_PRIVATE_FIELDS
1787
+ #undef UV_FS_REQ_PRIVATE_FIELDS
1788
+ #undef UV_WORK_PRIVATE_FIELDS
1789
+ #undef UV_FS_EVENT_PRIVATE_FIELDS
1790
+ #undef UV_LOOP_PRIVATE_FIELDS
1791
+ #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
1792
+
1793
+ #ifdef __cplusplus
1794
+ }
1795
+ #endif
1796
+ #endif /* UV_H */