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 https://github.com/libuv/libuv#documentation for documentation. */
23 
24 #ifndef UV_H
25 #define UV_H
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #if defined(BUILDING_UV_SHARED) && defined(USING_UV_SHARED)
31 #error "Define either BUILDING_UV_SHARED or USING_UV_SHARED, not both."
32 #endif
33 
34 #ifdef _WIN32
35   /* Windows - set up dll import/export decorators. */
36 # if defined(BUILDING_UV_SHARED)
37     /* Building shared library. */
38 #   define UV_EXTERN __declspec(dllexport)
39 # elif defined(USING_UV_SHARED)
40     /* Using shared library. */
41 #   define UV_EXTERN __declspec(dllimport)
42 # else
43     /* Building static library. */
44 #   define UV_EXTERN /* nothing */
45 # endif
46 #elif __GNUC__ >= 4
47 # define UV_EXTERN __attribute__((visibility("default")))
48 #else
49 # define UV_EXTERN /* nothing */
50 #endif
51 
52 #include "uv/errno.h"
53 #include "uv/version.h"
54 #include <stddef.h>
55 #include <stdio.h>
56 
57 #if defined(_MSC_VER) && _MSC_VER < 1600
58 # include "uv/stdint-msvc2008.h"
59 #else
60 # include <stdint.h>
61 #endif
62 
63 #if defined(_WIN32)
64 # include "uv/win.h"
65 #else
66 # include "uv/unix.h"
67 #endif
68 
69 /* Expand this list if necessary. */
70 #define UV_ERRNO_MAP(XX)                                                      \
71   XX(E2BIG, "argument list too long")                                         \
72   XX(EACCES, "permission denied")                                             \
73   XX(EADDRINUSE, "address already in use")                                    \
74   XX(EADDRNOTAVAIL, "address not available")                                  \
75   XX(EAFNOSUPPORT, "address family not supported")                            \
76   XX(EAGAIN, "resource temporarily unavailable")                              \
77   XX(EAI_ADDRFAMILY, "address family not supported")                          \
78   XX(EAI_AGAIN, "temporary failure")                                          \
79   XX(EAI_BADFLAGS, "bad ai_flags value")                                      \
80   XX(EAI_BADHINTS, "invalid value for hints")                                 \
81   XX(EAI_CANCELED, "request canceled")                                        \
82   XX(EAI_FAIL, "permanent failure")                                           \
83   XX(EAI_FAMILY, "ai_family not supported")                                   \
84   XX(EAI_MEMORY, "out of memory")                                             \
85   XX(EAI_NODATA, "no address")                                                \
86   XX(EAI_NONAME, "unknown node or service")                                   \
87   XX(EAI_OVERFLOW, "argument buffer overflow")                                \
88   XX(EAI_PROTOCOL, "resolved protocol is unknown")                            \
89   XX(EAI_SERVICE, "service not available for socket type")                    \
90   XX(EAI_SOCKTYPE, "socket type not supported")                               \
91   XX(EALREADY, "connection already in progress")                              \
92   XX(EBADF, "bad file descriptor")                                            \
93   XX(EBUSY, "resource busy or locked")                                        \
94   XX(ECANCELED, "operation canceled")                                         \
95   XX(ECHARSET, "invalid Unicode character")                                   \
96   XX(ECONNABORTED, "software caused connection abort")                        \
97   XX(ECONNREFUSED, "connection refused")                                      \
98   XX(ECONNRESET, "connection reset by peer")                                  \
99   XX(EDESTADDRREQ, "destination address required")                            \
100   XX(EEXIST, "file already exists")                                           \
101   XX(EFAULT, "bad address in system call argument")                           \
102   XX(EFBIG, "file too large")                                                 \
103   XX(EHOSTUNREACH, "host is unreachable")                                     \
104   XX(EINTR, "interrupted system call")                                        \
105   XX(EINVAL, "invalid argument")                                              \
106   XX(EIO, "i/o error")                                                        \
107   XX(EISCONN, "socket is already connected")                                  \
108   XX(EISDIR, "illegal operation on a directory")                              \
109   XX(ELOOP, "too many symbolic links encountered")                            \
110   XX(EMFILE, "too many open files")                                           \
111   XX(EMSGSIZE, "message too long")                                            \
112   XX(ENAMETOOLONG, "name too long")                                           \
113   XX(ENETDOWN, "network is down")                                             \
114   XX(ENETUNREACH, "network is unreachable")                                   \
115   XX(ENFILE, "file table overflow")                                           \
116   XX(ENOBUFS, "no buffer space available")                                    \
117   XX(ENODEV, "no such device")                                                \
118   XX(ENOENT, "no such file or directory")                                     \
119   XX(ENOMEM, "not enough memory")                                             \
120   XX(ENONET, "machine is not on the network")                                 \
121   XX(ENOPROTOOPT, "protocol not available")                                   \
122   XX(ENOSPC, "no space left on device")                                       \
123   XX(ENOSYS, "function not implemented")                                      \
124   XX(ENOTCONN, "socket is not connected")                                     \
125   XX(ENOTDIR, "not a directory")                                              \
126   XX(ENOTEMPTY, "directory not empty")                                        \
127   XX(ENOTSOCK, "socket operation on non-socket")                              \
128   XX(ENOTSUP, "operation not supported on socket")                            \
129   XX(EPERM, "operation not permitted")                                        \
130   XX(EPIPE, "broken pipe")                                                    \
131   XX(EPROTO, "protocol error")                                                \
132   XX(EPROTONOSUPPORT, "protocol not supported")                               \
133   XX(EPROTOTYPE, "protocol wrong type for socket")                            \
134   XX(ERANGE, "result too large")                                              \
135   XX(EROFS, "read-only file system")                                          \
136   XX(ESHUTDOWN, "cannot send after transport endpoint shutdown")              \
137   XX(ESPIPE, "invalid seek")                                                  \
138   XX(ESRCH, "no such process")                                                \
139   XX(ETIMEDOUT, "connection timed out")                                       \
140   XX(ETXTBSY, "text file is busy")                                            \
141   XX(EXDEV, "cross-device link not permitted")                                \
142   XX(UNKNOWN, "unknown error")                                                \
143   XX(EOF, "end of file")                                                      \
144   XX(ENXIO, "no such device or address")                                      \
145   XX(EMLINK, "too many links")                                                \
146   XX(EHOSTDOWN, "host is down")                                               \
147   XX(EREMOTEIO, "remote I/O error")                                           \
148   XX(ENOTTY, "inappropriate ioctl for device")                                \
149   XX(EFTYPE, "inappropriate file type or format")                             \
150   XX(EILSEQ, "illegal byte sequence")                                         \
151 
152 #define UV_HANDLE_TYPE_MAP(XX)                                                \
153   XX(ASYNC, async)                                                            \
154   XX(CHECK, check)                                                            \
155   XX(FS_EVENT, fs_event)                                                      \
156   XX(FS_POLL, fs_poll)                                                        \
157   XX(HANDLE, handle)                                                          \
158   XX(IDLE, idle)                                                              \
159   XX(NAMED_PIPE, pipe)                                                        \
160   XX(POLL, poll)                                                              \
161   XX(PREPARE, prepare)                                                        \
162   XX(PROCESS, process)                                                        \
163   XX(STREAM, stream)                                                          \
164   XX(TCP, tcp)                                                                \
165   XX(TIMER, timer)                                                            \
166   XX(TTY, tty)                                                                \
167   XX(UDP, udp)                                                                \
168   XX(SIGNAL, signal)                                                          \
169 
170 #define UV_REQ_TYPE_MAP(XX)                                                   \
171   XX(REQ, req)                                                                \
172   XX(CONNECT, connect)                                                        \
173   XX(WRITE, write)                                                            \
174   XX(SHUTDOWN, shutdown)                                                      \
175   XX(UDP_SEND, udp_send)                                                      \
176   XX(FS, fs)                                                                  \
177   XX(WORK, work)                                                              \
178   XX(GETADDRINFO, getaddrinfo)                                                \
179   XX(GETNAMEINFO, getnameinfo)                                                \
180   XX(RANDOM, random)                                                          \
181 
182 typedef enum {
183 #define XX(code, _) UV_ ## code = UV__ ## code,
184   UV_ERRNO_MAP(XX)
185 #undef XX
186   UV_ERRNO_MAX = UV__EOF - 1
187 } uv_errno_t;
188 
189 typedef enum {
190   UV_UNKNOWN_HANDLE = 0,
191 #define XX(uc, lc) UV_##uc,
192   UV_HANDLE_TYPE_MAP(XX)
193 #undef XX
194   UV_FILE,
195   UV_HANDLE_TYPE_MAX
196 } uv_handle_type;
197 
198 typedef enum {
199   UV_UNKNOWN_REQ = 0,
200 #define XX(uc, lc) UV_##uc,
201   UV_REQ_TYPE_MAP(XX)
202 #undef XX
203   UV_REQ_TYPE_PRIVATE
204   UV_REQ_TYPE_MAX
205 } uv_req_type;
206 
207 
208 /* Handle types. */
209 typedef struct uv_loop_s uv_loop_t;
210 typedef struct uv_handle_s uv_handle_t;
211 typedef struct uv_dir_s uv_dir_t;
212 typedef struct uv_stream_s uv_stream_t;
213 typedef struct uv_tcp_s uv_tcp_t;
214 typedef struct uv_udp_s uv_udp_t;
215 typedef struct uv_pipe_s uv_pipe_t;
216 typedef struct uv_tty_s uv_tty_t;
217 typedef struct uv_poll_s uv_poll_t;
218 typedef struct uv_timer_s uv_timer_t;
219 typedef struct uv_prepare_s uv_prepare_t;
220 typedef struct uv_check_s uv_check_t;
221 typedef struct uv_idle_s uv_idle_t;
222 typedef struct uv_async_s uv_async_t;
223 typedef struct uv_process_s uv_process_t;
224 typedef struct uv_fs_event_s uv_fs_event_t;
225 typedef struct uv_fs_poll_s uv_fs_poll_t;
226 typedef struct uv_signal_s uv_signal_t;
227 
228 /* Request types. */
229 typedef struct uv_req_s uv_req_t;
230 typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
231 typedef struct uv_getnameinfo_s uv_getnameinfo_t;
232 typedef struct uv_shutdown_s uv_shutdown_t;
233 typedef struct uv_write_s uv_write_t;
234 typedef struct uv_connect_s uv_connect_t;
235 typedef struct uv_udp_send_s uv_udp_send_t;
236 typedef struct uv_fs_s uv_fs_t;
237 typedef struct uv_work_s uv_work_t;
238 typedef struct uv_random_s uv_random_t;
239 
240 /* None of the above. */
241 typedef struct uv_env_item_s uv_env_item_t;
242 typedef struct uv_cpu_info_s uv_cpu_info_t;
243 typedef struct uv_interface_address_s uv_interface_address_t;
244 typedef struct uv_dirent_s uv_dirent_t;
245 typedef struct uv_passwd_s uv_passwd_t;
246 typedef struct uv_utsname_s uv_utsname_t;
247 typedef struct uv_statfs_s uv_statfs_t;
248 
249 typedef enum {
250   UV_LOOP_BLOCK_SIGNAL
251 } uv_loop_option;
252 
253 typedef enum {
254   UV_RUN_DEFAULT = 0,
255   UV_RUN_ONCE,
256   UV_RUN_NOWAIT
257 } uv_run_mode;
258 
259 
260 UV_EXTERN unsigned int uv_version(void);
261 UV_EXTERN const char* uv_version_string(void);
262 
263 typedef void* (*uv_malloc_func)(size_t size);
264 typedef void* (*uv_realloc_func)(void* ptr, size_t size);
265 typedef void* (*uv_calloc_func)(size_t count, size_t size);
266 typedef void (*uv_free_func)(void* ptr);
267 
268 UV_EXTERN void uv_library_shutdown(void);
269 
270 UV_EXTERN int uv_replace_allocator(uv_malloc_func malloc_func,
271                                    uv_realloc_func realloc_func,
272                                    uv_calloc_func calloc_func,
273                                    uv_free_func free_func);
274 
275 UV_EXTERN uv_loop_t* uv_default_loop(void);
276 UV_EXTERN int uv_loop_init(uv_loop_t* loop);
277 UV_EXTERN int uv_loop_close(uv_loop_t* loop);
278 /*
279  * NOTE:
280  *  This function is DEPRECATED (to be removed after 0.12), users should
281  *  allocate the loop manually and use uv_loop_init instead.
282  */
283 UV_EXTERN uv_loop_t* uv_loop_new(void);
284 /*
285  * NOTE:
286  *  This function is DEPRECATED (to be removed after 0.12). Users should use
287  *  uv_loop_close and free the memory manually instead.
288  */
289 UV_EXTERN void uv_loop_delete(uv_loop_t*);
290 UV_EXTERN size_t uv_loop_size(void);
291 UV_EXTERN int uv_loop_alive(const uv_loop_t* loop);
292 UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...);
293 UV_EXTERN int uv_loop_fork(uv_loop_t* loop);
294 
295 UV_EXTERN int uv_run(uv_loop_t*, uv_run_mode mode);
296 UV_EXTERN void uv_stop(uv_loop_t*);
297 
298 UV_EXTERN void uv_ref(uv_handle_t*);
299 UV_EXTERN void uv_unref(uv_handle_t*);
300 UV_EXTERN int uv_has_ref(const uv_handle_t*);
301 
302 UV_EXTERN void uv_update_time(uv_loop_t*);
303 UV_EXTERN uint64_t uv_now(const uv_loop_t*);
304 
305 UV_EXTERN int uv_backend_fd(const uv_loop_t*);
306 UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
307 
308 typedef void (*uv_alloc_cb)(uv_handle_t* handle,
309                             size_t suggested_size,
310                             uv_buf_t* buf);
311 typedef void (*uv_read_cb)(uv_stream_t* stream,
312                            ssize_t nread,
313                            const uv_buf_t* buf);
314 typedef void (*uv_write_cb)(uv_write_t* req, int status);
315 typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
316 typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
317 typedef void (*uv_connection_cb)(uv_stream_t* server, int status);
318 typedef void (*uv_close_cb)(uv_handle_t* handle);
319 typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events);
320 typedef void (*uv_timer_cb)(uv_timer_t* handle);
321 typedef void (*uv_async_cb)(uv_async_t* handle);
322 typedef void (*uv_prepare_cb)(uv_prepare_t* handle);
323 typedef void (*uv_check_cb)(uv_check_t* handle);
324 typedef void (*uv_idle_cb)(uv_idle_t* handle);
325 typedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status, int term_signal);
326 typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
327 typedef void (*uv_fs_cb)(uv_fs_t* req);
328 typedef void (*uv_work_cb)(uv_work_t* req);
329 typedef void (*uv_after_work_cb)(uv_work_t* req, int status);
330 typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
331                                   int status,
332                                   struct addrinfo* res);
333 typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
334                                   int status,
335                                   const char* hostname,
336                                   const char* service);
337 typedef void (*uv_random_cb)(uv_random_t* req,
338                              int status,
339                              void* buf,
340                              size_t buflen);
341 
342 typedef struct {
343   long tv_sec;
344   long tv_nsec;
345 } uv_timespec_t;
346 
347 
348 typedef struct {
349   uint64_t st_dev;
350   uint64_t st_mode;
351   uint64_t st_nlink;
352   uint64_t st_uid;
353   uint64_t st_gid;
354   uint64_t st_rdev;
355   uint64_t st_ino;
356   uint64_t st_size;
357   uint64_t st_blksize;
358   uint64_t st_blocks;
359   uint64_t st_flags;
360   uint64_t st_gen;
361   uv_timespec_t st_atim;
362   uv_timespec_t st_mtim;
363   uv_timespec_t st_ctim;
364   uv_timespec_t st_birthtim;
365 } uv_stat_t;
366 
367 
368 typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle,
369                                const char* filename,
370                                int events,
371                                int status);
372 
373 typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
374                               int status,
375                               const uv_stat_t* prev,
376                               const uv_stat_t* curr);
377 
378 typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum);
379 
380 
381 typedef enum {
382   UV_LEAVE_GROUP = 0,
383   UV_JOIN_GROUP
384 } uv_membership;
385 
386 
387 UV_EXTERN int uv_translate_sys_error(int sys_errno);
388 
389 UV_EXTERN const char* uv_strerror(int err);
390 UV_EXTERN char* uv_strerror_r(int err, char* buf, size_t buflen);
391 
392 UV_EXTERN const char* uv_err_name(int err);
393 UV_EXTERN char* uv_err_name_r(int err, char* buf, size_t buflen);
394 
395 
396 #define UV_REQ_FIELDS                                                         \
397   /* public */                                                                \
398   void* data;                                                                 \
399   /* read-only */                                                             \
400   uv_req_type type;                                                           \
401   /* private */                                                               \
402   void* reserved[6];                                                          \
403   UV_REQ_PRIVATE_FIELDS                                                       \
404 
405 /* Abstract base class of all requests. */
406 struct uv_req_s {
407   UV_REQ_FIELDS
408 };
409 
410 
411 /* Platform-specific request types. */
412 UV_PRIVATE_REQ_TYPES
413 
414 
415 UV_EXTERN int uv_shutdown(uv_shutdown_t* req,
416                           uv_stream_t* handle,
417                           uv_shutdown_cb cb);
418 
419 struct uv_shutdown_s {
420   UV_REQ_FIELDS
421   uv_stream_t* handle;
422   uv_shutdown_cb cb;
423   UV_SHUTDOWN_PRIVATE_FIELDS
424 };
425 
426 
427 #define UV_HANDLE_FIELDS                                                      \
428   /* public */                                                                \
429   void* data;                                                                 \
430   /* read-only */                                                             \
431   uv_loop_t* loop;                                                            \
432   uv_handle_type type;                                                        \
433   /* private */                                                               \
434   uv_close_cb close_cb;                                                       \
435   void* handle_queue[2];                                                      \
436   union {                                                                     \
437     int fd;                                                                   \
438     void* reserved[4];                                                        \
439   } u;                                                                        \
440   UV_HANDLE_PRIVATE_FIELDS                                                    \
441 
442 /* The abstract base class of all handles. */
443 struct uv_handle_s {
444   UV_HANDLE_FIELDS
445 };
446 
447 UV_EXTERN size_t uv_handle_size(uv_handle_type type);
448 UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle);
449 UV_EXTERN const char* uv_handle_type_name(uv_handle_type type);
450 UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle);
451 UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle);
452 UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data);
453 
454 UV_EXTERN size_t uv_req_size(uv_req_type type);
455 UV_EXTERN void* uv_req_get_data(const uv_req_t* req);
456 UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data);
457 UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req);
458 UV_EXTERN const char* uv_req_type_name(uv_req_type type);
459 
460 UV_EXTERN int uv_is_active(const uv_handle_t* handle);
461 
462 UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
463 
464 /* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */
465 UV_EXTERN void uv_print_all_handles(uv_loop_t* loop, FILE* stream);
466 UV_EXTERN void uv_print_active_handles(uv_loop_t* loop, FILE* stream);
467 
468 UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
469 
470 UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value);
471 UV_EXTERN int uv_recv_buffer_size(uv_handle_t* handle, int* value);
472 
473 UV_EXTERN int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd);
474 
475 UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
476 
477 
478 #define UV_STREAM_FIELDS                                                      \
479   /* number of bytes queued for writing */                                    \
480   size_t write_queue_size;                                                    \
481   uv_alloc_cb alloc_cb;                                                       \
482   uv_read_cb read_cb;                                                         \
483   /* private */                                                               \
484   UV_STREAM_PRIVATE_FIELDS
485 
486 /*
487  * uv_stream_t is a subclass of uv_handle_t.
488  *
489  * uv_stream is an abstract class.
490  *
491  * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t.
492  */
493 struct uv_stream_s {
494   UV_HANDLE_FIELDS
495   UV_STREAM_FIELDS
496 };
497 
498 UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);
499 
500 UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
501 UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
502 
503 UV_EXTERN int uv_read_start(uv_stream_t*,
504                             uv_alloc_cb alloc_cb,
505                             uv_read_cb read_cb);
506 UV_EXTERN int uv_read_stop(uv_stream_t*);
507 
508 UV_EXTERN int uv_write(uv_write_t* req,
509                        uv_stream_t* handle,
510                        const uv_buf_t bufs[],
511                        unsigned int nbufs,
512                        uv_write_cb cb);
513 UV_EXTERN int uv_write2(uv_write_t* req,
514                         uv_stream_t* handle,
515                         const uv_buf_t bufs[],
516                         unsigned int nbufs,
517                         uv_stream_t* send_handle,
518                         uv_write_cb cb);
519 UV_EXTERN int uv_try_write(uv_stream_t* handle,
520                            const uv_buf_t bufs[],
521                            unsigned int nbufs);
522 
523 /* uv_write_t is a subclass of uv_req_t. */
524 struct uv_write_s {
525   UV_REQ_FIELDS
526   uv_write_cb cb;
527   uv_stream_t* send_handle; /* TODO: make private and unix-only in v2.x. */
528   uv_stream_t* handle;
529   UV_WRITE_PRIVATE_FIELDS
530 };
531 
532 
533 UV_EXTERN int uv_is_readable(const uv_stream_t* handle);
534 UV_EXTERN int uv_is_writable(const uv_stream_t* handle);
535 
536 UV_EXTERN int uv_stream_set_blocking(uv_stream_t* handle, int blocking);
537 
538 UV_EXTERN int uv_is_closing(const uv_handle_t* handle);
539 
540 
541 /*
542  * uv_tcp_t is a subclass of uv_stream_t.
543  *
544  * Represents a TCP stream or TCP server.
545  */
546 struct uv_tcp_s {
547   UV_HANDLE_FIELDS
548   UV_STREAM_FIELDS
549   UV_TCP_PRIVATE_FIELDS
550 };
551 
552 UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
553 UV_EXTERN int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags);
554 UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
555 UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
556 UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
557                                int enable,
558                                unsigned int delay);
559 UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
560 
561 enum uv_tcp_flags {
562   /* Used with uv_tcp_bind, when an IPv6 address is used. */
563   UV_TCP_IPV6ONLY = 1
564 };
565 
566 UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
567                           const struct sockaddr* addr,
568                           unsigned int flags);
569 UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle,
570                                  struct sockaddr* name,
571                                  int* namelen);
572 UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle,
573                                  struct sockaddr* name,
574                                  int* namelen);
575 UV_EXTERN int uv_tcp_close_reset(uv_tcp_t* handle, uv_close_cb close_cb);
576 UV_EXTERN int uv_tcp_connect(uv_connect_t* req,
577                              uv_tcp_t* handle,
578                              const struct sockaddr* addr,
579                              uv_connect_cb cb);
580 
581 /* uv_connect_t is a subclass of uv_req_t. */
582 struct uv_connect_s {
583   UV_REQ_FIELDS
584   uv_connect_cb cb;
585   uv_stream_t* handle;
586   UV_CONNECT_PRIVATE_FIELDS
587 };
588 
589 
590 /*
591  * UDP support.
592  */
593 
594 enum uv_udp_flags {
595   /* Disables dual stack mode. */
596   UV_UDP_IPV6ONLY = 1,
597   /*
598    * Indicates message was truncated because read buffer was too small. The
599    * remainder was discarded by the OS. Used in uv_udp_recv_cb.
600    */
601   UV_UDP_PARTIAL = 2,
602   /*
603    * Indicates if SO_REUSEADDR will be set when binding the handle.
604    * This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
605    * Unix platforms, it sets the SO_REUSEADDR flag.  What that means is that
606    * multiple threads or processes can bind to the same address without error
607    * (provided they all set the flag) but only the last one to bind will receive
608    * any traffic, in effect "stealing" the port from the previous listener.
609    */
610   UV_UDP_REUSEADDR = 4,
611   /*
612    * Indicates that the message was received by recvmmsg, so the buffer provided
613    * must not be freed by the recv_cb callback.
614    */
615   UV_UDP_MMSG_CHUNK = 8,
616 
617   /*
618    * Indicates that recvmmsg should be used, if available.
619    */
620   UV_UDP_RECVMMSG = 256
621 };
622 
623 typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
624 typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
625                                ssize_t nread,
626                                const uv_buf_t* buf,
627                                const struct sockaddr* addr,
628                                unsigned flags);
629 
630 /* uv_udp_t is a subclass of uv_handle_t. */
631 struct uv_udp_s {
632   UV_HANDLE_FIELDS
633   /* read-only */
634   /*
635    * Number of bytes queued for sending. This field strictly shows how much
636    * information is currently queued.
637    */
638   size_t send_queue_size;
639   /*
640    * Number of send requests currently in the queue awaiting to be processed.
641    */
642   size_t send_queue_count;
643   UV_UDP_PRIVATE_FIELDS
644 };
645 
646 /* uv_udp_send_t is a subclass of uv_req_t. */
647 struct uv_udp_send_s {
648   UV_REQ_FIELDS
649   uv_udp_t* handle;
650   uv_udp_send_cb cb;
651   UV_UDP_SEND_PRIVATE_FIELDS
652 };
653 
654 UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
655 UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
656 UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
657 UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
658                           const struct sockaddr* addr,
659                           unsigned int flags);
660 UV_EXTERN int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr);
661 
662 UV_EXTERN int uv_udp_getpeername(const uv_udp_t* handle,
663                                  struct sockaddr* name,
664                                  int* namelen);
665 UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
666                                  struct sockaddr* name,
667                                  int* namelen);
668 UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
669                                     const char* multicast_addr,
670                                     const char* interface_addr,
671                                     uv_membership membership);
672 UV_EXTERN int uv_udp_set_source_membership(uv_udp_t* handle,
673                                            const char* multicast_addr,
674                                            const char* interface_addr,
675                                            const char* source_addr,
676                                            uv_membership membership);
677 UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
678 UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
679 UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle,
680                                              const char* interface_addr);
681 UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
682 UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
683 UV_EXTERN int uv_udp_send(uv_udp_send_t* req,
684                           uv_udp_t* handle,
685                           const uv_buf_t bufs[],
686                           unsigned int nbufs,
687                           const struct sockaddr* addr,
688                           uv_udp_send_cb send_cb);
689 UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
690                               const uv_buf_t bufs[],
691                               unsigned int nbufs,
692                               const struct sockaddr* addr);
693 UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
694                                 uv_alloc_cb alloc_cb,
695                                 uv_udp_recv_cb recv_cb);
696 UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
697 UV_EXTERN size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
698 UV_EXTERN size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);
699 
700 
701 /*
702  * uv_tty_t is a subclass of uv_stream_t.
703  *
704  * Representing a stream for the console.
705  */
706 struct uv_tty_s {
707   UV_HANDLE_FIELDS
708   UV_STREAM_FIELDS
709   UV_TTY_PRIVATE_FIELDS
710 };
711 
712 typedef enum {
713   /* Initial/normal terminal mode */
714   UV_TTY_MODE_NORMAL,
715   /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
716   UV_TTY_MODE_RAW,
717   /* Binary-safe I/O mode for IPC (Unix-only) */
718   UV_TTY_MODE_IO
719 } uv_tty_mode_t;
720 
721 typedef enum {
722   /*
723    * The console supports handling of virtual terminal sequences
724    * (Windows10 new console, ConEmu)
725    */
726   UV_TTY_SUPPORTED,
727   /* The console cannot process the virtual terminal sequence.  (Legacy
728    * console)
729    */
730   UV_TTY_UNSUPPORTED
731 } uv_tty_vtermstate_t;
732 
733 
734 UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
735 UV_EXTERN int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode);
736 UV_EXTERN int uv_tty_reset_mode(void);
737 UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);
738 UV_EXTERN void uv_tty_set_vterm_state(uv_tty_vtermstate_t state);
739 UV_EXTERN int uv_tty_get_vterm_state(uv_tty_vtermstate_t* state);
740 
741 #ifdef __cplusplus
742 extern "C++" {
743 
uv_tty_set_mode(uv_tty_t * handle,int mode)744 inline int uv_tty_set_mode(uv_tty_t* handle, int mode) {
745   return uv_tty_set_mode(handle, static_cast<uv_tty_mode_t>(mode));
746 }
747 
748 }
749 #endif
750 
751 UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
752 
753 /*
754  * uv_pipe_t is a subclass of uv_stream_t.
755  *
756  * Representing a pipe stream or pipe server. On Windows this is a Named
757  * Pipe. On Unix this is a Unix domain socket.
758  */
759 struct uv_pipe_s {
760   UV_HANDLE_FIELDS
761   UV_STREAM_FIELDS
762   int ipc; /* non-zero if this pipe is used for passing handles */
763   UV_PIPE_PRIVATE_FIELDS
764 };
765 
766 UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
767 UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
768 UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
769 UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
770                                uv_pipe_t* handle,
771                                const char* name,
772                                uv_connect_cb cb);
773 UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
774                                   char* buffer,
775                                   size_t* size);
776 UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
777                                   char* buffer,
778                                   size_t* size);
779 UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
780 UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle);
781 UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
782 UV_EXTERN int uv_pipe_chmod(uv_pipe_t* handle, int flags);
783 
784 
785 struct uv_poll_s {
786   UV_HANDLE_FIELDS
787   uv_poll_cb poll_cb;
788   UV_POLL_PRIVATE_FIELDS
789 };
790 
791 enum uv_poll_event {
792   UV_READABLE = 1,
793   UV_WRITABLE = 2,
794   UV_DISCONNECT = 4,
795   UV_PRIORITIZED = 8
796 };
797 
798 UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
799 UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop,
800                                   uv_poll_t* handle,
801                                   uv_os_sock_t socket);
802 UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb);
803 UV_EXTERN int uv_poll_stop(uv_poll_t* handle);
804 
805 
806 struct uv_prepare_s {
807   UV_HANDLE_FIELDS
808   UV_PREPARE_PRIVATE_FIELDS
809 };
810 
811 UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
812 UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
813 UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare);
814 
815 
816 struct uv_check_s {
817   UV_HANDLE_FIELDS
818   UV_CHECK_PRIVATE_FIELDS
819 };
820 
821 UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check);
822 UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb);
823 UV_EXTERN int uv_check_stop(uv_check_t* check);
824 
825 
826 struct uv_idle_s {
827   UV_HANDLE_FIELDS
828   UV_IDLE_PRIVATE_FIELDS
829 };
830 
831 UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle);
832 UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);
833 UV_EXTERN int uv_idle_stop(uv_idle_t* idle);
834 
835 
836 struct uv_async_s {
837   UV_HANDLE_FIELDS
838   UV_ASYNC_PRIVATE_FIELDS
839 };
840 
841 UV_EXTERN int uv_async_init(uv_loop_t*,
842                             uv_async_t* async,
843                             uv_async_cb async_cb);
844 UV_EXTERN int uv_async_send(uv_async_t* async);
845 
846 
847 /*
848  * uv_timer_t is a subclass of uv_handle_t.
849  *
850  * Used to get woken up at a specified time in the future.
851  */
852 struct uv_timer_s {
853   UV_HANDLE_FIELDS
854   UV_TIMER_PRIVATE_FIELDS
855 };
856 
857 UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
858 UV_EXTERN int uv_timer_start(uv_timer_t* handle,
859                              uv_timer_cb cb,
860                              uint64_t timeout,
861                              uint64_t repeat);
862 UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
863 UV_EXTERN int uv_timer_again(uv_timer_t* handle);
864 UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
865 UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
866 
867 
868 /*
869  * uv_getaddrinfo_t is a subclass of uv_req_t.
870  *
871  * Request object for uv_getaddrinfo.
872  */
873 struct uv_getaddrinfo_s {
874   UV_REQ_FIELDS
875   /* read-only */
876   uv_loop_t* loop;
877   /* struct addrinfo* addrinfo is marked as private, but it really isn't. */
878   UV_GETADDRINFO_PRIVATE_FIELDS
879 };
880 
881 
882 UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop,
883                              uv_getaddrinfo_t* req,
884                              uv_getaddrinfo_cb getaddrinfo_cb,
885                              const char* node,
886                              const char* service,
887                              const struct addrinfo* hints);
888 UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
889 
890 
891 /*
892 * uv_getnameinfo_t is a subclass of uv_req_t.
893 *
894 * Request object for uv_getnameinfo.
895 */
896 struct uv_getnameinfo_s {
897   UV_REQ_FIELDS
898   /* read-only */
899   uv_loop_t* loop;
900   /* host and service are marked as private, but they really aren't. */
901   UV_GETNAMEINFO_PRIVATE_FIELDS
902 };
903 
904 UV_EXTERN int uv_getnameinfo(uv_loop_t* loop,
905                              uv_getnameinfo_t* req,
906                              uv_getnameinfo_cb getnameinfo_cb,
907                              const struct sockaddr* addr,
908                              int flags);
909 
910 
911 /* uv_spawn() options. */
912 typedef enum {
913   UV_IGNORE         = 0x00,
914   UV_CREATE_PIPE    = 0x01,
915   UV_INHERIT_FD     = 0x02,
916   UV_INHERIT_STREAM = 0x04,
917 
918   /*
919    * When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
920    * determine the direction of flow, from the child process' perspective. Both
921    * flags may be specified to create a duplex data stream.
922    */
923   UV_READABLE_PIPE  = 0x10,
924   UV_WRITABLE_PIPE  = 0x20,
925 
926   /*
927    * Open the child pipe handle in overlapped mode on Windows.
928    * On Unix it is silently ignored.
929    */
930   UV_OVERLAPPED_PIPE = 0x40
931 } uv_stdio_flags;
932 
933 typedef struct uv_stdio_container_s {
934   uv_stdio_flags flags;
935 
936   union {
937     uv_stream_t* stream;
938     int fd;
939   } data;
940 } uv_stdio_container_t;
941 
942 typedef struct uv_process_options_s {
943   uv_exit_cb exit_cb; /* Called after the process exits. */
944   const char* file;   /* Path to program to execute. */
945   /*
946    * Command line arguments. args[0] should be the path to the program. On
947    * Windows this uses CreateProcess which concatenates the arguments into a
948    * string this can cause some strange errors. See the note at
949    * windows_verbatim_arguments.
950    */
951   char** args;
952   /*
953    * This will be set as the environ variable in the subprocess. If this is
954    * NULL then the parents environ will be used.
955    */
956   char** env;
957   /*
958    * If non-null this represents a directory the subprocess should execute
959    * in. Stands for current working directory.
960    */
961   const char* cwd;
962   /*
963    * Various flags that control how uv_spawn() behaves. See the definition of
964    * `enum uv_process_flags` below.
965    */
966   unsigned int flags;
967   /*
968    * The `stdio` field points to an array of uv_stdio_container_t structs that
969    * describe the file descriptors that will be made available to the child
970    * process. The convention is that stdio[0] points to stdin, fd 1 is used for
971    * stdout, and fd 2 is stderr.
972    *
973    * Note that on windows file descriptors greater than 2 are available to the
974    * child process only if the child processes uses the MSVCRT runtime.
975    */
976   int stdio_count;
977   uv_stdio_container_t* stdio;
978   /*
979    * Libuv can change the child process' user/group id. This happens only when
980    * the appropriate bits are set in the flags fields. This is not supported on
981    * windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
982    */
983   uv_uid_t uid;
984   uv_gid_t gid;
985 } uv_process_options_t;
986 
987 /*
988  * These are the flags that can be used for the uv_process_options.flags field.
989  */
990 enum uv_process_flags {
991   /*
992    * Set the child process' user id. The user id is supplied in the `uid` field
993    * of the options struct. This does not work on windows; setting this flag
994    * will cause uv_spawn() to fail.
995    */
996   UV_PROCESS_SETUID = (1 << 0),
997   /*
998    * Set the child process' group id. The user id is supplied in the `gid`
999    * field of the options struct. This does not work on windows; setting this
1000    * flag will cause uv_spawn() to fail.
1001    */
1002   UV_PROCESS_SETGID = (1 << 1),
1003   /*
1004    * Do not wrap any arguments in quotes, or perform any other escaping, when
1005    * converting the argument list into a command line string. This option is
1006    * only meaningful on Windows systems. On Unix it is silently ignored.
1007    */
1008   UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
1009   /*
1010    * Spawn the child process in a detached state - this will make it a process
1011    * group leader, and will effectively enable the child to keep running after
1012    * the parent exits.  Note that the child process will still keep the
1013    * parent's event loop alive unless the parent process calls uv_unref() on
1014    * the child's process handle.
1015    */
1016   UV_PROCESS_DETACHED = (1 << 3),
1017   /*
1018    * Hide the subprocess window that would normally be created. This option is
1019    * only meaningful on Windows systems. On Unix it is silently ignored.
1020    */
1021   UV_PROCESS_WINDOWS_HIDE = (1 << 4),
1022   /*
1023    * Hide the subprocess console window that would normally be created. This
1024    * option is only meaningful on Windows systems. On Unix it is silently
1025    * ignored.
1026    */
1027   UV_PROCESS_WINDOWS_HIDE_CONSOLE = (1 << 5),
1028   /*
1029    * Hide the subprocess GUI window that would normally be created. This
1030    * option is only meaningful on Windows systems. On Unix it is silently
1031    * ignored.
1032    */
1033   UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
1034 };
1035 
1036 /*
1037  * uv_process_t is a subclass of uv_handle_t.
1038  */
1039 struct uv_process_s {
1040   UV_HANDLE_FIELDS
1041   uv_exit_cb exit_cb;
1042   int pid;
1043   UV_PROCESS_PRIVATE_FIELDS
1044 };
1045 
1046 UV_EXTERN int uv_spawn(uv_loop_t* loop,
1047                        uv_process_t* handle,
1048                        const uv_process_options_t* options);
1049 UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
1050 UV_EXTERN int uv_kill(int pid, int signum);
1051 UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
1052 
1053 
1054 /*
1055  * uv_work_t is a subclass of uv_req_t.
1056  */
1057 struct uv_work_s {
1058   UV_REQ_FIELDS
1059   uv_loop_t* loop;
1060   uv_work_cb work_cb;
1061   uv_after_work_cb after_work_cb;
1062   UV_WORK_PRIVATE_FIELDS
1063 };
1064 
1065 UV_EXTERN int uv_queue_work(uv_loop_t* loop,
1066                             uv_work_t* req,
1067                             uv_work_cb work_cb,
1068                             uv_after_work_cb after_work_cb);
1069 
1070 UV_EXTERN int uv_cancel(uv_req_t* req);
1071 
1072 
1073 struct uv_cpu_times_s {
1074   uint64_t user; /* milliseconds */
1075   uint64_t nice; /* milliseconds */
1076   uint64_t sys; /* milliseconds */
1077   uint64_t idle; /* milliseconds */
1078   uint64_t irq; /* milliseconds */
1079 };
1080 
1081 struct uv_cpu_info_s {
1082   char* model;
1083   int speed;
1084   struct uv_cpu_times_s cpu_times;
1085 };
1086 
1087 struct uv_interface_address_s {
1088   char* name;
1089   char phys_addr[6];
1090   int is_internal;
1091   union {
1092     struct sockaddr_in address4;
1093     struct sockaddr_in6 address6;
1094   } address;
1095   union {
1096     struct sockaddr_in netmask4;
1097     struct sockaddr_in6 netmask6;
1098   } netmask;
1099 };
1100 
1101 struct uv_passwd_s {
1102   char* username;
1103   long uid;
1104   long gid;
1105   char* shell;
1106   char* homedir;
1107 };
1108 
1109 struct uv_utsname_s {
1110   char sysname[256];
1111   char release[256];
1112   char version[256];
1113   char machine[256];
1114   /* This struct does not contain the nodename and domainname fields present in
1115      the utsname type. domainname is a GNU extension. Both fields are referred
1116      to as meaningless in the docs. */
1117 };
1118 
1119 struct uv_statfs_s {
1120   uint64_t f_type;
1121   uint64_t f_bsize;
1122   uint64_t f_blocks;
1123   uint64_t f_bfree;
1124   uint64_t f_bavail;
1125   uint64_t f_files;
1126   uint64_t f_ffree;
1127   uint64_t f_spare[4];
1128 };
1129 
1130 typedef enum {
1131   UV_DIRENT_UNKNOWN,
1132   UV_DIRENT_FILE,
1133   UV_DIRENT_DIR,
1134   UV_DIRENT_LINK,
1135   UV_DIRENT_FIFO,
1136   UV_DIRENT_SOCKET,
1137   UV_DIRENT_CHAR,
1138   UV_DIRENT_BLOCK
1139 } uv_dirent_type_t;
1140 
1141 struct uv_dirent_s {
1142   const char* name;
1143   uv_dirent_type_t type;
1144 };
1145 
1146 UV_EXTERN char** uv_setup_args(int argc, char** argv);
1147 UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
1148 UV_EXTERN int uv_set_process_title(const char* title);
1149 UV_EXTERN int uv_resident_set_memory(size_t* rss);
1150 UV_EXTERN int uv_uptime(double* uptime);
1151 UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
1152 UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
1153 
1154 typedef struct {
1155   long tv_sec;
1156   long tv_usec;
1157 } uv_timeval_t;
1158 
1159 typedef struct {
1160   int64_t tv_sec;
1161   int32_t tv_usec;
1162 } uv_timeval64_t;
1163 
1164 typedef struct {
1165    uv_timeval_t ru_utime; /* user CPU time used */
1166    uv_timeval_t ru_stime; /* system CPU time used */
1167    uint64_t ru_maxrss;    /* maximum resident set size */
1168    uint64_t ru_ixrss;     /* integral shared memory size */
1169    uint64_t ru_idrss;     /* integral unshared data size */
1170    uint64_t ru_isrss;     /* integral unshared stack size */
1171    uint64_t ru_minflt;    /* page reclaims (soft page faults) */
1172    uint64_t ru_majflt;    /* page faults (hard page faults) */
1173    uint64_t ru_nswap;     /* swaps */
1174    uint64_t ru_inblock;   /* block input operations */
1175    uint64_t ru_oublock;   /* block output operations */
1176    uint64_t ru_msgsnd;    /* IPC messages sent */
1177    uint64_t ru_msgrcv;    /* IPC messages received */
1178    uint64_t ru_nsignals;  /* signals received */
1179    uint64_t ru_nvcsw;     /* voluntary context switches */
1180    uint64_t ru_nivcsw;    /* involuntary context switches */
1181 } uv_rusage_t;
1182 
1183 UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
1184 
1185 UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
1186 UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
1187 UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
1188 UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
1189 UV_EXTERN uv_pid_t uv_os_getpid(void);
1190 UV_EXTERN uv_pid_t uv_os_getppid(void);
1191 
1192 #if defined(__PASE__)
1193 /* On IBM i PASE, the highest process priority is -10 */
1194 # define UV_PRIORITY_LOW 39
1195 # define UV_PRIORITY_BELOW_NORMAL 15
1196 # define UV_PRIORITY_NORMAL 0
1197 # define UV_PRIORITY_ABOVE_NORMAL -4
1198 # define UV_PRIORITY_HIGH -7
1199 # define UV_PRIORITY_HIGHEST -10
1200 #else
1201 # define UV_PRIORITY_LOW 19
1202 # define UV_PRIORITY_BELOW_NORMAL 10
1203 # define UV_PRIORITY_NORMAL 0
1204 # define UV_PRIORITY_ABOVE_NORMAL -7
1205 # define UV_PRIORITY_HIGH -14
1206 # define UV_PRIORITY_HIGHEST -20
1207 #endif
1208 
1209 UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
1210 UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
1211 
1212 UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1213 UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1214 
1215 UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
1216                                      int* count);
1217 UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1218                                            int count);
1219 
1220 struct uv_env_item_s {
1221   char* name;
1222   char* value;
1223 };
1224 
1225 UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
1226 UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
1227 UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
1228 UV_EXTERN int uv_os_setenv(const char* name, const char* value);
1229 UV_EXTERN int uv_os_unsetenv(const char* name);
1230 
1231 #ifdef MAXHOSTNAMELEN
1232 # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
1233 #else
1234   /*
1235     Fallback for the maximum hostname size, including the null terminator. The
1236     Windows gethostname() documentation states that 256 bytes will always be
1237     large enough to hold the null-terminated hostname.
1238   */
1239 # define UV_MAXHOSTNAMESIZE 256
1240 #endif
1241 
1242 UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
1243 
1244 UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
1245 
1246 
1247 typedef enum {
1248   UV_FS_UNKNOWN = -1,
1249   UV_FS_CUSTOM,
1250   UV_FS_OPEN,
1251   UV_FS_CLOSE,
1252   UV_FS_READ,
1253   UV_FS_WRITE,
1254   UV_FS_SENDFILE,
1255   UV_FS_STAT,
1256   UV_FS_LSTAT,
1257   UV_FS_FSTAT,
1258   UV_FS_FTRUNCATE,
1259   UV_FS_UTIME,
1260   UV_FS_FUTIME,
1261   UV_FS_ACCESS,
1262   UV_FS_CHMOD,
1263   UV_FS_FCHMOD,
1264   UV_FS_FSYNC,
1265   UV_FS_FDATASYNC,
1266   UV_FS_UNLINK,
1267   UV_FS_RMDIR,
1268   UV_FS_MKDIR,
1269   UV_FS_MKDTEMP,
1270   UV_FS_RENAME,
1271   UV_FS_SCANDIR,
1272   UV_FS_LINK,
1273   UV_FS_SYMLINK,
1274   UV_FS_READLINK,
1275   UV_FS_CHOWN,
1276   UV_FS_FCHOWN,
1277   UV_FS_REALPATH,
1278   UV_FS_COPYFILE,
1279   UV_FS_LCHOWN,
1280   UV_FS_OPENDIR,
1281   UV_FS_READDIR,
1282   UV_FS_CLOSEDIR,
1283   UV_FS_STATFS,
1284   UV_FS_MKSTEMP,
1285   UV_FS_LUTIME
1286 } uv_fs_type;
1287 
1288 struct uv_dir_s {
1289   uv_dirent_t* dirents;
1290   size_t nentries;
1291   void* reserved[4];
1292   UV_DIR_PRIVATE_FIELDS
1293 };
1294 
1295 /* uv_fs_t is a subclass of uv_req_t. */
1296 struct uv_fs_s {
1297   UV_REQ_FIELDS
1298   uv_fs_type fs_type;
1299   uv_loop_t* loop;
1300   uv_fs_cb cb;
1301   ssize_t result;
1302   void* ptr;
1303   const char* path;
1304   uv_stat_t statbuf;  /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
1305   UV_FS_PRIVATE_FIELDS
1306 };
1307 
1308 UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
1309 UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
1310 UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
1311 UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
1312 UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
1313 UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
1314 
1315 UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1316 UV_EXTERN int uv_fs_close(uv_loop_t* loop,
1317                           uv_fs_t* req,
1318                           uv_file file,
1319                           uv_fs_cb cb);
1320 UV_EXTERN int uv_fs_open(uv_loop_t* loop,
1321                          uv_fs_t* req,
1322                          const char* path,
1323                          int flags,
1324                          int mode,
1325                          uv_fs_cb cb);
1326 UV_EXTERN int uv_fs_read(uv_loop_t* loop,
1327                          uv_fs_t* req,
1328                          uv_file file,
1329                          const uv_buf_t bufs[],
1330                          unsigned int nbufs,
1331                          int64_t offset,
1332                          uv_fs_cb cb);
1333 UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
1334                            uv_fs_t* req,
1335                            const char* path,
1336                            uv_fs_cb cb);
1337 UV_EXTERN int uv_fs_write(uv_loop_t* loop,
1338                           uv_fs_t* req,
1339                           uv_file file,
1340                           const uv_buf_t bufs[],
1341                           unsigned int nbufs,
1342                           int64_t offset,
1343                           uv_fs_cb cb);
1344 /*
1345  * This flag can be used with uv_fs_copyfile() to return an error if the
1346  * destination already exists.
1347  */
1348 #define UV_FS_COPYFILE_EXCL   0x0001
1349 
1350 /*
1351  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1352  * If copy-on-write is not supported, a fallback copy mechanism is used.
1353  */
1354 #define UV_FS_COPYFILE_FICLONE 0x0002
1355 
1356 /*
1357  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1358  * If copy-on-write is not supported, an error is returned.
1359  */
1360 #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
1361 
1362 UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
1363                              uv_fs_t* req,
1364                              const char* path,
1365                              const char* new_path,
1366                              int flags,
1367                              uv_fs_cb cb);
1368 UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
1369                           uv_fs_t* req,
1370                           const char* path,
1371                           int mode,
1372                           uv_fs_cb cb);
1373 UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
1374                             uv_fs_t* req,
1375                             const char* tpl,
1376                             uv_fs_cb cb);
1377 UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
1378                             uv_fs_t* req,
1379                             const char* tpl,
1380                             uv_fs_cb cb);
1381 UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
1382                           uv_fs_t* req,
1383                           const char* path,
1384                           uv_fs_cb cb);
1385 UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
1386                             uv_fs_t* req,
1387                             const char* path,
1388                             int flags,
1389                             uv_fs_cb cb);
1390 UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
1391                                  uv_dirent_t* ent);
1392 UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
1393                             uv_fs_t* req,
1394                             const char* path,
1395                             uv_fs_cb cb);
1396 UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
1397                             uv_fs_t* req,
1398                             uv_dir_t* dir,
1399                             uv_fs_cb cb);
1400 UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
1401                              uv_fs_t* req,
1402                              uv_dir_t* dir,
1403                              uv_fs_cb cb);
1404 UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
1405                          uv_fs_t* req,
1406                          const char* path,
1407                          uv_fs_cb cb);
1408 UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
1409                           uv_fs_t* req,
1410                           uv_file file,
1411                           uv_fs_cb cb);
1412 UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
1413                            uv_fs_t* req,
1414                            const char* path,
1415                            const char* new_path,
1416                            uv_fs_cb cb);
1417 UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
1418                           uv_fs_t* req,
1419                           uv_file file,
1420                           uv_fs_cb cb);
1421 UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
1422                               uv_fs_t* req,
1423                               uv_file file,
1424                               uv_fs_cb cb);
1425 UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
1426                               uv_fs_t* req,
1427                               uv_file file,
1428                               int64_t offset,
1429                               uv_fs_cb cb);
1430 UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
1431                              uv_fs_t* req,
1432                              uv_file out_fd,
1433                              uv_file in_fd,
1434                              int64_t in_offset,
1435                              size_t length,
1436                              uv_fs_cb cb);
1437 UV_EXTERN int uv_fs_access(uv_loop_t* loop,
1438                            uv_fs_t* req,
1439                            const char* path,
1440                            int mode,
1441                            uv_fs_cb cb);
1442 UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
1443                           uv_fs_t* req,
1444                           const char* path,
1445                           int mode,
1446                           uv_fs_cb cb);
1447 UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
1448                           uv_fs_t* req,
1449                           const char* path,
1450                           double atime,
1451                           double mtime,
1452                           uv_fs_cb cb);
1453 UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
1454                            uv_fs_t* req,
1455                            uv_file file,
1456                            double atime,
1457                            double mtime,
1458                            uv_fs_cb cb);
1459 UV_EXTERN int uv_fs_lutime(uv_loop_t* loop,
1460                            uv_fs_t* req,
1461                            const char* path,
1462                            double atime,
1463                            double mtime,
1464                            uv_fs_cb cb);
1465 UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
1466                           uv_fs_t* req,
1467                           const char* path,
1468                           uv_fs_cb cb);
1469 UV_EXTERN int uv_fs_link(uv_loop_t* loop,
1470                          uv_fs_t* req,
1471                          const char* path,
1472                          const char* new_path,
1473                          uv_fs_cb cb);
1474 
1475 /*
1476  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1477  * path argument points to a directory.
1478  */
1479 #define UV_FS_SYMLINK_DIR          0x0001
1480 
1481 /*
1482  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1483  * the symlink is to be created using junction points.
1484  */
1485 #define UV_FS_SYMLINK_JUNCTION     0x0002
1486 
1487 UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
1488                             uv_fs_t* req,
1489                             const char* path,
1490                             const char* new_path,
1491                             int flags,
1492                             uv_fs_cb cb);
1493 UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
1494                              uv_fs_t* req,
1495                              const char* path,
1496                              uv_fs_cb cb);
1497 UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
1498                              uv_fs_t* req,
1499                              const char* path,
1500                              uv_fs_cb cb);
1501 UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
1502                            uv_fs_t* req,
1503                            uv_file file,
1504                            int mode,
1505                            uv_fs_cb cb);
1506 UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
1507                           uv_fs_t* req,
1508                           const char* path,
1509                           uv_uid_t uid,
1510                           uv_gid_t gid,
1511                           uv_fs_cb cb);
1512 UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
1513                            uv_fs_t* req,
1514                            uv_file file,
1515                            uv_uid_t uid,
1516                            uv_gid_t gid,
1517                            uv_fs_cb cb);
1518 UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
1519                            uv_fs_t* req,
1520                            const char* path,
1521                            uv_uid_t uid,
1522                            uv_gid_t gid,
1523                            uv_fs_cb cb);
1524 UV_EXTERN int uv_fs_statfs(uv_loop_t* loop,
1525                            uv_fs_t* req,
1526                            const char* path,
1527                            uv_fs_cb cb);
1528 
1529 
1530 enum uv_fs_event {
1531   UV_RENAME = 1,
1532   UV_CHANGE = 2
1533 };
1534 
1535 
1536 struct uv_fs_event_s {
1537   UV_HANDLE_FIELDS
1538   /* private */
1539   char* path;
1540   UV_FS_EVENT_PRIVATE_FIELDS
1541 };
1542 
1543 
1544 /*
1545  * uv_fs_stat() based polling file watcher.
1546  */
1547 struct uv_fs_poll_s {
1548   UV_HANDLE_FIELDS
1549   /* Private, don't touch. */
1550   void* poll_ctx;
1551 };
1552 
1553 UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1554 UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1555                                uv_fs_poll_cb poll_cb,
1556                                const char* path,
1557                                unsigned int interval);
1558 UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1559 UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
1560                                  char* buffer,
1561                                  size_t* size);
1562 
1563 
1564 struct uv_signal_s {
1565   UV_HANDLE_FIELDS
1566   uv_signal_cb signal_cb;
1567   int signum;
1568   UV_SIGNAL_PRIVATE_FIELDS
1569 };
1570 
1571 UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
1572 UV_EXTERN int uv_signal_start(uv_signal_t* handle,
1573                               uv_signal_cb signal_cb,
1574                               int signum);
1575 UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
1576                                       uv_signal_cb signal_cb,
1577                                       int signum);
1578 UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
1579 
1580 UV_EXTERN void uv_loadavg(double avg[3]);
1581 
1582 
1583 /*
1584  * Flags to be passed to uv_fs_event_start().
1585  */
1586 enum uv_fs_event_flags {
1587   /*
1588    * By default, if the fs event watcher is given a directory name, we will
1589    * watch for all events in that directory. This flags overrides this behavior
1590    * and makes fs_event report only changes to the directory entry itself. This
1591    * flag does not affect individual files watched.
1592    * This flag is currently not implemented yet on any backend.
1593    */
1594   UV_FS_EVENT_WATCH_ENTRY = 1,
1595 
1596   /*
1597    * By default uv_fs_event will try to use a kernel interface such as inotify
1598    * or kqueue to detect events. This may not work on remote filesystems such
1599    * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1600    * regular interval.
1601    * This flag is currently not implemented yet on any backend.
1602    */
1603   UV_FS_EVENT_STAT = 2,
1604 
1605   /*
1606    * By default, event watcher, when watching directory, is not registering
1607    * (is ignoring) changes in it's subdirectories.
1608    * This flag will override this behaviour on platforms that support it.
1609    */
1610   UV_FS_EVENT_RECURSIVE = 4
1611 };
1612 
1613 
1614 UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
1615 UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
1616                                 uv_fs_event_cb cb,
1617                                 const char* path,
1618                                 unsigned int flags);
1619 UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
1620 UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
1621                                   char* buffer,
1622                                   size_t* size);
1623 
1624 UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
1625 UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
1626 
1627 UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
1628 UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
1629 
1630 UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
1631 UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
1632 
1633 
1634 struct uv_random_s {
1635   UV_REQ_FIELDS
1636   /* read-only */
1637   uv_loop_t* loop;
1638   /* private */
1639   int status;
1640   void* buf;
1641   size_t buflen;
1642   uv_random_cb cb;
1643   struct uv__work work_req;
1644 };
1645 
1646 UV_EXTERN int uv_random(uv_loop_t* loop,
1647                         uv_random_t* req,
1648                         void *buf,
1649                         size_t buflen,
1650                         unsigned flags,  /* For future extension; must be 0. */
1651                         uv_random_cb cb);
1652 
1653 #if defined(IF_NAMESIZE)
1654 # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
1655 #elif defined(IFNAMSIZ)
1656 # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
1657 #else
1658 # define UV_IF_NAMESIZE (16 + 1)
1659 #endif
1660 
1661 UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
1662                                 char* buffer,
1663                                 size_t* size);
1664 UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
1665                                char* buffer,
1666                                size_t* size);
1667 
1668 UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1669 
1670 UV_EXTERN int uv_cwd(char* buffer, size_t* size);
1671 
1672 UV_EXTERN int uv_chdir(const char* dir);
1673 
1674 UV_EXTERN uint64_t uv_get_free_memory(void);
1675 UV_EXTERN uint64_t uv_get_total_memory(void);
1676 UV_EXTERN uint64_t uv_get_constrained_memory(void);
1677 
1678 UV_EXTERN uint64_t uv_hrtime(void);
1679 UV_EXTERN void uv_sleep(unsigned int msec);
1680 
1681 UV_EXTERN void uv_disable_stdio_inheritance(void);
1682 
1683 UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1684 UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1685 UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1686 UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
1687 
1688 UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1689 UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
1690 UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1691 UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1692 UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1693 UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1694 
1695 UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1696 UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1697 UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1698 UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1699 UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1700 UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1701 UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1702 UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1703 
1704 UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1705 UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1706 UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1707 UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1708 UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1709 
1710 UV_EXTERN int uv_cond_init(uv_cond_t* cond);
1711 UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
1712 UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
1713 UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
1714 
1715 UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
1716 UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
1717 UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
1718 
1719 UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
1720 UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
1721                                 uv_mutex_t* mutex,
1722                                 uint64_t timeout);
1723 
1724 UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1725 
1726 UV_EXTERN int uv_key_create(uv_key_t* key);
1727 UV_EXTERN void uv_key_delete(uv_key_t* key);
1728 UV_EXTERN void* uv_key_get(uv_key_t* key);
1729 UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
1730 
1731 UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
1732 
1733 typedef void (*uv_thread_cb)(void* arg);
1734 
1735 UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
1736 
1737 typedef enum {
1738   UV_THREAD_NO_FLAGS = 0x00,
1739   UV_THREAD_HAS_STACK_SIZE = 0x01
1740 } uv_thread_create_flags;
1741 
1742 struct uv_thread_options_s {
1743   unsigned int flags;
1744   size_t stack_size;
1745   /* More fields may be added at any time. */
1746 };
1747 
1748 typedef struct uv_thread_options_s uv_thread_options_t;
1749 
1750 UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
1751                                   const uv_thread_options_t* params,
1752                                   uv_thread_cb entry,
1753                                   void* arg);
1754 UV_EXTERN uv_thread_t uv_thread_self(void);
1755 UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1756 UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
1757 
1758 /* The presence of these unions force similar struct layout. */
1759 #define XX(_, name) uv_ ## name ## _t name;
1760 union uv_any_handle {
1761   UV_HANDLE_TYPE_MAP(XX)
1762 };
1763 
1764 union uv_any_req {
1765   UV_REQ_TYPE_MAP(XX)
1766 };
1767 #undef XX
1768 
1769 
1770 struct uv_loop_s {
1771   /* User data - use this for whatever. */
1772   void* data;
1773   /* Loop reference counting. */
1774   unsigned int active_handles;
1775   void* handle_queue[2];
1776   union {
1777     void* unused[2];
1778     unsigned int count;
1779   } active_reqs;
1780   /* Internal flag to signal loop stop. */
1781   unsigned int stop_flag;
1782   UV_LOOP_PRIVATE_FIELDS
1783 };
1784 
1785 UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
1786 UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
1787 
1788 /* Don't export the private CPP symbols. */
1789 #undef UV_HANDLE_TYPE_PRIVATE
1790 #undef UV_REQ_TYPE_PRIVATE
1791 #undef UV_REQ_PRIVATE_FIELDS
1792 #undef UV_STREAM_PRIVATE_FIELDS
1793 #undef UV_TCP_PRIVATE_FIELDS
1794 #undef UV_PREPARE_PRIVATE_FIELDS
1795 #undef UV_CHECK_PRIVATE_FIELDS
1796 #undef UV_IDLE_PRIVATE_FIELDS
1797 #undef UV_ASYNC_PRIVATE_FIELDS
1798 #undef UV_TIMER_PRIVATE_FIELDS
1799 #undef UV_GETADDRINFO_PRIVATE_FIELDS
1800 #undef UV_GETNAMEINFO_PRIVATE_FIELDS
1801 #undef UV_FS_REQ_PRIVATE_FIELDS
1802 #undef UV_WORK_PRIVATE_FIELDS
1803 #undef UV_FS_EVENT_PRIVATE_FIELDS
1804 #undef UV_SIGNAL_PRIVATE_FIELDS
1805 #undef UV_LOOP_PRIVATE_FIELDS
1806 #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
1807 #undef UV__ERR
1808 
1809 #ifdef __cplusplus
1810 }
1811 #endif
1812 #endif /* UV_H */
1813