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