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