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