1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
22 /* See https://github.com/libuv/libuv#documentation for documentation. */
27 /* Include KWSys Large File Support configuration. */
28 #include <cmsys/Configure.h>
34 #if defined(BUILDING_UV_SHARED) && defined(USING_UV_SHARED)
35 #error "Define either BUILDING_UV_SHARED or USING_UV_SHARED, not both."
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)
47 /* Building static library. */
48 # define UV_EXTERN /* nothing */
51 # define UV_EXTERN __attribute__((visibility("default")))
52 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) /* Sun Studio >= 8 */
53 # define UV_EXTERN __global
55 # define UV_EXTERN /* nothing */
59 #include "uv/version.h"
63 #if defined(_MSC_VER) && _MSC_VER < 1600
64 # include "uv/stdint-msvc2008.h"
75 /* Expand this list if necessary. */
76 #define UV_ERRNO_MAP(XX) \
77 XX(E2BIG, "argument list too long") \
78 XX(EACCES, "permission denied") \
79 XX(EADDRINUSE, "address already in use") \
80 XX(EADDRNOTAVAIL, "address not available") \
81 XX(EAFNOSUPPORT, "address family not supported") \
82 XX(EAGAIN, "resource temporarily unavailable") \
83 XX(EAI_ADDRFAMILY, "address family not supported") \
84 XX(EAI_AGAIN, "temporary failure") \
85 XX(EAI_BADFLAGS, "bad ai_flags value") \
86 XX(EAI_BADHINTS, "invalid value for hints") \
87 XX(EAI_CANCELED, "request canceled") \
88 XX(EAI_FAIL, "permanent failure") \
89 XX(EAI_FAMILY, "ai_family not supported") \
90 XX(EAI_MEMORY, "out of memory") \
91 XX(EAI_NODATA, "no address") \
92 XX(EAI_NONAME, "unknown node or service") \
93 XX(EAI_OVERFLOW, "argument buffer overflow") \
94 XX(EAI_PROTOCOL, "resolved protocol is unknown") \
95 XX(EAI_SERVICE, "service not available for socket type") \
96 XX(EAI_SOCKTYPE, "socket type not supported") \
97 XX(EALREADY, "connection already in progress") \
98 XX(EBADF, "bad file descriptor") \
99 XX(EBUSY, "resource busy or locked") \
100 XX(ECANCELED, "operation canceled") \
101 XX(ECHARSET, "invalid Unicode character") \
102 XX(ECONNABORTED, "software caused connection abort") \
103 XX(ECONNREFUSED, "connection refused") \
104 XX(ECONNRESET, "connection reset by peer") \
105 XX(EDESTADDRREQ, "destination address required") \
106 XX(EEXIST, "file already exists") \
107 XX(EFAULT, "bad address in system call argument") \
108 XX(EFBIG, "file too large") \
109 XX(EHOSTUNREACH, "host is unreachable") \
110 XX(EINTR, "interrupted system call") \
111 XX(EINVAL, "invalid argument") \
112 XX(EIO, "i/o error") \
113 XX(EISCONN, "socket is already connected") \
114 XX(EISDIR, "illegal operation on a directory") \
115 XX(ELOOP, "too many symbolic links encountered") \
116 XX(EMFILE, "too many open files") \
117 XX(EMSGSIZE, "message too long") \
118 XX(ENAMETOOLONG, "name too long") \
119 XX(ENETDOWN, "network is down") \
120 XX(ENETUNREACH, "network is unreachable") \
121 XX(ENFILE, "file table overflow") \
122 XX(ENOBUFS, "no buffer space available") \
123 XX(ENODEV, "no such device") \
124 XX(ENOENT, "no such file or directory") \
125 XX(ENOMEM, "not enough memory") \
126 XX(ENONET, "machine is not on the network") \
127 XX(ENOPROTOOPT, "protocol not available") \
128 XX(ENOSPC, "no space left on device") \
129 XX(ENOSYS, "function not implemented") \
130 XX(ENOTCONN, "socket is not connected") \
131 XX(ENOTDIR, "not a directory") \
132 XX(ENOTEMPTY, "directory not empty") \
133 XX(ENOTSOCK, "socket operation on non-socket") \
134 XX(ENOTSUP, "operation not supported on socket") \
135 XX(EOVERFLOW, "value too large for defined data type") \
136 XX(EPERM, "operation not permitted") \
137 XX(EPIPE, "broken pipe") \
138 XX(EPROTO, "protocol error") \
139 XX(EPROTONOSUPPORT, "protocol not supported") \
140 XX(EPROTOTYPE, "protocol wrong type for socket") \
141 XX(ERANGE, "result too large") \
142 XX(EROFS, "read-only file system") \
143 XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \
144 XX(ESPIPE, "invalid seek") \
145 XX(ESRCH, "no such process") \
146 XX(ETIMEDOUT, "connection timed out") \
147 XX(ETXTBSY, "text file is busy") \
148 XX(EXDEV, "cross-device link not permitted") \
149 XX(UNKNOWN, "unknown error") \
150 XX(EOF, "end of file") \
151 XX(ENXIO, "no such device or address") \
152 XX(EMLINK, "too many links") \
153 XX(EHOSTDOWN, "host is down") \
154 XX(EREMOTEIO, "remote I/O error") \
155 XX(ENOTTY, "inappropriate ioctl for device") \
156 XX(EFTYPE, "inappropriate file type or format") \
157 XX(EILSEQ, "illegal byte sequence") \
158 XX(ESOCKTNOSUPPORT, "socket type not supported") \
160 #define UV_HANDLE_TYPE_MAP(XX) \
163 XX(FS_EVENT, fs_event) \
164 XX(FS_POLL, fs_poll) \
167 XX(NAMED_PIPE, pipe) \
169 XX(PREPARE, prepare) \
170 XX(PROCESS, process) \
178 #define UV_REQ_TYPE_MAP(XX) \
180 XX(CONNECT, connect) \
182 XX(SHUTDOWN, shutdown) \
183 XX(UDP_SEND, udp_send) \
186 XX(GETADDRINFO, getaddrinfo) \
187 XX(GETNAMEINFO, getnameinfo) \
191 #define XX(code, _) UV_ ## code = UV__ ## code,
194 UV_ERRNO_MAX = UV__EOF - 1
198 UV_UNKNOWN_HANDLE = 0,
199 #define XX(uc, lc) UV_##uc,
200 UV_HANDLE_TYPE_MAP(XX)
208 #define XX(uc, lc) UV_##uc,
217 typedef struct uv_loop_s uv_loop_t;
218 typedef struct uv_handle_s uv_handle_t;
219 typedef struct uv_dir_s uv_dir_t;
220 typedef struct uv_stream_s uv_stream_t;
221 typedef struct uv_tcp_s uv_tcp_t;
222 typedef struct uv_udp_s uv_udp_t;
223 typedef struct uv_pipe_s uv_pipe_t;
224 typedef struct uv_tty_s uv_tty_t;
225 typedef struct uv_poll_s uv_poll_t;
226 typedef struct uv_timer_s uv_timer_t;
227 typedef struct uv_prepare_s uv_prepare_t;
228 typedef struct uv_check_s uv_check_t;
229 typedef struct uv_idle_s uv_idle_t;
230 typedef struct uv_async_s uv_async_t;
231 typedef struct uv_process_s uv_process_t;
232 typedef struct uv_fs_event_s uv_fs_event_t;
233 typedef struct uv_fs_poll_s uv_fs_poll_t;
234 typedef struct uv_signal_s uv_signal_t;
237 typedef struct uv_req_s uv_req_t;
238 typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
239 typedef struct uv_getnameinfo_s uv_getnameinfo_t;
240 typedef struct uv_shutdown_s uv_shutdown_t;
241 typedef struct uv_write_s uv_write_t;
242 typedef struct uv_connect_s uv_connect_t;
243 typedef struct uv_udp_send_s uv_udp_send_t;
244 typedef struct uv_fs_s uv_fs_t;
245 typedef struct uv_work_s uv_work_t;
246 typedef struct uv_random_s uv_random_t;
248 /* None of the above. */
249 typedef struct uv_env_item_s uv_env_item_t;
250 typedef struct uv_cpu_info_s uv_cpu_info_t;
251 typedef struct uv_interface_address_s uv_interface_address_t;
252 typedef struct uv_dirent_s uv_dirent_t;
253 typedef struct uv_passwd_s uv_passwd_t;
254 typedef struct uv_utsname_s uv_utsname_t;
255 typedef struct uv_statfs_s uv_statfs_t;
258 UV_LOOP_BLOCK_SIGNAL = 0,
269 UV_EXTERN unsigned int uv_version(void);
270 UV_EXTERN const char* uv_version_string(void);
272 typedef void* (*uv_malloc_func)(size_t size);
273 typedef void* (*uv_realloc_func)(void* ptr, size_t size);
274 typedef void* (*uv_calloc_func)(size_t count, size_t size);
275 typedef void (*uv_free_func)(void* ptr);
277 UV_EXTERN void uv_library_shutdown(void);
279 UV_EXTERN int uv_replace_allocator(uv_malloc_func malloc_func,
280 uv_realloc_func realloc_func,
281 uv_calloc_func calloc_func,
282 uv_free_func free_func);
284 UV_EXTERN uv_loop_t* uv_default_loop(void);
285 UV_EXTERN int uv_loop_init(uv_loop_t* loop);
286 UV_EXTERN int uv_loop_close(uv_loop_t* loop);
289 * This function is DEPRECATED (to be removed after 0.12), users should
290 * allocate the loop manually and use uv_loop_init instead.
292 UV_EXTERN uv_loop_t* uv_loop_new(void);
295 * This function is DEPRECATED (to be removed after 0.12). Users should use
296 * uv_loop_close and free the memory manually instead.
298 UV_EXTERN void uv_loop_delete(uv_loop_t*);
299 UV_EXTERN size_t uv_loop_size(void);
300 UV_EXTERN int uv_loop_alive(const uv_loop_t* loop);
301 UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...);
302 UV_EXTERN int uv_loop_fork(uv_loop_t* loop);
304 UV_EXTERN int uv_run(uv_loop_t*, uv_run_mode mode);
305 UV_EXTERN void uv_stop(uv_loop_t*);
307 UV_EXTERN void uv_ref(uv_handle_t*);
308 UV_EXTERN void uv_unref(uv_handle_t*);
309 UV_EXTERN int uv_has_ref(const uv_handle_t*);
311 UV_EXTERN void uv_update_time(uv_loop_t*);
312 UV_EXTERN uint64_t uv_now(const uv_loop_t*);
314 UV_EXTERN int uv_backend_fd(const uv_loop_t*);
315 UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
317 typedef void (*uv_alloc_cb)(uv_handle_t* handle,
318 size_t suggested_size,
320 typedef void (*uv_read_cb)(uv_stream_t* stream,
322 const uv_buf_t* buf);
323 typedef void (*uv_write_cb)(uv_write_t* req, int status);
324 typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
325 typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
326 typedef void (*uv_connection_cb)(uv_stream_t* server, int status);
327 typedef void (*uv_close_cb)(uv_handle_t* handle);
328 typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events);
329 typedef void (*uv_timer_cb)(uv_timer_t* handle);
330 typedef void (*uv_async_cb)(uv_async_t* handle);
331 typedef void (*uv_prepare_cb)(uv_prepare_t* handle);
332 typedef void (*uv_check_cb)(uv_check_t* handle);
333 typedef void (*uv_idle_cb)(uv_idle_t* handle);
334 typedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status, int term_signal);
335 typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
336 typedef void (*uv_fs_cb)(uv_fs_t* req);
337 typedef void (*uv_work_cb)(uv_work_t* req);
338 typedef void (*uv_after_work_cb)(uv_work_t* req, int status);
339 typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
341 struct addrinfo* res);
342 typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
344 const char* hostname,
345 const char* service);
346 typedef void (*uv_random_cb)(uv_random_t* req,
370 uv_timespec_t st_atim;
371 uv_timespec_t st_mtim;
372 uv_timespec_t st_ctim;
373 uv_timespec_t st_birthtim;
377 typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle,
378 const char* filename,
382 typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
384 const uv_stat_t* prev,
385 const uv_stat_t* curr);
387 typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum);
396 UV_EXTERN int uv_translate_sys_error(int sys_errno);
398 UV_EXTERN const char* uv_strerror(int err);
399 UV_EXTERN char* uv_strerror_r(int err, char* buf, size_t buflen);
401 UV_EXTERN const char* uv_err_name(int err);
402 UV_EXTERN char* uv_err_name_r(int err, char* buf, size_t buflen);
405 #define UV_REQ_FIELDS \
412 UV_REQ_PRIVATE_FIELDS \
414 /* Abstract base class of all requests. */
420 /* Platform-specific request types. */
424 UV_EXTERN int uv_shutdown(uv_shutdown_t* req,
428 struct uv_shutdown_s {
432 UV_SHUTDOWN_PRIVATE_FIELDS
436 #define UV_HANDLE_FIELDS \
441 uv_handle_type type; \
443 uv_close_cb close_cb; \
444 void* handle_queue[2]; \
449 UV_HANDLE_PRIVATE_FIELDS \
451 /* The abstract base class of all handles. */
456 UV_EXTERN size_t uv_handle_size(uv_handle_type type);
457 UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle);
458 UV_EXTERN const char* uv_handle_type_name(uv_handle_type type);
459 UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle);
460 UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle);
461 UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data);
463 UV_EXTERN size_t uv_req_size(uv_req_type type);
464 UV_EXTERN void* uv_req_get_data(const uv_req_t* req);
465 UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data);
466 UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req);
467 UV_EXTERN const char* uv_req_type_name(uv_req_type type);
469 UV_EXTERN int uv_is_active(const uv_handle_t* handle);
471 UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
473 /* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */
474 UV_EXTERN void uv_print_all_handles(uv_loop_t* loop, FILE* stream);
475 UV_EXTERN void uv_print_active_handles(uv_loop_t* loop, FILE* stream);
477 UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
479 UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value);
480 UV_EXTERN int uv_recv_buffer_size(uv_handle_t* handle, int* value);
482 UV_EXTERN int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd);
484 UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
486 UV_EXTERN int uv_pipe(uv_file fds[2], int read_flags, int write_flags);
487 UV_EXTERN int uv_socketpair(int type,
489 uv_os_sock_t socket_vector[2],
493 #define UV_STREAM_FIELDS \
494 /* number of bytes queued for writing */ \
495 size_t write_queue_size; \
496 uv_alloc_cb alloc_cb; \
497 uv_read_cb read_cb; \
499 UV_STREAM_PRIVATE_FIELDS
502 * uv_stream_t is a subclass of uv_handle_t.
504 * uv_stream is an abstract class.
506 * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t.
513 UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);
515 UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
516 UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
518 UV_EXTERN int uv_read_start(uv_stream_t*,
519 uv_alloc_cb alloc_cb,
521 UV_EXTERN int uv_read_stop(uv_stream_t*);
523 UV_EXTERN int uv_write(uv_write_t* req,
525 const uv_buf_t bufs[],
528 UV_EXTERN int uv_write2(uv_write_t* req,
530 const uv_buf_t bufs[],
532 uv_stream_t* send_handle,
534 UV_EXTERN int uv_try_write(uv_stream_t* handle,
535 const uv_buf_t bufs[],
537 UV_EXTERN int uv_try_write2(uv_stream_t* handle,
538 const uv_buf_t bufs[],
540 uv_stream_t* send_handle);
542 /* uv_write_t is a subclass of uv_req_t. */
546 uv_stream_t* send_handle; /* TODO: make private and unix-only in v2.x. */
548 UV_WRITE_PRIVATE_FIELDS
552 UV_EXTERN int uv_is_readable(const uv_stream_t* handle);
553 UV_EXTERN int uv_is_writable(const uv_stream_t* handle);
555 UV_EXTERN int uv_stream_set_blocking(uv_stream_t* handle, int blocking);
557 UV_EXTERN int uv_is_closing(const uv_handle_t* handle);
561 * uv_tcp_t is a subclass of uv_stream_t.
563 * Represents a TCP stream or TCP server.
568 UV_TCP_PRIVATE_FIELDS
571 UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
572 UV_EXTERN int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags);
573 UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
574 UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
575 UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
578 UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
581 /* Used with uv_tcp_bind, when an IPv6 address is used. */
585 UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
586 const struct sockaddr* addr,
588 UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle,
589 struct sockaddr* name,
591 UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle,
592 struct sockaddr* name,
594 UV_EXTERN int uv_tcp_close_reset(uv_tcp_t* handle, uv_close_cb close_cb);
595 UV_EXTERN int uv_tcp_connect(uv_connect_t* req,
597 const struct sockaddr* addr,
600 /* uv_connect_t is a subclass of uv_req_t. */
601 struct uv_connect_s {
605 UV_CONNECT_PRIVATE_FIELDS
614 /* Disables dual stack mode. */
617 * Indicates message was truncated because read buffer was too small. The
618 * remainder was discarded by the OS. Used in uv_udp_recv_cb.
622 * Indicates if SO_REUSEADDR will be set when binding the handle.
623 * This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
624 * Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
625 * multiple threads or processes can bind to the same address without error
626 * (provided they all set the flag) but only the last one to bind will receive
627 * any traffic, in effect "stealing" the port from the previous listener.
629 UV_UDP_REUSEADDR = 4,
631 * Indicates that the message was received by recvmmsg, so the buffer provided
632 * must not be freed by the recv_cb callback.
634 UV_UDP_MMSG_CHUNK = 8,
636 * Indicates that the buffer provided has been fully utilized by recvmmsg and
637 * that it should now be freed by the recv_cb callback. When this flag is set
638 * in uv_udp_recv_cb, nread will always be 0 and addr will always be NULL.
640 UV_UDP_MMSG_FREE = 16,
642 * Indicates if IP_RECVERR/IPV6_RECVERR will be set when binding the handle.
643 * This sets IP_RECVERR for IPv4 and IPV6_RECVERR for IPv6 UDP sockets on
644 * Linux. This stops the Linux kernel from suppressing some ICMP error
645 * messages and enables full ICMP error reporting for faster failover.
646 * This flag is no-op on platforms other than Linux.
648 UV_UDP_LINUX_RECVERR = 32,
650 * Indicates that recvmmsg should be used, if available.
652 UV_UDP_RECVMMSG = 256
655 typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
656 typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
659 const struct sockaddr* addr,
662 /* uv_udp_t is a subclass of uv_handle_t. */
667 * Number of bytes queued for sending. This field strictly shows how much
668 * information is currently queued.
670 size_t send_queue_size;
672 * Number of send requests currently in the queue awaiting to be processed.
674 size_t send_queue_count;
675 UV_UDP_PRIVATE_FIELDS
678 /* uv_udp_send_t is a subclass of uv_req_t. */
679 struct uv_udp_send_s {
683 UV_UDP_SEND_PRIVATE_FIELDS
686 UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
687 UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
688 UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
689 UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
690 const struct sockaddr* addr,
692 UV_EXTERN int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr);
694 UV_EXTERN int uv_udp_getpeername(const uv_udp_t* handle,
695 struct sockaddr* name,
697 UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
698 struct sockaddr* name,
700 UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
701 const char* multicast_addr,
702 const char* interface_addr,
703 uv_membership membership);
704 UV_EXTERN int uv_udp_set_source_membership(uv_udp_t* handle,
705 const char* multicast_addr,
706 const char* interface_addr,
707 const char* source_addr,
708 uv_membership membership);
709 UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
710 UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
711 UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle,
712 const char* interface_addr);
713 UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
714 UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
715 UV_EXTERN int uv_udp_send(uv_udp_send_t* req,
717 const uv_buf_t bufs[],
719 const struct sockaddr* addr,
720 uv_udp_send_cb send_cb);
721 UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
722 const uv_buf_t bufs[],
724 const struct sockaddr* addr);
725 UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
726 uv_alloc_cb alloc_cb,
727 uv_udp_recv_cb recv_cb);
728 UV_EXTERN int uv_udp_using_recvmmsg(const uv_udp_t* handle);
729 UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
730 UV_EXTERN size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
731 UV_EXTERN size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);
735 * uv_tty_t is a subclass of uv_stream_t.
737 * Representing a stream for the console.
742 UV_TTY_PRIVATE_FIELDS
746 /* Initial/normal terminal mode */
748 /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
750 /* Binary-safe I/O mode for IPC (Unix-only) */
756 * The console supports handling of virtual terminal sequences
757 * (Windows10 new console, ConEmu)
760 /* The console cannot process the virtual terminal sequence. (Legacy
764 } uv_tty_vtermstate_t;
767 UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
768 UV_EXTERN int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode);
769 UV_EXTERN int uv_tty_reset_mode(void);
770 UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);
771 UV_EXTERN void uv_tty_set_vterm_state(uv_tty_vtermstate_t state);
772 UV_EXTERN int uv_tty_get_vterm_state(uv_tty_vtermstate_t* state);
777 inline int uv_tty_set_mode(uv_tty_t* handle, int mode) {
778 return uv_tty_set_mode(handle, static_cast<uv_tty_mode_t>(mode));
784 UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
787 * uv_pipe_t is a subclass of uv_stream_t.
789 * Representing a pipe stream or pipe server. On Windows this is a Named
790 * Pipe. On Unix this is a Unix domain socket.
795 int ipc; /* non-zero if this pipe is used for passing handles */
796 UV_PIPE_PRIVATE_FIELDS
799 UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
800 UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
801 UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
802 UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
806 UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
809 UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
812 UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
813 UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle);
814 UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
815 UV_EXTERN int uv_pipe_chmod(uv_pipe_t* handle, int flags);
821 UV_POLL_PRIVATE_FIELDS
831 UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
832 UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop,
834 uv_os_sock_t socket);
835 UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb);
836 UV_EXTERN int uv_poll_stop(uv_poll_t* handle);
839 struct uv_prepare_s {
841 UV_PREPARE_PRIVATE_FIELDS
844 UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
845 UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
846 UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare);
851 UV_CHECK_PRIVATE_FIELDS
854 UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check);
855 UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb);
856 UV_EXTERN int uv_check_stop(uv_check_t* check);
861 UV_IDLE_PRIVATE_FIELDS
864 UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle);
865 UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);
866 UV_EXTERN int uv_idle_stop(uv_idle_t* idle);
871 UV_ASYNC_PRIVATE_FIELDS
874 UV_EXTERN int uv_async_init(uv_loop_t*,
876 uv_async_cb async_cb);
877 UV_EXTERN int uv_async_send(uv_async_t* async);
881 * uv_timer_t is a subclass of uv_handle_t.
883 * Used to get woken up at a specified time in the future.
887 UV_TIMER_PRIVATE_FIELDS
890 UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
891 UV_EXTERN int uv_timer_start(uv_timer_t* handle,
895 UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
896 UV_EXTERN int uv_timer_again(uv_timer_t* handle);
897 UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
898 UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
899 UV_EXTERN uint64_t uv_timer_get_due_in(const uv_timer_t* handle);
903 * uv_getaddrinfo_t is a subclass of uv_req_t.
905 * Request object for uv_getaddrinfo.
907 struct uv_getaddrinfo_s {
911 /* struct addrinfo* addrinfo is marked as private, but it really isn't. */
912 UV_GETADDRINFO_PRIVATE_FIELDS
916 UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop,
917 uv_getaddrinfo_t* req,
918 uv_getaddrinfo_cb getaddrinfo_cb,
921 const struct addrinfo* hints);
922 UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
926 * uv_getnameinfo_t is a subclass of uv_req_t.
928 * Request object for uv_getnameinfo.
930 struct uv_getnameinfo_s {
934 /* host and service are marked as private, but they really aren't. */
935 UV_GETNAMEINFO_PRIVATE_FIELDS
938 UV_EXTERN int uv_getnameinfo(uv_loop_t* loop,
939 uv_getnameinfo_t* req,
940 uv_getnameinfo_cb getnameinfo_cb,
941 const struct sockaddr* addr,
945 /* uv_spawn() options. */
948 UV_CREATE_PIPE = 0x01,
949 UV_INHERIT_FD = 0x02,
950 UV_INHERIT_STREAM = 0x04,
953 * When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
954 * determine the direction of flow, from the child process' perspective. Both
955 * flags may be specified to create a duplex data stream.
957 UV_READABLE_PIPE = 0x10,
958 UV_WRITABLE_PIPE = 0x20,
961 * When UV_CREATE_PIPE is specified, specifying UV_NONBLOCK_PIPE opens the
962 * handle in non-blocking mode in the child. This may cause loss of data,
963 * if the child is not designed to handle to encounter this mode,
964 * but can also be significantly more efficient.
966 UV_NONBLOCK_PIPE = 0x40,
967 UV_OVERLAPPED_PIPE = 0x40 /* old name, for compatibility */
970 typedef struct uv_stdio_container_s {
971 uv_stdio_flags flags;
977 } uv_stdio_container_t;
979 typedef struct uv_process_options_s {
980 uv_exit_cb exit_cb; /* Called after the process exits. */
981 const char* file; /* Path to program to execute. */
983 * Command line arguments. args[0] should be the path to the program. On
984 * Windows this uses CreateProcess which concatenates the arguments into a
985 * string this can cause some strange errors. See the note at
986 * windows_verbatim_arguments.
990 * This will be set as the environ variable in the subprocess. If this is
991 * NULL then the parents environ will be used.
995 * If non-null this represents a directory the subprocess should execute
996 * in. Stands for current working directory.
1000 * Various flags that control how uv_spawn() behaves. See the definition of
1001 * `enum uv_process_flags` below.
1005 * The `stdio` field points to an array of uv_stdio_container_t structs that
1006 * describe the file descriptors that will be made available to the child
1007 * process. The convention is that stdio[0] points to stdin, fd 1 is used for
1008 * stdout, and fd 2 is stderr.
1010 * Note that on windows file descriptors greater than 2 are available to the
1011 * child process only if the child processes uses the MSVCRT runtime.
1014 uv_stdio_container_t* stdio;
1016 * Libuv can change the child process' user/group id. This happens only when
1017 * the appropriate bits are set in the flags fields. This is not supported on
1018 * windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
1023 Libuv can set the child process' CPU affinity mask. This happens when
1024 `cpumask` is non-NULL. It must point to an array of char values
1025 of length `cpumask_size`, whose value must be at least that returned by
1026 uv_cpumask_size(). Each byte in the mask can be either zero (false)
1027 or non-zero (true) to indicate whether the corresponding processor at
1028 that index is included.
1030 If enabled on an unsupported platform, uv_spawn() will fail with
1034 size_t cpumask_size;
1035 } uv_process_options_t;
1038 * These are the flags that can be used for the uv_process_options.flags field.
1040 enum uv_process_flags {
1042 * Set the child process' user id. The user id is supplied in the `uid` field
1043 * of the options struct. This does not work on windows; setting this flag
1044 * will cause uv_spawn() to fail.
1046 UV_PROCESS_SETUID = (1 << 0),
1048 * Set the child process' group id. The user id is supplied in the `gid`
1049 * field of the options struct. This does not work on windows; setting this
1050 * flag will cause uv_spawn() to fail.
1052 UV_PROCESS_SETGID = (1 << 1),
1054 * Do not wrap any arguments in quotes, or perform any other escaping, when
1055 * converting the argument list into a command line string. This option is
1056 * only meaningful on Windows systems. On Unix it is silently ignored.
1058 UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
1060 * Spawn the child process in a detached state - this will make it a process
1061 * group leader, and will effectively enable the child to keep running after
1062 * the parent exits. Note that the child process will still keep the
1063 * parent's event loop alive unless the parent process calls uv_unref() on
1064 * the child's process handle.
1066 UV_PROCESS_DETACHED = (1 << 3),
1068 * Hide the subprocess window that would normally be created. This option is
1069 * only meaningful on Windows systems. On Unix it is silently ignored.
1071 UV_PROCESS_WINDOWS_HIDE = (1 << 4),
1073 * Hide the subprocess console window that would normally be created. This
1074 * option is only meaningful on Windows systems. On Unix it is silently
1077 UV_PROCESS_WINDOWS_HIDE_CONSOLE = (1 << 5),
1079 * Hide the subprocess GUI window that would normally be created. This
1080 * option is only meaningful on Windows systems. On Unix it is silently
1083 UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
1087 * uv_process_t is a subclass of uv_handle_t.
1089 struct uv_process_s {
1093 UV_PROCESS_PRIVATE_FIELDS
1096 UV_EXTERN int uv_spawn(uv_loop_t* loop,
1097 uv_process_t* handle,
1098 const uv_process_options_t* options);
1099 UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
1100 UV_EXTERN int uv_kill(int pid, int signum);
1101 UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
1105 * uv_work_t is a subclass of uv_req_t.
1111 uv_after_work_cb after_work_cb;
1112 UV_WORK_PRIVATE_FIELDS
1115 UV_EXTERN int uv_queue_work(uv_loop_t* loop,
1118 uv_after_work_cb after_work_cb);
1120 UV_EXTERN int uv_cancel(uv_req_t* req);
1123 struct uv_cpu_times_s {
1124 uint64_t user; /* milliseconds */
1125 uint64_t nice; /* milliseconds */
1126 uint64_t sys; /* milliseconds */
1127 uint64_t idle; /* milliseconds */
1128 uint64_t irq; /* milliseconds */
1131 struct uv_cpu_info_s {
1134 struct uv_cpu_times_s cpu_times;
1137 struct uv_interface_address_s {
1142 struct sockaddr_in address4;
1143 struct sockaddr_in6 address6;
1146 struct sockaddr_in netmask4;
1147 struct sockaddr_in6 netmask6;
1151 struct uv_passwd_s {
1159 struct uv_utsname_s {
1164 /* This struct does not contain the nodename and domainname fields present in
1165 the utsname type. domainname is a GNU extension. Both fields are referred
1166 to as meaningless in the docs. */
1169 struct uv_statfs_s {
1177 uint64_t f_spare[4];
1191 struct uv_dirent_s {
1193 uv_dirent_type_t type;
1196 UV_EXTERN char** uv_setup_args(int argc, char** argv);
1197 UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
1198 UV_EXTERN int uv_set_process_title(const char* title);
1199 UV_EXTERN int uv_resident_set_memory(size_t* rss);
1200 UV_EXTERN int uv_uptime(double* uptime);
1201 UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
1202 UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
1215 uv_timeval_t ru_utime; /* user CPU time used */
1216 uv_timeval_t ru_stime; /* system CPU time used */
1217 uint64_t ru_maxrss; /* maximum resident set size */
1218 uint64_t ru_ixrss; /* integral shared memory size */
1219 uint64_t ru_idrss; /* integral unshared data size */
1220 uint64_t ru_isrss; /* integral unshared stack size */
1221 uint64_t ru_minflt; /* page reclaims (soft page faults) */
1222 uint64_t ru_majflt; /* page faults (hard page faults) */
1223 uint64_t ru_nswap; /* swaps */
1224 uint64_t ru_inblock; /* block input operations */
1225 uint64_t ru_oublock; /* block output operations */
1226 uint64_t ru_msgsnd; /* IPC messages sent */
1227 uint64_t ru_msgrcv; /* IPC messages received */
1228 uint64_t ru_nsignals; /* signals received */
1229 uint64_t ru_nvcsw; /* voluntary context switches */
1230 uint64_t ru_nivcsw; /* involuntary context switches */
1233 UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
1235 UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
1236 UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
1237 UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
1238 UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
1239 UV_EXTERN uv_pid_t uv_os_getpid(void);
1240 UV_EXTERN uv_pid_t uv_os_getppid(void);
1242 #if defined(__PASE__)
1243 /* On IBM i PASE, the highest process priority is -10 */
1244 # define UV_PRIORITY_LOW 39 /* RUNPTY(99) */
1245 # define UV_PRIORITY_BELOW_NORMAL 15 /* RUNPTY(50) */
1246 # define UV_PRIORITY_NORMAL 0 /* RUNPTY(20) */
1247 # define UV_PRIORITY_ABOVE_NORMAL -4 /* RUNTY(12) */
1248 # define UV_PRIORITY_HIGH -7 /* RUNPTY(6) */
1249 # define UV_PRIORITY_HIGHEST -10 /* RUNPTY(1) */
1251 # define UV_PRIORITY_LOW 19
1252 # define UV_PRIORITY_BELOW_NORMAL 10
1253 # define UV_PRIORITY_NORMAL 0
1254 # define UV_PRIORITY_ABOVE_NORMAL -7
1255 # define UV_PRIORITY_HIGH -14
1256 # define UV_PRIORITY_HIGHEST -20
1259 UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
1260 UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
1262 UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1263 UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1264 UV_EXTERN int uv_cpumask_size(void);
1266 UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
1268 UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1271 struct uv_env_item_s {
1276 UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
1277 UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
1278 UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
1279 UV_EXTERN int uv_os_setenv(const char* name, const char* value);
1280 UV_EXTERN int uv_os_unsetenv(const char* name);
1282 #ifdef MAXHOSTNAMELEN
1283 # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
1286 Fallback for the maximum hostname size, including the null terminator. The
1287 Windows gethostname() documentation states that 256 bytes will always be
1288 large enough to hold the null-terminated hostname.
1290 # define UV_MAXHOSTNAMESIZE 256
1293 UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
1295 UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
1297 UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
1341 uv_dirent_t* dirents;
1344 UV_DIR_PRIVATE_FIELDS
1347 /* uv_fs_t is a subclass of uv_req_t. */
1356 uv_stat_t statbuf; /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
1357 UV_FS_PRIVATE_FIELDS
1360 UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
1361 UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
1362 UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
1363 UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
1364 UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
1365 UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
1367 UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1368 UV_EXTERN int uv_fs_close(uv_loop_t* loop,
1372 UV_EXTERN int uv_fs_open(uv_loop_t* loop,
1378 UV_EXTERN int uv_fs_read(uv_loop_t* loop,
1381 const uv_buf_t bufs[],
1385 UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
1389 UV_EXTERN int uv_fs_write(uv_loop_t* loop,
1392 const uv_buf_t bufs[],
1397 * This flag can be used with uv_fs_copyfile() to return an error if the
1398 * destination already exists.
1400 #define UV_FS_COPYFILE_EXCL 0x0001
1403 * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1404 * If copy-on-write is not supported, a fallback copy mechanism is used.
1406 #define UV_FS_COPYFILE_FICLONE 0x0002
1409 * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1410 * If copy-on-write is not supported, an error is returned.
1412 #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
1414 UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
1417 const char* new_path,
1420 UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
1425 UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
1429 UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
1433 UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
1437 UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
1442 UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
1444 UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
1448 UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
1452 UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
1456 UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
1460 UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
1464 UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
1467 const char* new_path,
1469 UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
1473 UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
1477 UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
1482 UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
1489 UV_EXTERN int uv_fs_access(uv_loop_t* loop,
1494 UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
1499 UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
1505 UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
1511 UV_EXTERN int uv_fs_lutime(uv_loop_t* loop,
1517 UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
1521 UV_EXTERN int uv_fs_link(uv_loop_t* loop,
1524 const char* new_path,
1528 * This flag can be used with uv_fs_symlink() on Windows to specify whether
1529 * path argument points to a directory.
1531 #define UV_FS_SYMLINK_DIR 0x0001
1534 * This flag can be used with uv_fs_symlink() on Windows to specify whether
1535 * the symlink is to be created using junction points.
1537 #define UV_FS_SYMLINK_JUNCTION 0x0002
1539 UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
1542 const char* new_path,
1545 UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
1549 UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
1553 UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
1558 UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
1564 UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
1570 UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
1576 UV_EXTERN int uv_fs_statfs(uv_loop_t* loop,
1588 struct uv_fs_event_s {
1592 UV_FS_EVENT_PRIVATE_FIELDS
1597 * uv_fs_stat() based polling file watcher.
1599 struct uv_fs_poll_s {
1601 /* Private, don't touch. */
1605 UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1606 UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1607 uv_fs_poll_cb poll_cb,
1609 unsigned int interval);
1610 UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1611 UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
1616 struct uv_signal_s {
1618 uv_signal_cb signal_cb;
1620 UV_SIGNAL_PRIVATE_FIELDS
1623 UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
1624 UV_EXTERN int uv_signal_start(uv_signal_t* handle,
1625 uv_signal_cb signal_cb,
1627 UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
1628 uv_signal_cb signal_cb,
1630 UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
1632 UV_EXTERN void uv_loadavg(double avg[3]);
1636 * Flags to be passed to uv_fs_event_start().
1638 enum uv_fs_event_flags {
1640 * By default, if the fs event watcher is given a directory name, we will
1641 * watch for all events in that directory. This flags overrides this behavior
1642 * and makes fs_event report only changes to the directory entry itself. This
1643 * flag does not affect individual files watched.
1644 * This flag is currently not implemented yet on any backend.
1646 UV_FS_EVENT_WATCH_ENTRY = 1,
1649 * By default uv_fs_event will try to use a kernel interface such as inotify
1650 * or kqueue to detect events. This may not work on remote filesystems such
1651 * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1653 * This flag is currently not implemented yet on any backend.
1655 UV_FS_EVENT_STAT = 2,
1658 * By default, event watcher, when watching directory, is not registering
1659 * (is ignoring) changes in it's subdirectories.
1660 * This flag will override this behaviour on platforms that support it.
1662 UV_FS_EVENT_RECURSIVE = 4
1666 UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
1667 UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
1670 unsigned int flags);
1671 UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
1672 UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
1676 UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
1677 UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
1679 UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
1680 UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
1681 UV_EXTERN int uv_ip_name(const struct sockaddr* src, char* dst, size_t size);
1683 UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
1684 UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
1687 struct uv_random_s {
1696 struct uv__work work_req;
1699 UV_EXTERN int uv_random(uv_loop_t* loop,
1703 unsigned flags, /* For future extension; must be 0. */
1706 #if defined(IF_NAMESIZE)
1707 # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
1708 #elif defined(IFNAMSIZ)
1709 # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
1711 # define UV_IF_NAMESIZE (16 + 1)
1714 UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
1717 UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
1721 UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1723 UV_EXTERN int uv_cwd(char* buffer, size_t* size);
1725 UV_EXTERN int uv_chdir(const char* dir);
1727 UV_EXTERN uint64_t uv_get_free_memory(void);
1728 UV_EXTERN uint64_t uv_get_total_memory(void);
1729 UV_EXTERN uint64_t uv_get_constrained_memory(void);
1731 UV_EXTERN uint64_t uv_hrtime(void);
1732 UV_EXTERN void uv_sleep(unsigned int msec);
1734 UV_EXTERN void uv_disable_stdio_inheritance(void);
1736 UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1737 UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1738 UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1739 UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
1741 UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1742 UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
1743 UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1744 UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1745 UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1746 UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1748 UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1749 UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1750 UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1751 UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1752 UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1753 UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1754 UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1755 UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1757 UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1758 UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1759 UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1760 UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1761 UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1763 UV_EXTERN int uv_cond_init(uv_cond_t* cond);
1764 UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
1765 UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
1766 UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
1768 UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
1769 UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
1770 UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
1772 UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
1773 UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
1777 UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1779 UV_EXTERN int uv_key_create(uv_key_t* key);
1780 UV_EXTERN void uv_key_delete(uv_key_t* key);
1781 UV_EXTERN void* uv_key_get(uv_key_t* key);
1782 UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
1784 UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
1786 typedef void (*uv_thread_cb)(void* arg);
1788 UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
1791 UV_THREAD_NO_FLAGS = 0x00,
1792 UV_THREAD_HAS_STACK_SIZE = 0x01
1793 } uv_thread_create_flags;
1795 struct uv_thread_options_s {
1798 /* More fields may be added at any time. */
1801 typedef struct uv_thread_options_s uv_thread_options_t;
1803 UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
1804 const uv_thread_options_t* params,
1807 UV_EXTERN uv_thread_t uv_thread_self(void);
1808 UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1809 UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
1811 /* The presence of these unions force similar struct layout. */
1812 #define XX(_, name) uv_ ## name ## _t name;
1813 union uv_any_handle {
1814 UV_HANDLE_TYPE_MAP(XX)
1824 /* User data - use this for whatever. */
1826 /* Loop reference counting. */
1827 unsigned int active_handles;
1828 void* handle_queue[2];
1833 /* Internal storage for future extensions. */
1834 void* internal_fields;
1835 /* Internal flag to signal loop stop. */
1836 unsigned int stop_flag;
1837 UV_LOOP_PRIVATE_FIELDS
1840 UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
1841 UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
1843 /* Don't export the private CPP symbols. */
1844 #undef UV_HANDLE_TYPE_PRIVATE
1845 #undef UV_REQ_TYPE_PRIVATE
1846 #undef UV_REQ_PRIVATE_FIELDS
1847 #undef UV_STREAM_PRIVATE_FIELDS
1848 #undef UV_TCP_PRIVATE_FIELDS
1849 #undef UV_PREPARE_PRIVATE_FIELDS
1850 #undef UV_CHECK_PRIVATE_FIELDS
1851 #undef UV_IDLE_PRIVATE_FIELDS
1852 #undef UV_ASYNC_PRIVATE_FIELDS
1853 #undef UV_TIMER_PRIVATE_FIELDS
1854 #undef UV_GETADDRINFO_PRIVATE_FIELDS
1855 #undef UV_GETNAMEINFO_PRIVATE_FIELDS
1856 #undef UV_FS_REQ_PRIVATE_FIELDS
1857 #undef UV_WORK_PRIVATE_FIELDS
1858 #undef UV_FS_EVENT_PRIVATE_FIELDS
1859 #undef UV_SIGNAL_PRIVATE_FIELDS
1860 #undef UV_LOOP_PRIVATE_FIELDS
1861 #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS