rbuv 0.0.1 → 0.0.2

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