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