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