• 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 
1106 struct uv_cpu_times_s {
1107   uint64_t user; /* milliseconds */
1108   uint64_t nice; /* milliseconds */
1109   uint64_t sys; /* milliseconds */
1110   uint64_t idle; /* milliseconds */
1111   uint64_t irq; /* milliseconds */
1112 };
1113 
1114 struct uv_cpu_info_s {
1115   char* model;
1116   int speed;
1117   struct uv_cpu_times_s cpu_times;
1118 };
1119 
1120 struct uv_interface_address_s {
1121   char* name;
1122   char phys_addr[6];
1123   int is_internal;
1124   union {
1125     struct sockaddr_in address4;
1126     struct sockaddr_in6 address6;
1127   } address;
1128   union {
1129     struct sockaddr_in netmask4;
1130     struct sockaddr_in6 netmask6;
1131   } netmask;
1132 };
1133 
1134 struct uv_passwd_s {
1135   char* username;
1136   unsigned long uid;
1137   unsigned long gid;
1138   char* shell;
1139   char* homedir;
1140 };
1141 
1142 struct uv_utsname_s {
1143   char sysname[256];
1144   char release[256];
1145   char version[256];
1146   char machine[256];
1147   /* This struct does not contain the nodename and domainname fields present in
1148      the utsname type. domainname is a GNU extension. Both fields are referred
1149      to as meaningless in the docs. */
1150 };
1151 
1152 struct uv_statfs_s {
1153   uint64_t f_type;
1154   uint64_t f_bsize;
1155   uint64_t f_blocks;
1156   uint64_t f_bfree;
1157   uint64_t f_bavail;
1158   uint64_t f_files;
1159   uint64_t f_ffree;
1160   uint64_t f_spare[4];
1161 };
1162 
1163 typedef enum {
1164   UV_DIRENT_UNKNOWN,
1165   UV_DIRENT_FILE,
1166   UV_DIRENT_DIR,
1167   UV_DIRENT_LINK,
1168   UV_DIRENT_FIFO,
1169   UV_DIRENT_SOCKET,
1170   UV_DIRENT_CHAR,
1171   UV_DIRENT_BLOCK
1172 } uv_dirent_type_t;
1173 
1174 struct uv_dirent_s {
1175   const char* name;
1176   uv_dirent_type_t type;
1177 };
1178 
1179 UV_EXTERN char** uv_setup_args(int argc, char** argv);
1180 UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
1181 UV_EXTERN int uv_set_process_title(const char* title);
1182 UV_EXTERN int uv_resident_set_memory(size_t* rss);
1183 UV_EXTERN int uv_uptime(double* uptime);
1184 UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
1185 UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
1186 
1187 typedef struct {
1188   long tv_sec;
1189   long tv_usec;
1190 } uv_timeval_t;
1191 
1192 typedef struct {
1193   int64_t tv_sec;
1194   int32_t tv_usec;
1195 } uv_timeval64_t;
1196 
1197 typedef struct {
1198    uv_timeval_t ru_utime; /* user CPU time used */
1199    uv_timeval_t ru_stime; /* system CPU time used */
1200    uint64_t ru_maxrss;    /* maximum resident set size */
1201    uint64_t ru_ixrss;     /* integral shared memory size */
1202    uint64_t ru_idrss;     /* integral unshared data size */
1203    uint64_t ru_isrss;     /* integral unshared stack size */
1204    uint64_t ru_minflt;    /* page reclaims (soft page faults) */
1205    uint64_t ru_majflt;    /* page faults (hard page faults) */
1206    uint64_t ru_nswap;     /* swaps */
1207    uint64_t ru_inblock;   /* block input operations */
1208    uint64_t ru_oublock;   /* block output operations */
1209    uint64_t ru_msgsnd;    /* IPC messages sent */
1210    uint64_t ru_msgrcv;    /* IPC messages received */
1211    uint64_t ru_nsignals;  /* signals received */
1212    uint64_t ru_nvcsw;     /* voluntary context switches */
1213    uint64_t ru_nivcsw;    /* involuntary context switches */
1214 } uv_rusage_t;
1215 
1216 UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
1217 
1218 UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
1219 UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
1220 UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
1221 UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
1222 UV_EXTERN uv_pid_t uv_os_getpid(void);
1223 UV_EXTERN uv_pid_t uv_os_getppid(void);
1224 
1225 #if defined(__PASE__)
1226 /* On IBM i PASE, the highest process priority is -10 */
1227 # define UV_PRIORITY_LOW 39          /* RUNPTY(99) */
1228 # define UV_PRIORITY_BELOW_NORMAL 15 /* RUNPTY(50) */
1229 # define UV_PRIORITY_NORMAL 0        /* RUNPTY(20) */
1230 # define UV_PRIORITY_ABOVE_NORMAL -4 /* RUNTY(12) */
1231 # define UV_PRIORITY_HIGH -7         /* RUNPTY(6) */
1232 # define UV_PRIORITY_HIGHEST -10     /* RUNPTY(1) */
1233 #else
1234 # define UV_PRIORITY_LOW 19
1235 # define UV_PRIORITY_BELOW_NORMAL 10
1236 # define UV_PRIORITY_NORMAL 0
1237 # define UV_PRIORITY_ABOVE_NORMAL -7
1238 # define UV_PRIORITY_HIGH -14
1239 # define UV_PRIORITY_HIGHEST -20
1240 #endif
1241 
1242 UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
1243 UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
1244 
1245 UV_EXTERN unsigned int uv_available_parallelism(void);
1246 UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1247 UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1248 
1249 UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
1250                                      int* count);
1251 UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1252                                            int count);
1253 
1254 struct uv_env_item_s {
1255   char* name;
1256   char* value;
1257 };
1258 
1259 UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
1260 UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
1261 UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
1262 UV_EXTERN int uv_os_setenv(const char* name, const char* value);
1263 UV_EXTERN int uv_os_unsetenv(const char* name);
1264 
1265 #ifdef MAXHOSTNAMELEN
1266 # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
1267 #else
1268   /*
1269     Fallback for the maximum hostname size, including the null terminator. The
1270     Windows gethostname() documentation states that 256 bytes will always be
1271     large enough to hold the null-terminated hostname.
1272   */
1273 # define UV_MAXHOSTNAMESIZE 256
1274 #endif
1275 
1276 UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
1277 
1278 UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
1279 
1280 UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
1281 
1282 typedef enum {
1283   UV_FS_UNKNOWN = -1,
1284   UV_FS_CUSTOM,
1285   UV_FS_OPEN,
1286   UV_FS_CLOSE,
1287   UV_FS_READ,
1288   UV_FS_WRITE,
1289   UV_FS_SENDFILE,
1290   UV_FS_STAT,
1291   UV_FS_LSTAT,
1292   UV_FS_FSTAT,
1293   UV_FS_FTRUNCATE,
1294   UV_FS_UTIME,
1295   UV_FS_FUTIME,
1296   UV_FS_ACCESS,
1297   UV_FS_CHMOD,
1298   UV_FS_FCHMOD,
1299   UV_FS_FSYNC,
1300   UV_FS_FDATASYNC,
1301   UV_FS_UNLINK,
1302   UV_FS_RMDIR,
1303   UV_FS_MKDIR,
1304   UV_FS_MKDTEMP,
1305   UV_FS_RENAME,
1306   UV_FS_SCANDIR,
1307   UV_FS_LINK,
1308   UV_FS_SYMLINK,
1309   UV_FS_READLINK,
1310   UV_FS_CHOWN,
1311   UV_FS_FCHOWN,
1312   UV_FS_REALPATH,
1313   UV_FS_COPYFILE,
1314   UV_FS_LCHOWN,
1315   UV_FS_OPENDIR,
1316   UV_FS_READDIR,
1317   UV_FS_CLOSEDIR,
1318   UV_FS_STATFS,
1319   UV_FS_MKSTEMP,
1320   UV_FS_LUTIME
1321 } uv_fs_type;
1322 
1323 struct uv_dir_s {
1324   uv_dirent_t* dirents;
1325   size_t nentries;
1326   void* reserved[4];
1327   UV_DIR_PRIVATE_FIELDS
1328 };
1329 
1330 /* uv_fs_t is a subclass of uv_req_t. */
1331 struct uv_fs_s {
1332   UV_REQ_FIELDS
1333   uv_fs_type fs_type;
1334   uv_loop_t* loop;
1335   uv_fs_cb cb;
1336   ssize_t result;
1337   void* ptr;
1338   const char* path;
1339   uv_stat_t statbuf;  /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
1340   UV_FS_PRIVATE_FIELDS
1341 };
1342 
1343 UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
1344 UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
1345 UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
1346 UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
1347 UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
1348 UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
1349 
1350 UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1351 UV_EXTERN int uv_fs_close(uv_loop_t* loop,
1352                           uv_fs_t* req,
1353                           uv_file file,
1354                           uv_fs_cb cb);
1355 UV_EXTERN int uv_fs_open(uv_loop_t* loop,
1356                          uv_fs_t* req,
1357                          const char* path,
1358                          int flags,
1359                          int mode,
1360                          uv_fs_cb cb);
1361 UV_EXTERN int uv_fs_read(uv_loop_t* loop,
1362                          uv_fs_t* req,
1363                          uv_file file,
1364                          const uv_buf_t bufs[],
1365                          unsigned int nbufs,
1366                          int64_t offset,
1367                          uv_fs_cb cb);
1368 UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
1369                            uv_fs_t* req,
1370                            const char* path,
1371                            uv_fs_cb cb);
1372 UV_EXTERN int uv_fs_write(uv_loop_t* loop,
1373                           uv_fs_t* req,
1374                           uv_file file,
1375                           const uv_buf_t bufs[],
1376                           unsigned int nbufs,
1377                           int64_t offset,
1378                           uv_fs_cb cb);
1379 /*
1380  * This flag can be used with uv_fs_copyfile() to return an error if the
1381  * destination already exists.
1382  */
1383 #define UV_FS_COPYFILE_EXCL   0x0001
1384 
1385 /*
1386  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1387  * If copy-on-write is not supported, a fallback copy mechanism is used.
1388  */
1389 #define UV_FS_COPYFILE_FICLONE 0x0002
1390 
1391 /*
1392  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1393  * If copy-on-write is not supported, an error is returned.
1394  */
1395 #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
1396 
1397 UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
1398                              uv_fs_t* req,
1399                              const char* path,
1400                              const char* new_path,
1401                              int flags,
1402                              uv_fs_cb cb);
1403 UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
1404                           uv_fs_t* req,
1405                           const char* path,
1406                           int mode,
1407                           uv_fs_cb cb);
1408 UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
1409                             uv_fs_t* req,
1410                             const char* tpl,
1411                             uv_fs_cb cb);
1412 UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
1413                             uv_fs_t* req,
1414                             const char* tpl,
1415                             uv_fs_cb cb);
1416 UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
1417                           uv_fs_t* req,
1418                           const char* path,
1419                           uv_fs_cb cb);
1420 UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
1421                             uv_fs_t* req,
1422                             const char* path,
1423                             int flags,
1424                             uv_fs_cb cb);
1425 UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
1426                                  uv_dirent_t* ent);
1427 UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
1428                             uv_fs_t* req,
1429                             const char* path,
1430                             uv_fs_cb cb);
1431 UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
1432                             uv_fs_t* req,
1433                             uv_dir_t* dir,
1434                             uv_fs_cb cb);
1435 UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
1436                              uv_fs_t* req,
1437                              uv_dir_t* dir,
1438                              uv_fs_cb cb);
1439 UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
1440                          uv_fs_t* req,
1441                          const char* path,
1442                          uv_fs_cb cb);
1443 UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
1444                           uv_fs_t* req,
1445                           uv_file file,
1446                           uv_fs_cb cb);
1447 UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
1448                            uv_fs_t* req,
1449                            const char* path,
1450                            const char* new_path,
1451                            uv_fs_cb cb);
1452 UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
1453                           uv_fs_t* req,
1454                           uv_file file,
1455                           uv_fs_cb cb);
1456 UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
1457                               uv_fs_t* req,
1458                               uv_file file,
1459                               uv_fs_cb cb);
1460 UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
1461                               uv_fs_t* req,
1462                               uv_file file,
1463                               int64_t offset,
1464                               uv_fs_cb cb);
1465 UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
1466                              uv_fs_t* req,
1467                              uv_file out_fd,
1468                              uv_file in_fd,
1469                              int64_t in_offset,
1470                              size_t length,
1471                              uv_fs_cb cb);
1472 UV_EXTERN int uv_fs_access(uv_loop_t* loop,
1473                            uv_fs_t* req,
1474                            const char* path,
1475                            int mode,
1476                            uv_fs_cb cb);
1477 UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
1478                           uv_fs_t* req,
1479                           const char* path,
1480                           int mode,
1481                           uv_fs_cb cb);
1482 UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
1483                           uv_fs_t* req,
1484                           const char* path,
1485                           double atime,
1486                           double mtime,
1487                           uv_fs_cb cb);
1488 UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
1489                            uv_fs_t* req,
1490                            uv_file file,
1491                            double atime,
1492                            double mtime,
1493                            uv_fs_cb cb);
1494 UV_EXTERN int uv_fs_lutime(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_lstat(uv_loop_t* loop,
1501                           uv_fs_t* req,
1502                           const char* path,
1503                           uv_fs_cb cb);
1504 UV_EXTERN int uv_fs_link(uv_loop_t* loop,
1505                          uv_fs_t* req,
1506                          const char* path,
1507                          const char* new_path,
1508                          uv_fs_cb cb);
1509 
1510 /*
1511  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1512  * path argument points to a directory.
1513  */
1514 #define UV_FS_SYMLINK_DIR          0x0001
1515 
1516 /*
1517  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1518  * the symlink is to be created using junction points.
1519  */
1520 #define UV_FS_SYMLINK_JUNCTION     0x0002
1521 
1522 UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
1523                             uv_fs_t* req,
1524                             const char* path,
1525                             const char* new_path,
1526                             int flags,
1527                             uv_fs_cb cb);
1528 UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
1529                              uv_fs_t* req,
1530                              const char* path,
1531                              uv_fs_cb cb);
1532 UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
1533                              uv_fs_t* req,
1534                              const char* path,
1535                              uv_fs_cb cb);
1536 UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
1537                            uv_fs_t* req,
1538                            uv_file file,
1539                            int mode,
1540                            uv_fs_cb cb);
1541 UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
1542                           uv_fs_t* req,
1543                           const char* path,
1544                           uv_uid_t uid,
1545                           uv_gid_t gid,
1546                           uv_fs_cb cb);
1547 UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
1548                            uv_fs_t* req,
1549                            uv_file file,
1550                            uv_uid_t uid,
1551                            uv_gid_t gid,
1552                            uv_fs_cb cb);
1553 UV_EXTERN int uv_fs_lchown(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_statfs(uv_loop_t* loop,
1560                            uv_fs_t* req,
1561                            const char* path,
1562                            uv_fs_cb cb);
1563 
1564 
1565 enum uv_fs_event {
1566   UV_RENAME = 1,
1567   UV_CHANGE = 2
1568 };
1569 
1570 
1571 struct uv_fs_event_s {
1572   UV_HANDLE_FIELDS
1573   /* private */
1574   char* path;
1575   UV_FS_EVENT_PRIVATE_FIELDS
1576 };
1577 
1578 
1579 /*
1580  * uv_fs_stat() based polling file watcher.
1581  */
1582 struct uv_fs_poll_s {
1583   UV_HANDLE_FIELDS
1584   /* Private, don't touch. */
1585   void* poll_ctx;
1586 };
1587 
1588 UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1589 UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1590                                uv_fs_poll_cb poll_cb,
1591                                const char* path,
1592                                unsigned int interval);
1593 UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1594 UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
1595                                  char* buffer,
1596                                  size_t* size);
1597 
1598 
1599 struct uv_signal_s {
1600   UV_HANDLE_FIELDS
1601   uv_signal_cb signal_cb;
1602   int signum;
1603   UV_SIGNAL_PRIVATE_FIELDS
1604 };
1605 
1606 UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
1607 UV_EXTERN int uv_signal_start(uv_signal_t* handle,
1608                               uv_signal_cb signal_cb,
1609                               int signum);
1610 UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
1611                                       uv_signal_cb signal_cb,
1612                                       int signum);
1613 UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
1614 
1615 UV_EXTERN void uv_loadavg(double avg[3]);
1616 
1617 
1618 /*
1619  * Flags to be passed to uv_fs_event_start().
1620  */
1621 enum uv_fs_event_flags {
1622   /*
1623    * By default, if the fs event watcher is given a directory name, we will
1624    * watch for all events in that directory. This flags overrides this behavior
1625    * and makes fs_event report only changes to the directory entry itself. This
1626    * flag does not affect individual files watched.
1627    * This flag is currently not implemented yet on any backend.
1628    */
1629   UV_FS_EVENT_WATCH_ENTRY = 1,
1630 
1631   /*
1632    * By default uv_fs_event will try to use a kernel interface such as inotify
1633    * or kqueue to detect events. This may not work on remote filesystems such
1634    * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1635    * regular interval.
1636    * This flag is currently not implemented yet on any backend.
1637    */
1638   UV_FS_EVENT_STAT = 2,
1639 
1640   /*
1641    * By default, event watcher, when watching directory, is not registering
1642    * (is ignoring) changes in it's subdirectories.
1643    * This flag will override this behaviour on platforms that support it.
1644    */
1645   UV_FS_EVENT_RECURSIVE = 4
1646 };
1647 
1648 
1649 UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
1650 UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
1651                                 uv_fs_event_cb cb,
1652                                 const char* path,
1653                                 unsigned int flags);
1654 UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
1655 UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
1656                                   char* buffer,
1657                                   size_t* size);
1658 
1659 UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
1660 UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
1661 
1662 UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
1663 UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
1664 UV_EXTERN int uv_ip_name(const struct sockaddr* src, char* dst, size_t size);
1665 
1666 UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
1667 UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
1668 
1669 
1670 struct uv_random_s {
1671   UV_REQ_FIELDS
1672   /* read-only */
1673   uv_loop_t* loop;
1674   /* private */
1675   int status;
1676   void* buf;
1677   size_t buflen;
1678   uv_random_cb cb;
1679   struct uv__work work_req;
1680 };
1681 
1682 UV_EXTERN int uv_random(uv_loop_t* loop,
1683                         uv_random_t* req,
1684                         void *buf,
1685                         size_t buflen,
1686                         unsigned flags,  /* For future extension; must be 0. */
1687                         uv_random_cb cb);
1688 
1689 #if defined(IF_NAMESIZE)
1690 # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
1691 #elif defined(IFNAMSIZ)
1692 # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
1693 #else
1694 # define UV_IF_NAMESIZE (16 + 1)
1695 #endif
1696 
1697 UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
1698                                 char* buffer,
1699                                 size_t* size);
1700 UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
1701                                char* buffer,
1702                                size_t* size);
1703 
1704 UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1705 
1706 UV_EXTERN int uv_cwd(char* buffer, size_t* size);
1707 
1708 UV_EXTERN int uv_chdir(const char* dir);
1709 
1710 UV_EXTERN uint64_t uv_get_free_memory(void);
1711 UV_EXTERN uint64_t uv_get_total_memory(void);
1712 UV_EXTERN uint64_t uv_get_constrained_memory(void);
1713 
1714 UV_EXTERN uint64_t uv_hrtime(void);
1715 UV_EXTERN void uv_sleep(unsigned int msec);
1716 
1717 UV_EXTERN void uv_disable_stdio_inheritance(void);
1718 
1719 UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1720 UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1721 UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1722 UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
1723 
1724 UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1725 UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
1726 UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1727 UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1728 UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1729 UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1730 
1731 UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1732 UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1733 UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1734 UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1735 UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1736 UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1737 UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1738 UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1739 
1740 UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1741 UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1742 UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1743 UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1744 UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1745 
1746 UV_EXTERN int uv_cond_init(uv_cond_t* cond);
1747 UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
1748 UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
1749 UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
1750 
1751 UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
1752 UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
1753 UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
1754 
1755 UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
1756 UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
1757                                 uv_mutex_t* mutex,
1758                                 uint64_t timeout);
1759 
1760 UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1761 
1762 UV_EXTERN int uv_key_create(uv_key_t* key);
1763 UV_EXTERN void uv_key_delete(uv_key_t* key);
1764 UV_EXTERN void* uv_key_get(uv_key_t* key);
1765 UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
1766 
1767 UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
1768 
1769 typedef void (*uv_thread_cb)(void* arg);
1770 
1771 UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
1772 
1773 typedef enum {
1774   UV_THREAD_NO_FLAGS = 0x00,
1775   UV_THREAD_HAS_STACK_SIZE = 0x01
1776 } uv_thread_create_flags;
1777 
1778 struct uv_thread_options_s {
1779   unsigned int flags;
1780   size_t stack_size;
1781   /* More fields may be added at any time. */
1782 };
1783 
1784 typedef struct uv_thread_options_s uv_thread_options_t;
1785 
1786 UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
1787                                   const uv_thread_options_t* params,
1788                                   uv_thread_cb entry,
1789                                   void* arg);
1790 UV_EXTERN uv_thread_t uv_thread_self(void);
1791 UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1792 UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
1793 
1794 /* The presence of these unions force similar struct layout. */
1795 #define XX(_, name) uv_ ## name ## _t name;
1796 union uv_any_handle {
1797   UV_HANDLE_TYPE_MAP(XX)
1798 };
1799 
1800 union uv_any_req {
1801   UV_REQ_TYPE_MAP(XX)
1802 };
1803 #undef XX
1804 
1805 
1806 struct uv_loop_s {
1807   /* User data - use this for whatever. */
1808   void* data;
1809   /* Loop reference counting. */
1810   unsigned int active_handles;
1811   void* handle_queue[2];
1812   union {
1813     void* unused;
1814     unsigned int count;
1815   } active_reqs;
1816   /* Internal storage for future extensions. */
1817   void* internal_fields;
1818   /* Internal flag to signal loop stop. */
1819   unsigned int stop_flag;
1820   UV_LOOP_PRIVATE_FIELDS
1821 };
1822 
1823 UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
1824 UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
1825 
1826 /* Don't export the private CPP symbols. */
1827 #undef UV_HANDLE_TYPE_PRIVATE
1828 #undef UV_REQ_TYPE_PRIVATE
1829 #undef UV_REQ_PRIVATE_FIELDS
1830 #undef UV_STREAM_PRIVATE_FIELDS
1831 #undef UV_TCP_PRIVATE_FIELDS
1832 #undef UV_PREPARE_PRIVATE_FIELDS
1833 #undef UV_CHECK_PRIVATE_FIELDS
1834 #undef UV_IDLE_PRIVATE_FIELDS
1835 #undef UV_ASYNC_PRIVATE_FIELDS
1836 #undef UV_TIMER_PRIVATE_FIELDS
1837 #undef UV_GETADDRINFO_PRIVATE_FIELDS
1838 #undef UV_GETNAMEINFO_PRIVATE_FIELDS
1839 #undef UV_FS_REQ_PRIVATE_FIELDS
1840 #undef UV_WORK_PRIVATE_FIELDS
1841 #undef UV_FS_EVENT_PRIVATE_FIELDS
1842 #undef UV_SIGNAL_PRIVATE_FIELDS
1843 #undef UV_LOOP_PRIVATE_FIELDS
1844 #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
1845 #undef UV__ERR
1846 
1847 #ifdef __cplusplus
1848 }
1849 #endif
1850 #endif /* UV_H */
1851