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