Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:05:23

0001 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
0002  *
0003  * Permission is hereby granted, free of charge, to any person obtaining a copy
0004  * of this software and associated documentation files (the "Software"), to
0005  * deal in the Software without restriction, including without limitation the
0006  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
0007  * sell copies of the Software, and to permit persons to whom the Software is
0008  * furnished to do so, subject to the following conditions:
0009  *
0010  * The above copyright notice and this permission notice shall be included in
0011  * all copies or substantial portions of the Software.
0012  *
0013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0018  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0019  * IN THE SOFTWARE.
0020  */
0021 
0022 /* See https://github.com/libuv/libuv#documentation for documentation. */
0023 
0024 #ifndef UV_H
0025 #define UV_H
0026 #ifdef __cplusplus
0027 extern "C" {
0028 #endif
0029 
0030 #if defined(BUILDING_UV_SHARED) && defined(USING_UV_SHARED)
0031 #error "Define either BUILDING_UV_SHARED or USING_UV_SHARED, not both."
0032 #endif
0033 
0034 #ifndef UV_EXTERN
0035 #ifdef _WIN32
0036   /* Windows - set up dll import/export decorators. */
0037 # if defined(BUILDING_UV_SHARED)
0038     /* Building shared library. */
0039 #   define UV_EXTERN __declspec(dllexport)
0040 # elif defined(USING_UV_SHARED)
0041     /* Using shared library. */
0042 #   define UV_EXTERN __declspec(dllimport)
0043 # else
0044     /* Building static library. */
0045 #   define UV_EXTERN /* nothing */
0046 # endif
0047 #elif __GNUC__ >= 4
0048 # define UV_EXTERN __attribute__((visibility("default")))
0049 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550) /* Sun Studio >= 8 */
0050 # define UV_EXTERN __global
0051 #else
0052 # define UV_EXTERN /* nothing */
0053 #endif
0054 #endif /* UV_EXTERN */
0055 
0056 #include "uv/errno.h"
0057 #include "uv/version.h"
0058 #include <stddef.h>
0059 #include <stdio.h>
0060 #include <stdint.h>
0061 
0062 /* Internal type, do not use. */
0063 struct uv__queue {
0064   struct uv__queue* next;
0065   struct uv__queue* prev;
0066 };
0067 
0068 #if defined(_WIN32)
0069 # include "uv/win.h"
0070 #else
0071 # include "uv/unix.h"
0072 #endif
0073 
0074 /* Expand this list if necessary. */
0075 #define UV_ERRNO_MAP(XX)                                                      \
0076   XX(E2BIG, "argument list too long")                                         \
0077   XX(EACCES, "permission denied")                                             \
0078   XX(EADDRINUSE, "address already in use")                                    \
0079   XX(EADDRNOTAVAIL, "address not available")                                  \
0080   XX(EAFNOSUPPORT, "address family not supported")                            \
0081   XX(EAGAIN, "resource temporarily unavailable")                              \
0082   XX(EAI_ADDRFAMILY, "address family not supported")                          \
0083   XX(EAI_AGAIN, "temporary failure")                                          \
0084   XX(EAI_BADFLAGS, "bad ai_flags value")                                      \
0085   XX(EAI_BADHINTS, "invalid value for hints")                                 \
0086   XX(EAI_CANCELED, "request canceled")                                        \
0087   XX(EAI_FAIL, "permanent failure")                                           \
0088   XX(EAI_FAMILY, "ai_family not supported")                                   \
0089   XX(EAI_MEMORY, "out of memory")                                             \
0090   XX(EAI_NODATA, "no address")                                                \
0091   XX(EAI_NONAME, "unknown node or service")                                   \
0092   XX(EAI_OVERFLOW, "argument buffer overflow")                                \
0093   XX(EAI_PROTOCOL, "resolved protocol is unknown")                            \
0094   XX(EAI_SERVICE, "service not available for socket type")                    \
0095   XX(EAI_SOCKTYPE, "socket type not supported")                               \
0096   XX(EALREADY, "connection already in progress")                              \
0097   XX(EBADF, "bad file descriptor")                                            \
0098   XX(EBUSY, "resource busy or locked")                                        \
0099   XX(ECANCELED, "operation canceled")                                         \
0100   XX(ECHARSET, "invalid Unicode character")                                   \
0101   XX(ECONNABORTED, "software caused connection abort")                        \
0102   XX(ECONNREFUSED, "connection refused")                                      \
0103   XX(ECONNRESET, "connection reset by peer")                                  \
0104   XX(EDESTADDRREQ, "destination address required")                            \
0105   XX(EEXIST, "file already exists")                                           \
0106   XX(EFAULT, "bad address in system call argument")                           \
0107   XX(EFBIG, "file too large")                                                 \
0108   XX(EHOSTUNREACH, "host is unreachable")                                     \
0109   XX(EINTR, "interrupted system call")                                        \
0110   XX(EINVAL, "invalid argument")                                              \
0111   XX(EIO, "i/o error")                                                        \
0112   XX(EISCONN, "socket is already connected")                                  \
0113   XX(EISDIR, "illegal operation on a directory")                              \
0114   XX(ELOOP, "too many symbolic links encountered")                            \
0115   XX(EMFILE, "too many open files")                                           \
0116   XX(EMSGSIZE, "message too long")                                            \
0117   XX(ENAMETOOLONG, "name too long")                                           \
0118   XX(ENETDOWN, "network is down")                                             \
0119   XX(ENETUNREACH, "network is unreachable")                                   \
0120   XX(ENFILE, "file table overflow")                                           \
0121   XX(ENOBUFS, "no buffer space available")                                    \
0122   XX(ENODEV, "no such device")                                                \
0123   XX(ENOENT, "no such file or directory")                                     \
0124   XX(ENOMEM, "not enough memory")                                             \
0125   XX(ENONET, "machine is not on the network")                                 \
0126   XX(ENOPROTOOPT, "protocol not available")                                   \
0127   XX(ENOSPC, "no space left on device")                                       \
0128   XX(ENOSYS, "function not implemented")                                      \
0129   XX(ENOTCONN, "socket is not connected")                                     \
0130   XX(ENOTDIR, "not a directory")                                              \
0131   XX(ENOTEMPTY, "directory not empty")                                        \
0132   XX(ENOTSOCK, "socket operation on non-socket")                              \
0133   XX(ENOTSUP, "operation not supported on socket")                            \
0134   XX(EOVERFLOW, "value too large for defined data type")                      \
0135   XX(EPERM, "operation not permitted")                                        \
0136   XX(EPIPE, "broken pipe")                                                    \
0137   XX(EPROTO, "protocol error")                                                \
0138   XX(EPROTONOSUPPORT, "protocol not supported")                               \
0139   XX(EPROTOTYPE, "protocol wrong type for socket")                            \
0140   XX(ERANGE, "result too large")                                              \
0141   XX(EROFS, "read-only file system")                                          \
0142   XX(ESHUTDOWN, "cannot send after transport endpoint shutdown")              \
0143   XX(ESPIPE, "invalid seek")                                                  \
0144   XX(ESRCH, "no such process")                                                \
0145   XX(ETIMEDOUT, "connection timed out")                                       \
0146   XX(ETXTBSY, "text file is busy")                                            \
0147   XX(EXDEV, "cross-device link not permitted")                                \
0148   XX(UNKNOWN, "unknown error")                                                \
0149   XX(EOF, "end of file")                                                      \
0150   XX(ENXIO, "no such device or address")                                      \
0151   XX(EMLINK, "too many links")                                                \
0152   XX(EHOSTDOWN, "host is down")                                               \
0153   XX(EREMOTEIO, "remote I/O error")                                           \
0154   XX(ENOTTY, "inappropriate ioctl for device")                                \
0155   XX(EFTYPE, "inappropriate file type or format")                             \
0156   XX(EILSEQ, "illegal byte sequence")                                         \
0157   XX(ESOCKTNOSUPPORT, "socket type not supported")                            \
0158   XX(ENODATA, "no data available")                                            \
0159   XX(EUNATCH, "protocol driver not attached")                                 \
0160 
0161 #define UV_HANDLE_TYPE_MAP(XX)                                                \
0162   XX(ASYNC, async)                                                            \
0163   XX(CHECK, check)                                                            \
0164   XX(FS_EVENT, fs_event)                                                      \
0165   XX(FS_POLL, fs_poll)                                                        \
0166   XX(HANDLE, handle)                                                          \
0167   XX(IDLE, idle)                                                              \
0168   XX(NAMED_PIPE, pipe)                                                        \
0169   XX(POLL, poll)                                                              \
0170   XX(PREPARE, prepare)                                                        \
0171   XX(PROCESS, process)                                                        \
0172   XX(STREAM, stream)                                                          \
0173   XX(TCP, tcp)                                                                \
0174   XX(TIMER, timer)                                                            \
0175   XX(TTY, tty)                                                                \
0176   XX(UDP, udp)                                                                \
0177   XX(SIGNAL, signal)                                                          \
0178 
0179 #define UV_REQ_TYPE_MAP(XX)                                                   \
0180   XX(REQ, req)                                                                \
0181   XX(CONNECT, connect)                                                        \
0182   XX(WRITE, write)                                                            \
0183   XX(SHUTDOWN, shutdown)                                                      \
0184   XX(UDP_SEND, udp_send)                                                      \
0185   XX(FS, fs)                                                                  \
0186   XX(WORK, work)                                                              \
0187   XX(GETADDRINFO, getaddrinfo)                                                \
0188   XX(GETNAMEINFO, getnameinfo)                                                \
0189   XX(RANDOM, random)                                                          \
0190 
0191 typedef enum {
0192 #define XX(code, _) UV_ ## code = UV__ ## code,
0193   UV_ERRNO_MAP(XX)
0194 #undef XX
0195   UV_ERRNO_MAX = UV__EOF - 1
0196 } uv_errno_t;
0197 
0198 typedef enum {
0199   UV_UNKNOWN_HANDLE = 0,
0200 #define XX(uc, lc) UV_##uc,
0201   UV_HANDLE_TYPE_MAP(XX)
0202 #undef XX
0203   UV_FILE,
0204   UV_HANDLE_TYPE_MAX
0205 } uv_handle_type;
0206 
0207 typedef enum {
0208   UV_UNKNOWN_REQ = 0,
0209 #define XX(uc, lc) UV_##uc,
0210   UV_REQ_TYPE_MAP(XX)
0211 #undef XX
0212   UV_REQ_TYPE_PRIVATE
0213   UV_REQ_TYPE_MAX
0214 } uv_req_type;
0215 
0216 
0217 /* Handle types. */
0218 typedef struct uv_loop_s uv_loop_t;
0219 typedef struct uv_handle_s uv_handle_t;
0220 typedef struct uv_dir_s uv_dir_t;
0221 typedef struct uv_stream_s uv_stream_t;
0222 typedef struct uv_tcp_s uv_tcp_t;
0223 typedef struct uv_udp_s uv_udp_t;
0224 typedef struct uv_pipe_s uv_pipe_t;
0225 typedef struct uv_tty_s uv_tty_t;
0226 typedef struct uv_poll_s uv_poll_t;
0227 typedef struct uv_timer_s uv_timer_t;
0228 typedef struct uv_prepare_s uv_prepare_t;
0229 typedef struct uv_check_s uv_check_t;
0230 typedef struct uv_idle_s uv_idle_t;
0231 typedef struct uv_async_s uv_async_t;
0232 typedef struct uv_process_s uv_process_t;
0233 typedef struct uv_fs_event_s uv_fs_event_t;
0234 typedef struct uv_fs_poll_s uv_fs_poll_t;
0235 typedef struct uv_signal_s uv_signal_t;
0236 
0237 /* Request types. */
0238 typedef struct uv_req_s uv_req_t;
0239 typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
0240 typedef struct uv_getnameinfo_s uv_getnameinfo_t;
0241 typedef struct uv_shutdown_s uv_shutdown_t;
0242 typedef struct uv_write_s uv_write_t;
0243 typedef struct uv_connect_s uv_connect_t;
0244 typedef struct uv_udp_send_s uv_udp_send_t;
0245 typedef struct uv_fs_s uv_fs_t;
0246 typedef struct uv_work_s uv_work_t;
0247 typedef struct uv_random_s uv_random_t;
0248 
0249 /* None of the above. */
0250 typedef struct uv_env_item_s uv_env_item_t;
0251 typedef struct uv_cpu_info_s uv_cpu_info_t;
0252 typedef struct uv_interface_address_s uv_interface_address_t;
0253 typedef struct uv_dirent_s uv_dirent_t;
0254 typedef struct uv_passwd_s uv_passwd_t;
0255 typedef struct uv_group_s uv_group_t;
0256 typedef struct uv_utsname_s uv_utsname_t;
0257 typedef struct uv_statfs_s uv_statfs_t;
0258 
0259 typedef struct uv_metrics_s uv_metrics_t;
0260 
0261 typedef enum {
0262   UV_LOOP_BLOCK_SIGNAL = 0,
0263   UV_METRICS_IDLE_TIME
0264 } uv_loop_option;
0265 
0266 typedef enum {
0267   UV_RUN_DEFAULT = 0,
0268   UV_RUN_ONCE,
0269   UV_RUN_NOWAIT
0270 } uv_run_mode;
0271 
0272 
0273 UV_EXTERN unsigned int uv_version(void);
0274 UV_EXTERN const char* uv_version_string(void);
0275 
0276 typedef void* (*uv_malloc_func)(size_t size);
0277 typedef void* (*uv_realloc_func)(void* ptr, size_t size);
0278 typedef void* (*uv_calloc_func)(size_t count, size_t size);
0279 typedef void (*uv_free_func)(void* ptr);
0280 
0281 UV_EXTERN void uv_library_shutdown(void);
0282 
0283 UV_EXTERN int uv_replace_allocator(uv_malloc_func malloc_func,
0284                                    uv_realloc_func realloc_func,
0285                                    uv_calloc_func calloc_func,
0286                                    uv_free_func free_func);
0287 
0288 UV_EXTERN uv_loop_t* uv_default_loop(void);
0289 UV_EXTERN int uv_loop_init(uv_loop_t* loop);
0290 UV_EXTERN int uv_loop_close(uv_loop_t* loop);
0291 /*
0292  * NOTE:
0293  *  This function is DEPRECATED, users should
0294  *  allocate the loop manually and use uv_loop_init instead.
0295  */
0296 UV_EXTERN uv_loop_t* uv_loop_new(void);
0297 /*
0298  * NOTE:
0299  *  This function is DEPRECATED. Users should use
0300  *  uv_loop_close and free the memory manually instead.
0301  */
0302 UV_EXTERN void uv_loop_delete(uv_loop_t*);
0303 UV_EXTERN size_t uv_loop_size(void);
0304 UV_EXTERN int uv_loop_alive(const uv_loop_t* loop);
0305 UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...);
0306 UV_EXTERN int uv_loop_fork(uv_loop_t* loop);
0307 
0308 UV_EXTERN int uv_run(uv_loop_t*, uv_run_mode mode);
0309 UV_EXTERN void uv_stop(uv_loop_t*);
0310 
0311 UV_EXTERN void uv_ref(uv_handle_t*);
0312 UV_EXTERN void uv_unref(uv_handle_t*);
0313 UV_EXTERN int uv_has_ref(const uv_handle_t*);
0314 
0315 UV_EXTERN void uv_update_time(uv_loop_t*);
0316 UV_EXTERN uint64_t uv_now(const uv_loop_t*);
0317 
0318 UV_EXTERN int uv_backend_fd(const uv_loop_t*);
0319 UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
0320 
0321 typedef void (*uv_alloc_cb)(uv_handle_t* handle,
0322                             size_t suggested_size,
0323                             uv_buf_t* buf);
0324 typedef void (*uv_read_cb)(uv_stream_t* stream,
0325                            ssize_t nread,
0326                            const uv_buf_t* buf);
0327 typedef void (*uv_write_cb)(uv_write_t* req, int status);
0328 typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
0329 typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
0330 typedef void (*uv_connection_cb)(uv_stream_t* server, int status);
0331 typedef void (*uv_close_cb)(uv_handle_t* handle);
0332 typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events);
0333 typedef void (*uv_timer_cb)(uv_timer_t* handle);
0334 typedef void (*uv_async_cb)(uv_async_t* handle);
0335 typedef void (*uv_prepare_cb)(uv_prepare_t* handle);
0336 typedef void (*uv_check_cb)(uv_check_t* handle);
0337 typedef void (*uv_idle_cb)(uv_idle_t* handle);
0338 typedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status, int term_signal);
0339 typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
0340 typedef void (*uv_fs_cb)(uv_fs_t* req);
0341 typedef void (*uv_work_cb)(uv_work_t* req);
0342 typedef void (*uv_after_work_cb)(uv_work_t* req, int status);
0343 typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
0344                                   int status,
0345                                   struct addrinfo* res);
0346 typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
0347                                   int status,
0348                                   const char* hostname,
0349                                   const char* service);
0350 typedef void (*uv_random_cb)(uv_random_t* req,
0351                              int status,
0352                              void* buf,
0353                              size_t buflen);
0354 
0355 typedef enum {
0356   UV_CLOCK_MONOTONIC,
0357   UV_CLOCK_REALTIME
0358 } uv_clock_id;
0359 
0360 /* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
0361 typedef struct {
0362   long tv_sec;
0363   long tv_nsec;
0364 } uv_timespec_t;
0365 
0366 typedef struct {
0367   int64_t tv_sec;
0368   int32_t tv_nsec;
0369 } uv_timespec64_t;
0370 
0371 /* XXX(bnoordhuis) not 2038-proof, https://github.com/libuv/libuv/issues/3864 */
0372 typedef struct {
0373   long tv_sec;
0374   long tv_usec;
0375 } uv_timeval_t;
0376 
0377 typedef struct {
0378   int64_t tv_sec;
0379   int32_t tv_usec;
0380 } uv_timeval64_t;
0381 
0382 typedef struct {
0383   uint64_t st_dev;
0384   uint64_t st_mode;
0385   uint64_t st_nlink;
0386   uint64_t st_uid;
0387   uint64_t st_gid;
0388   uint64_t st_rdev;
0389   uint64_t st_ino;
0390   uint64_t st_size;
0391   uint64_t st_blksize;
0392   uint64_t st_blocks;
0393   uint64_t st_flags;
0394   uint64_t st_gen;
0395   uv_timespec_t st_atim;
0396   uv_timespec_t st_mtim;
0397   uv_timespec_t st_ctim;
0398   uv_timespec_t st_birthtim;
0399 } uv_stat_t;
0400 
0401 
0402 typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle,
0403                                const char* filename,
0404                                int events,
0405                                int status);
0406 
0407 typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
0408                               int status,
0409                               const uv_stat_t* prev,
0410                               const uv_stat_t* curr);
0411 
0412 typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum);
0413 
0414 
0415 typedef enum {
0416   UV_LEAVE_GROUP = 0,
0417   UV_JOIN_GROUP
0418 } uv_membership;
0419 
0420 
0421 UV_EXTERN int uv_translate_sys_error(int sys_errno);
0422 
0423 UV_EXTERN const char* uv_strerror(int err);
0424 UV_EXTERN char* uv_strerror_r(int err, char* buf, size_t buflen);
0425 
0426 UV_EXTERN const char* uv_err_name(int err);
0427 UV_EXTERN char* uv_err_name_r(int err, char* buf, size_t buflen);
0428 
0429 
0430 #define UV_REQ_FIELDS                                                         \
0431   /* public */                                                                \
0432   void* data;                                                                 \
0433   /* read-only */                                                             \
0434   uv_req_type type;                                                           \
0435   /* private */                                                               \
0436   void* reserved[6];                                                          \
0437   UV_REQ_PRIVATE_FIELDS                                                       \
0438 
0439 /* Abstract base class of all requests. */
0440 struct uv_req_s {
0441   UV_REQ_FIELDS
0442 };
0443 
0444 
0445 /* Platform-specific request types. */
0446 UV_PRIVATE_REQ_TYPES
0447 
0448 
0449 UV_EXTERN int uv_shutdown(uv_shutdown_t* req,
0450                           uv_stream_t* handle,
0451                           uv_shutdown_cb cb);
0452 
0453 struct uv_shutdown_s {
0454   UV_REQ_FIELDS
0455   uv_stream_t* handle;
0456   uv_shutdown_cb cb;
0457   UV_SHUTDOWN_PRIVATE_FIELDS
0458 };
0459 
0460 
0461 #define UV_HANDLE_FIELDS                                                      \
0462   /* public */                                                                \
0463   void* data;                                                                 \
0464   /* read-only */                                                             \
0465   uv_loop_t* loop;                                                            \
0466   uv_handle_type type;                                                        \
0467   /* private */                                                               \
0468   uv_close_cb close_cb;                                                       \
0469   struct uv__queue handle_queue;                                              \
0470   union {                                                                     \
0471     int fd;                                                                   \
0472     void* reserved[4];                                                        \
0473   } u;                                                                        \
0474   UV_HANDLE_PRIVATE_FIELDS                                                    \
0475 
0476 /* The abstract base class of all handles. */
0477 struct uv_handle_s {
0478   UV_HANDLE_FIELDS
0479 };
0480 
0481 UV_EXTERN size_t uv_handle_size(uv_handle_type type);
0482 UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle);
0483 UV_EXTERN const char* uv_handle_type_name(uv_handle_type type);
0484 UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle);
0485 UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle);
0486 UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data);
0487 
0488 UV_EXTERN size_t uv_req_size(uv_req_type type);
0489 UV_EXTERN void* uv_req_get_data(const uv_req_t* req);
0490 UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data);
0491 UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req);
0492 UV_EXTERN const char* uv_req_type_name(uv_req_type type);
0493 
0494 UV_EXTERN int uv_is_active(const uv_handle_t* handle);
0495 
0496 UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
0497 
0498 /* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */
0499 UV_EXTERN void uv_print_all_handles(uv_loop_t* loop, FILE* stream);
0500 UV_EXTERN void uv_print_active_handles(uv_loop_t* loop, FILE* stream);
0501 
0502 UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
0503 
0504 UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value);
0505 UV_EXTERN int uv_recv_buffer_size(uv_handle_t* handle, int* value);
0506 
0507 UV_EXTERN int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd);
0508 
0509 UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
0510 
0511 UV_EXTERN int uv_pipe(uv_file fds[2], int read_flags, int write_flags);
0512 UV_EXTERN int uv_socketpair(int type,
0513                             int protocol,
0514                             uv_os_sock_t socket_vector[2],
0515                             int flags0,
0516                             int flags1);
0517 
0518 #define UV_STREAM_FIELDS                                                      \
0519   /* number of bytes queued for writing */                                    \
0520   size_t write_queue_size;                                                    \
0521   uv_alloc_cb alloc_cb;                                                       \
0522   uv_read_cb read_cb;                                                         \
0523   /* private */                                                               \
0524   UV_STREAM_PRIVATE_FIELDS
0525 
0526 /*
0527  * uv_stream_t is a subclass of uv_handle_t.
0528  *
0529  * uv_stream is an abstract class.
0530  *
0531  * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t.
0532  */
0533 struct uv_stream_s {
0534   UV_HANDLE_FIELDS
0535   UV_STREAM_FIELDS
0536 };
0537 
0538 UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);
0539 
0540 UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
0541 UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
0542 
0543 UV_EXTERN int uv_read_start(uv_stream_t*,
0544                             uv_alloc_cb alloc_cb,
0545                             uv_read_cb read_cb);
0546 UV_EXTERN int uv_read_stop(uv_stream_t*);
0547 
0548 UV_EXTERN int uv_write(uv_write_t* req,
0549                        uv_stream_t* handle,
0550                        const uv_buf_t bufs[],
0551                        unsigned int nbufs,
0552                        uv_write_cb cb);
0553 UV_EXTERN int uv_write2(uv_write_t* req,
0554                         uv_stream_t* handle,
0555                         const uv_buf_t bufs[],
0556                         unsigned int nbufs,
0557                         uv_stream_t* send_handle,
0558                         uv_write_cb cb);
0559 UV_EXTERN int uv_try_write(uv_stream_t* handle,
0560                            const uv_buf_t bufs[],
0561                            unsigned int nbufs);
0562 UV_EXTERN int uv_try_write2(uv_stream_t* handle,
0563                             const uv_buf_t bufs[],
0564                             unsigned int nbufs,
0565                             uv_stream_t* send_handle);
0566 
0567 /* uv_write_t is a subclass of uv_req_t. */
0568 struct uv_write_s {
0569   UV_REQ_FIELDS
0570   uv_write_cb cb;
0571   uv_stream_t* send_handle; /* TODO: make private and unix-only in v2.x. */
0572   uv_stream_t* handle;
0573   UV_WRITE_PRIVATE_FIELDS
0574 };
0575 
0576 
0577 UV_EXTERN int uv_is_readable(const uv_stream_t* handle);
0578 UV_EXTERN int uv_is_writable(const uv_stream_t* handle);
0579 
0580 UV_EXTERN int uv_stream_set_blocking(uv_stream_t* handle, int blocking);
0581 
0582 UV_EXTERN int uv_is_closing(const uv_handle_t* handle);
0583 
0584 
0585 /*
0586  * uv_tcp_t is a subclass of uv_stream_t.
0587  *
0588  * Represents a TCP stream or TCP server.
0589  */
0590 struct uv_tcp_s {
0591   UV_HANDLE_FIELDS
0592   UV_STREAM_FIELDS
0593   UV_TCP_PRIVATE_FIELDS
0594 };
0595 
0596 UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
0597 UV_EXTERN int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, unsigned int flags);
0598 UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
0599 UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
0600 UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
0601                                int enable,
0602                                unsigned int delay);
0603 UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
0604 
0605 enum uv_tcp_flags {
0606   /* Used with uv_tcp_bind, when an IPv6 address is used. */
0607   UV_TCP_IPV6ONLY = 1
0608 };
0609 
0610 UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
0611                           const struct sockaddr* addr,
0612                           unsigned int flags);
0613 UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle,
0614                                  struct sockaddr* name,
0615                                  int* namelen);
0616 UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle,
0617                                  struct sockaddr* name,
0618                                  int* namelen);
0619 UV_EXTERN int uv_tcp_close_reset(uv_tcp_t* handle, uv_close_cb close_cb);
0620 UV_EXTERN int uv_tcp_connect(uv_connect_t* req,
0621                              uv_tcp_t* handle,
0622                              const struct sockaddr* addr,
0623                              uv_connect_cb cb);
0624 
0625 /* uv_connect_t is a subclass of uv_req_t. */
0626 struct uv_connect_s {
0627   UV_REQ_FIELDS
0628   uv_connect_cb cb;
0629   uv_stream_t* handle;
0630   UV_CONNECT_PRIVATE_FIELDS
0631 };
0632 
0633 
0634 /*
0635  * UDP support.
0636  */
0637 
0638 enum uv_udp_flags {
0639   /* Disables dual stack mode. */
0640   UV_UDP_IPV6ONLY = 1,
0641   /*
0642    * Indicates message was truncated because read buffer was too small. The
0643    * remainder was discarded by the OS. Used in uv_udp_recv_cb.
0644    */
0645   UV_UDP_PARTIAL = 2,
0646   /*
0647    * Indicates if SO_REUSEADDR will be set when binding the handle.
0648    * This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
0649    * Unix platforms, it sets the SO_REUSEADDR flag.  What that means is that
0650    * multiple threads or processes can bind to the same address without error
0651    * (provided they all set the flag) but only the last one to bind will receive
0652    * any traffic, in effect "stealing" the port from the previous listener.
0653    */
0654   UV_UDP_REUSEADDR = 4,
0655   /*
0656    * Indicates that the message was received by recvmmsg, so the buffer provided
0657    * must not be freed by the recv_cb callback.
0658    */
0659   UV_UDP_MMSG_CHUNK = 8,
0660   /*
0661    * Indicates that the buffer provided has been fully utilized by recvmmsg and
0662    * that it should now be freed by the recv_cb callback. When this flag is set
0663    * in uv_udp_recv_cb, nread will always be 0 and addr will always be NULL.
0664    */
0665   UV_UDP_MMSG_FREE = 16,
0666   /*
0667    * Indicates if IP_RECVERR/IPV6_RECVERR will be set when binding the handle.
0668    * This sets IP_RECVERR for IPv4 and IPV6_RECVERR for IPv6 UDP sockets on
0669    * Linux. This stops the Linux kernel from suppressing some ICMP error
0670    * messages and enables full ICMP error reporting for faster failover.
0671    * This flag is no-op on platforms other than Linux.
0672    */
0673   UV_UDP_LINUX_RECVERR = 32,
0674   /*
0675    * Indicates that recvmmsg should be used, if available.
0676    */
0677   UV_UDP_RECVMMSG = 256
0678 };
0679 
0680 typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
0681 typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
0682                                ssize_t nread,
0683                                const uv_buf_t* buf,
0684                                const struct sockaddr* addr,
0685                                unsigned flags);
0686 
0687 /* uv_udp_t is a subclass of uv_handle_t. */
0688 struct uv_udp_s {
0689   UV_HANDLE_FIELDS
0690   /* read-only */
0691   /*
0692    * Number of bytes queued for sending. This field strictly shows how much
0693    * information is currently queued.
0694    */
0695   size_t send_queue_size;
0696   /*
0697    * Number of send requests currently in the queue awaiting to be processed.
0698    */
0699   size_t send_queue_count;
0700   UV_UDP_PRIVATE_FIELDS
0701 };
0702 
0703 /* uv_udp_send_t is a subclass of uv_req_t. */
0704 struct uv_udp_send_s {
0705   UV_REQ_FIELDS
0706   uv_udp_t* handle;
0707   uv_udp_send_cb cb;
0708   UV_UDP_SEND_PRIVATE_FIELDS
0709 };
0710 
0711 UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
0712 UV_EXTERN int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, unsigned int flags);
0713 UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
0714 UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
0715                           const struct sockaddr* addr,
0716                           unsigned int flags);
0717 UV_EXTERN int uv_udp_connect(uv_udp_t* handle, const struct sockaddr* addr);
0718 
0719 UV_EXTERN int uv_udp_getpeername(const uv_udp_t* handle,
0720                                  struct sockaddr* name,
0721                                  int* namelen);
0722 UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
0723                                  struct sockaddr* name,
0724                                  int* namelen);
0725 UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
0726                                     const char* multicast_addr,
0727                                     const char* interface_addr,
0728                                     uv_membership membership);
0729 UV_EXTERN int uv_udp_set_source_membership(uv_udp_t* handle,
0730                                            const char* multicast_addr,
0731                                            const char* interface_addr,
0732                                            const char* source_addr,
0733                                            uv_membership membership);
0734 UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
0735 UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
0736 UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle,
0737                                              const char* interface_addr);
0738 UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
0739 UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
0740 UV_EXTERN int uv_udp_send(uv_udp_send_t* req,
0741                           uv_udp_t* handle,
0742                           const uv_buf_t bufs[],
0743                           unsigned int nbufs,
0744                           const struct sockaddr* addr,
0745                           uv_udp_send_cb send_cb);
0746 UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
0747                               const uv_buf_t bufs[],
0748                               unsigned int nbufs,
0749                               const struct sockaddr* addr);
0750 UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
0751                                 uv_alloc_cb alloc_cb,
0752                                 uv_udp_recv_cb recv_cb);
0753 UV_EXTERN int uv_udp_using_recvmmsg(const uv_udp_t* handle);
0754 UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
0755 UV_EXTERN size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
0756 UV_EXTERN size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);
0757 
0758 
0759 /*
0760  * uv_tty_t is a subclass of uv_stream_t.
0761  *
0762  * Representing a stream for the console.
0763  */
0764 struct uv_tty_s {
0765   UV_HANDLE_FIELDS
0766   UV_STREAM_FIELDS
0767   UV_TTY_PRIVATE_FIELDS
0768 };
0769 
0770 typedef enum {
0771   /* Initial/normal terminal mode */
0772   UV_TTY_MODE_NORMAL,
0773   /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
0774   UV_TTY_MODE_RAW,
0775   /* Binary-safe I/O mode for IPC (Unix-only) */
0776   UV_TTY_MODE_IO
0777 } uv_tty_mode_t;
0778 
0779 typedef enum {
0780   /*
0781    * The console supports handling of virtual terminal sequences
0782    * (Windows10 new console, ConEmu)
0783    */
0784   UV_TTY_SUPPORTED,
0785   /* The console cannot process the virtual terminal sequence.  (Legacy
0786    * console)
0787    */
0788   UV_TTY_UNSUPPORTED
0789 } uv_tty_vtermstate_t;
0790 
0791 
0792 UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
0793 UV_EXTERN int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode);
0794 UV_EXTERN int uv_tty_reset_mode(void);
0795 UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);
0796 UV_EXTERN void uv_tty_set_vterm_state(uv_tty_vtermstate_t state);
0797 UV_EXTERN int uv_tty_get_vterm_state(uv_tty_vtermstate_t* state);
0798 
0799 #ifdef __cplusplus
0800 extern "C++" {
0801 
0802 inline int uv_tty_set_mode(uv_tty_t* handle, int mode) {
0803   return uv_tty_set_mode(handle, static_cast<uv_tty_mode_t>(mode));
0804 }
0805 
0806 }
0807 #endif
0808 
0809 UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
0810 
0811 enum {
0812   UV_PIPE_NO_TRUNCATE = 1u << 0
0813 };
0814 
0815 /*
0816  * uv_pipe_t is a subclass of uv_stream_t.
0817  *
0818  * Representing a pipe stream or pipe server. On Windows this is a Named
0819  * Pipe. On Unix this is a Unix domain socket.
0820  */
0821 struct uv_pipe_s {
0822   UV_HANDLE_FIELDS
0823   UV_STREAM_FIELDS
0824   int ipc; /* non-zero if this pipe is used for passing handles */
0825   UV_PIPE_PRIVATE_FIELDS
0826 };
0827 
0828 UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
0829 UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
0830 UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
0831 UV_EXTERN int uv_pipe_bind2(uv_pipe_t* handle,
0832                             const char* name,
0833                             size_t namelen,
0834                             unsigned int flags);
0835 UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
0836                                uv_pipe_t* handle,
0837                                const char* name,
0838                                uv_connect_cb cb);
0839 UV_EXTERN int uv_pipe_connect2(uv_connect_t* req,
0840                                uv_pipe_t* handle,
0841                                const char* name,
0842                                size_t namelen,
0843                                unsigned int flags,
0844                                uv_connect_cb cb);
0845 UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
0846                                   char* buffer,
0847                                   size_t* size);
0848 UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
0849                                   char* buffer,
0850                                   size_t* size);
0851 UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
0852 UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle);
0853 UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
0854 UV_EXTERN int uv_pipe_chmod(uv_pipe_t* handle, int flags);
0855 
0856 
0857 struct uv_poll_s {
0858   UV_HANDLE_FIELDS
0859   uv_poll_cb poll_cb;
0860   UV_POLL_PRIVATE_FIELDS
0861 };
0862 
0863 enum uv_poll_event {
0864   UV_READABLE = 1,
0865   UV_WRITABLE = 2,
0866   UV_DISCONNECT = 4,
0867   UV_PRIORITIZED = 8
0868 };
0869 
0870 UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
0871 UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop,
0872                                   uv_poll_t* handle,
0873                                   uv_os_sock_t socket);
0874 UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb);
0875 UV_EXTERN int uv_poll_stop(uv_poll_t* handle);
0876 
0877 
0878 struct uv_prepare_s {
0879   UV_HANDLE_FIELDS
0880   UV_PREPARE_PRIVATE_FIELDS
0881 };
0882 
0883 UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
0884 UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
0885 UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare);
0886 
0887 
0888 struct uv_check_s {
0889   UV_HANDLE_FIELDS
0890   UV_CHECK_PRIVATE_FIELDS
0891 };
0892 
0893 UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check);
0894 UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb);
0895 UV_EXTERN int uv_check_stop(uv_check_t* check);
0896 
0897 
0898 struct uv_idle_s {
0899   UV_HANDLE_FIELDS
0900   UV_IDLE_PRIVATE_FIELDS
0901 };
0902 
0903 UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle);
0904 UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);
0905 UV_EXTERN int uv_idle_stop(uv_idle_t* idle);
0906 
0907 
0908 struct uv_async_s {
0909   UV_HANDLE_FIELDS
0910   UV_ASYNC_PRIVATE_FIELDS
0911 };
0912 
0913 UV_EXTERN int uv_async_init(uv_loop_t*,
0914                             uv_async_t* async,
0915                             uv_async_cb async_cb);
0916 UV_EXTERN int uv_async_send(uv_async_t* async);
0917 
0918 
0919 /*
0920  * uv_timer_t is a subclass of uv_handle_t.
0921  *
0922  * Used to get woken up at a specified time in the future.
0923  */
0924 struct uv_timer_s {
0925   UV_HANDLE_FIELDS
0926   UV_TIMER_PRIVATE_FIELDS
0927 };
0928 
0929 UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
0930 UV_EXTERN int uv_timer_start(uv_timer_t* handle,
0931                              uv_timer_cb cb,
0932                              uint64_t timeout,
0933                              uint64_t repeat);
0934 UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
0935 UV_EXTERN int uv_timer_again(uv_timer_t* handle);
0936 UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
0937 UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
0938 UV_EXTERN uint64_t uv_timer_get_due_in(const uv_timer_t* handle);
0939 
0940 
0941 /*
0942  * uv_getaddrinfo_t is a subclass of uv_req_t.
0943  *
0944  * Request object for uv_getaddrinfo.
0945  */
0946 struct uv_getaddrinfo_s {
0947   UV_REQ_FIELDS
0948   /* read-only */
0949   uv_loop_t* loop;
0950   /* struct addrinfo* addrinfo is marked as private, but it really isn't. */
0951   UV_GETADDRINFO_PRIVATE_FIELDS
0952 };
0953 
0954 
0955 UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop,
0956                              uv_getaddrinfo_t* req,
0957                              uv_getaddrinfo_cb getaddrinfo_cb,
0958                              const char* node,
0959                              const char* service,
0960                              const struct addrinfo* hints);
0961 UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
0962 
0963 
0964 /*
0965 * uv_getnameinfo_t is a subclass of uv_req_t.
0966 *
0967 * Request object for uv_getnameinfo.
0968 */
0969 struct uv_getnameinfo_s {
0970   UV_REQ_FIELDS
0971   /* read-only */
0972   uv_loop_t* loop;
0973   /* host and service are marked as private, but they really aren't. */
0974   UV_GETNAMEINFO_PRIVATE_FIELDS
0975 };
0976 
0977 UV_EXTERN int uv_getnameinfo(uv_loop_t* loop,
0978                              uv_getnameinfo_t* req,
0979                              uv_getnameinfo_cb getnameinfo_cb,
0980                              const struct sockaddr* addr,
0981                              int flags);
0982 
0983 
0984 /* uv_spawn() options. */
0985 typedef enum {
0986   UV_IGNORE         = 0x00,
0987   UV_CREATE_PIPE    = 0x01,
0988   UV_INHERIT_FD     = 0x02,
0989   UV_INHERIT_STREAM = 0x04,
0990 
0991   /*
0992    * When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
0993    * determine the direction of flow, from the child process' perspective. Both
0994    * flags may be specified to create a duplex data stream.
0995    */
0996   UV_READABLE_PIPE  = 0x10,
0997   UV_WRITABLE_PIPE  = 0x20,
0998 
0999   /*
1000    * When UV_CREATE_PIPE is specified, specifying UV_NONBLOCK_PIPE opens the
1001    * handle in non-blocking mode in the child. This may cause loss of data,
1002    * if the child is not designed to handle to encounter this mode,
1003    * but can also be significantly more efficient.
1004    */
1005   UV_NONBLOCK_PIPE  = 0x40,
1006   UV_OVERLAPPED_PIPE = 0x40 /* old name, for compatibility */
1007 } uv_stdio_flags;
1008 
1009 typedef struct uv_stdio_container_s {
1010   uv_stdio_flags flags;
1011 
1012   union {
1013     uv_stream_t* stream;
1014     int fd;
1015   } data;
1016 } uv_stdio_container_t;
1017 
1018 typedef struct uv_process_options_s {
1019   uv_exit_cb exit_cb; /* Called after the process exits. */
1020   const char* file;   /* Path to program to execute. */
1021   /*
1022    * Command line arguments. args[0] should be the path to the program. On
1023    * Windows this uses CreateProcess which concatenates the arguments into a
1024    * string this can cause some strange errors. See the note at
1025    * windows_verbatim_arguments.
1026    */
1027   char** args;
1028   /*
1029    * This will be set as the environ variable in the subprocess. If this is
1030    * NULL then the parents environ will be used.
1031    */
1032   char** env;
1033   /*
1034    * If non-null this represents a directory the subprocess should execute
1035    * in. Stands for current working directory.
1036    */
1037   const char* cwd;
1038   /*
1039    * Various flags that control how uv_spawn() behaves. See the definition of
1040    * `enum uv_process_flags` below.
1041    */
1042   unsigned int flags;
1043   /*
1044    * The `stdio` field points to an array of uv_stdio_container_t structs that
1045    * describe the file descriptors that will be made available to the child
1046    * process. The convention is that stdio[0] points to stdin, fd 1 is used for
1047    * stdout, and fd 2 is stderr.
1048    *
1049    * Note that on windows file descriptors greater than 2 are available to the
1050    * child process only if the child processes uses the MSVCRT runtime.
1051    */
1052   int stdio_count;
1053   uv_stdio_container_t* stdio;
1054   /*
1055    * Libuv can change the child process' user/group id. This happens only when
1056    * the appropriate bits are set in the flags fields. This is not supported on
1057    * windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
1058    */
1059   uv_uid_t uid;
1060   uv_gid_t gid;
1061 } uv_process_options_t;
1062 
1063 /*
1064  * These are the flags that can be used for the uv_process_options.flags field.
1065  */
1066 enum uv_process_flags {
1067   /*
1068    * Set the child process' user id. The user id is supplied in the `uid` field
1069    * of the options struct. This does not work on windows; setting this flag
1070    * will cause uv_spawn() to fail.
1071    */
1072   UV_PROCESS_SETUID = (1 << 0),
1073   /*
1074    * Set the child process' group id. The user id is supplied in the `gid`
1075    * field of the options struct. This does not work on windows; setting this
1076    * flag will cause uv_spawn() to fail.
1077    */
1078   UV_PROCESS_SETGID = (1 << 1),
1079   /*
1080    * Do not wrap any arguments in quotes, or perform any other escaping, when
1081    * converting the argument list into a command line string. This option is
1082    * only meaningful on Windows systems. On Unix it is silently ignored.
1083    */
1084   UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
1085   /*
1086    * Spawn the child process in a detached state - this will make it a process
1087    * group leader, and will effectively enable the child to keep running after
1088    * the parent exits.  Note that the child process will still keep the
1089    * parent's event loop alive unless the parent process calls uv_unref() on
1090    * the child's process handle.
1091    */
1092   UV_PROCESS_DETACHED = (1 << 3),
1093   /*
1094    * Hide the subprocess window that would normally be created. This option is
1095    * only meaningful on Windows systems. On Unix it is silently ignored.
1096    */
1097   UV_PROCESS_WINDOWS_HIDE = (1 << 4),
1098   /*
1099    * Hide the subprocess console window that would normally be created. This
1100    * option is only meaningful on Windows systems. On Unix it is silently
1101    * ignored.
1102    */
1103   UV_PROCESS_WINDOWS_HIDE_CONSOLE = (1 << 5),
1104   /*
1105    * Hide the subprocess GUI window that would normally be created. This
1106    * option is only meaningful on Windows systems. On Unix it is silently
1107    * ignored.
1108    */
1109   UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6),
1110   /*
1111    * On Windows, if the path to the program to execute, specified in
1112    * uv_process_options_t's file field, has a directory component,
1113    * search for the exact file name before trying variants with
1114    * extensions like '.exe' or '.cmd'.
1115    */
1116   UV_PROCESS_WINDOWS_FILE_PATH_EXACT_NAME = (1 << 7)
1117 };
1118 
1119 /*
1120  * uv_process_t is a subclass of uv_handle_t.
1121  */
1122 struct uv_process_s {
1123   UV_HANDLE_FIELDS
1124   uv_exit_cb exit_cb;
1125   int pid;
1126   UV_PROCESS_PRIVATE_FIELDS
1127 };
1128 
1129 UV_EXTERN int uv_spawn(uv_loop_t* loop,
1130                        uv_process_t* handle,
1131                        const uv_process_options_t* options);
1132 UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
1133 UV_EXTERN int uv_kill(int pid, int signum);
1134 UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
1135 
1136 
1137 /*
1138  * uv_work_t is a subclass of uv_req_t.
1139  */
1140 struct uv_work_s {
1141   UV_REQ_FIELDS
1142   uv_loop_t* loop;
1143   uv_work_cb work_cb;
1144   uv_after_work_cb after_work_cb;
1145   UV_WORK_PRIVATE_FIELDS
1146 };
1147 
1148 UV_EXTERN int uv_queue_work(uv_loop_t* loop,
1149                             uv_work_t* req,
1150                             uv_work_cb work_cb,
1151                             uv_after_work_cb after_work_cb);
1152 
1153 UV_EXTERN int uv_cancel(uv_req_t* req);
1154 
1155 
1156 struct uv_cpu_times_s {
1157   uint64_t user; /* milliseconds */
1158   uint64_t nice; /* milliseconds */
1159   uint64_t sys; /* milliseconds */
1160   uint64_t idle; /* milliseconds */
1161   uint64_t irq; /* milliseconds */
1162 };
1163 
1164 struct uv_cpu_info_s {
1165   char* model;
1166   int speed;
1167   struct uv_cpu_times_s cpu_times;
1168 };
1169 
1170 struct uv_interface_address_s {
1171   char* name;
1172   char phys_addr[6];
1173   int is_internal;
1174   union {
1175     struct sockaddr_in address4;
1176     struct sockaddr_in6 address6;
1177   } address;
1178   union {
1179     struct sockaddr_in netmask4;
1180     struct sockaddr_in6 netmask6;
1181   } netmask;
1182 };
1183 
1184 struct uv_passwd_s {
1185   char* username;
1186   unsigned long uid;
1187   unsigned long gid;
1188   char* shell;
1189   char* homedir;
1190 };
1191 
1192 struct uv_group_s {
1193   char* groupname;
1194   unsigned long gid;
1195   char** members;
1196 };
1197 
1198 struct uv_utsname_s {
1199   char sysname[256];
1200   char release[256];
1201   char version[256];
1202   char machine[256];
1203   /* This struct does not contain the nodename and domainname fields present in
1204      the utsname type. domainname is a GNU extension. Both fields are referred
1205      to as meaningless in the docs. */
1206 };
1207 
1208 struct uv_statfs_s {
1209   uint64_t f_type;
1210   uint64_t f_bsize;
1211   uint64_t f_blocks;
1212   uint64_t f_bfree;
1213   uint64_t f_bavail;
1214   uint64_t f_files;
1215   uint64_t f_ffree;
1216   uint64_t f_spare[4];
1217 };
1218 
1219 typedef enum {
1220   UV_DIRENT_UNKNOWN,
1221   UV_DIRENT_FILE,
1222   UV_DIRENT_DIR,
1223   UV_DIRENT_LINK,
1224   UV_DIRENT_FIFO,
1225   UV_DIRENT_SOCKET,
1226   UV_DIRENT_CHAR,
1227   UV_DIRENT_BLOCK
1228 } uv_dirent_type_t;
1229 
1230 struct uv_dirent_s {
1231   const char* name;
1232   uv_dirent_type_t type;
1233 };
1234 
1235 UV_EXTERN char** uv_setup_args(int argc, char** argv);
1236 UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
1237 UV_EXTERN int uv_set_process_title(const char* title);
1238 UV_EXTERN int uv_resident_set_memory(size_t* rss);
1239 UV_EXTERN int uv_uptime(double* uptime);
1240 UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
1241 UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
1242 
1243 typedef struct {
1244    uv_timeval_t ru_utime; /* user CPU time used */
1245    uv_timeval_t ru_stime; /* system CPU time used */
1246    uint64_t ru_maxrss;    /* maximum resident set size */
1247    uint64_t ru_ixrss;     /* integral shared memory size */
1248    uint64_t ru_idrss;     /* integral unshared data size */
1249    uint64_t ru_isrss;     /* integral unshared stack size */
1250    uint64_t ru_minflt;    /* page reclaims (soft page faults) */
1251    uint64_t ru_majflt;    /* page faults (hard page faults) */
1252    uint64_t ru_nswap;     /* swaps */
1253    uint64_t ru_inblock;   /* block input operations */
1254    uint64_t ru_oublock;   /* block output operations */
1255    uint64_t ru_msgsnd;    /* IPC messages sent */
1256    uint64_t ru_msgrcv;    /* IPC messages received */
1257    uint64_t ru_nsignals;  /* signals received */
1258    uint64_t ru_nvcsw;     /* voluntary context switches */
1259    uint64_t ru_nivcsw;    /* involuntary context switches */
1260 } uv_rusage_t;
1261 
1262 UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
1263 
1264 UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
1265 UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
1266 UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
1267 UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
1268 UV_EXTERN int uv_os_get_passwd2(uv_passwd_t* pwd, uv_uid_t uid);
1269 UV_EXTERN int uv_os_get_group(uv_group_t* grp, uv_uid_t gid);
1270 UV_EXTERN void uv_os_free_group(uv_group_t* grp);
1271 UV_EXTERN uv_pid_t uv_os_getpid(void);
1272 UV_EXTERN uv_pid_t uv_os_getppid(void);
1273 
1274 #if defined(__PASE__)
1275 /* On IBM i PASE, the highest process priority is -10 */
1276 # define UV_PRIORITY_LOW 39          /* RUNPTY(99) */
1277 # define UV_PRIORITY_BELOW_NORMAL 15 /* RUNPTY(50) */
1278 # define UV_PRIORITY_NORMAL 0        /* RUNPTY(20) */
1279 # define UV_PRIORITY_ABOVE_NORMAL -4 /* RUNTY(12) */
1280 # define UV_PRIORITY_HIGH -7         /* RUNPTY(6) */
1281 # define UV_PRIORITY_HIGHEST -10     /* RUNPTY(1) */
1282 #else
1283 # define UV_PRIORITY_LOW 19
1284 # define UV_PRIORITY_BELOW_NORMAL 10
1285 # define UV_PRIORITY_NORMAL 0
1286 # define UV_PRIORITY_ABOVE_NORMAL -7
1287 # define UV_PRIORITY_HIGH -14
1288 # define UV_PRIORITY_HIGHEST -20
1289 #endif
1290 
1291 UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
1292 UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
1293 
1294 enum {
1295   UV_THREAD_PRIORITY_HIGHEST = 2,
1296   UV_THREAD_PRIORITY_ABOVE_NORMAL = 1,
1297   UV_THREAD_PRIORITY_NORMAL = 0,
1298   UV_THREAD_PRIORITY_BELOW_NORMAL = -1,
1299   UV_THREAD_PRIORITY_LOWEST = -2,
1300 };
1301 
1302 UV_EXTERN int uv_thread_getpriority(uv_thread_t tid, int* priority);
1303 UV_EXTERN int uv_thread_setpriority(uv_thread_t tid, int priority);
1304 
1305 UV_EXTERN unsigned int uv_available_parallelism(void);
1306 UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1307 UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1308 UV_EXTERN int uv_cpumask_size(void);
1309 
1310 UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
1311                                      int* count);
1312 UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1313                                            int count);
1314 
1315 struct uv_env_item_s {
1316   char* name;
1317   char* value;
1318 };
1319 
1320 UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
1321 UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
1322 UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
1323 UV_EXTERN int uv_os_setenv(const char* name, const char* value);
1324 UV_EXTERN int uv_os_unsetenv(const char* name);
1325 
1326 #ifdef MAXHOSTNAMELEN
1327 # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
1328 #else
1329   /*
1330     Fallback for the maximum hostname size, including the null terminator. The
1331     Windows gethostname() documentation states that 256 bytes will always be
1332     large enough to hold the null-terminated hostname.
1333   */
1334 # define UV_MAXHOSTNAMESIZE 256
1335 #endif
1336 
1337 UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
1338 
1339 UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
1340 
1341 struct uv_metrics_s {
1342   uint64_t loop_count;
1343   uint64_t events;
1344   uint64_t events_waiting;
1345   /* private */
1346   uint64_t* reserved[13];
1347 };
1348 
1349 UV_EXTERN int uv_metrics_info(uv_loop_t* loop, uv_metrics_t* metrics);
1350 UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
1351 
1352 typedef enum {
1353   UV_FS_UNKNOWN = -1,
1354   UV_FS_CUSTOM,
1355   UV_FS_OPEN,
1356   UV_FS_CLOSE,
1357   UV_FS_READ,
1358   UV_FS_WRITE,
1359   UV_FS_SENDFILE,
1360   UV_FS_STAT,
1361   UV_FS_LSTAT,
1362   UV_FS_FSTAT,
1363   UV_FS_FTRUNCATE,
1364   UV_FS_UTIME,
1365   UV_FS_FUTIME,
1366   UV_FS_ACCESS,
1367   UV_FS_CHMOD,
1368   UV_FS_FCHMOD,
1369   UV_FS_FSYNC,
1370   UV_FS_FDATASYNC,
1371   UV_FS_UNLINK,
1372   UV_FS_RMDIR,
1373   UV_FS_MKDIR,
1374   UV_FS_MKDTEMP,
1375   UV_FS_RENAME,
1376   UV_FS_SCANDIR,
1377   UV_FS_LINK,
1378   UV_FS_SYMLINK,
1379   UV_FS_READLINK,
1380   UV_FS_CHOWN,
1381   UV_FS_FCHOWN,
1382   UV_FS_REALPATH,
1383   UV_FS_COPYFILE,
1384   UV_FS_LCHOWN,
1385   UV_FS_OPENDIR,
1386   UV_FS_READDIR,
1387   UV_FS_CLOSEDIR,
1388   UV_FS_STATFS,
1389   UV_FS_MKSTEMP,
1390   UV_FS_LUTIME
1391 } uv_fs_type;
1392 
1393 struct uv_dir_s {
1394   uv_dirent_t* dirents;
1395   size_t nentries;
1396   void* reserved[4];
1397   UV_DIR_PRIVATE_FIELDS
1398 };
1399 
1400 /* uv_fs_t is a subclass of uv_req_t. */
1401 struct uv_fs_s {
1402   UV_REQ_FIELDS
1403   uv_fs_type fs_type;
1404   uv_loop_t* loop;
1405   uv_fs_cb cb;
1406   ssize_t result;
1407   void* ptr;
1408   const char* path;
1409   uv_stat_t statbuf;  /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
1410   UV_FS_PRIVATE_FIELDS
1411 };
1412 
1413 UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
1414 UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
1415 UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
1416 UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
1417 UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
1418 UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
1419 
1420 UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1421 UV_EXTERN int uv_fs_close(uv_loop_t* loop,
1422                           uv_fs_t* req,
1423                           uv_file file,
1424                           uv_fs_cb cb);
1425 UV_EXTERN int uv_fs_open(uv_loop_t* loop,
1426                          uv_fs_t* req,
1427                          const char* path,
1428                          int flags,
1429                          int mode,
1430                          uv_fs_cb cb);
1431 UV_EXTERN int uv_fs_read(uv_loop_t* loop,
1432                          uv_fs_t* req,
1433                          uv_file file,
1434                          const uv_buf_t bufs[],
1435                          unsigned int nbufs,
1436                          int64_t offset,
1437                          uv_fs_cb cb);
1438 UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
1439                            uv_fs_t* req,
1440                            const char* path,
1441                            uv_fs_cb cb);
1442 UV_EXTERN int uv_fs_write(uv_loop_t* loop,
1443                           uv_fs_t* req,
1444                           uv_file file,
1445                           const uv_buf_t bufs[],
1446                           unsigned int nbufs,
1447                           int64_t offset,
1448                           uv_fs_cb cb);
1449 /*
1450  * This flag can be used with uv_fs_copyfile() to return an error if the
1451  * destination already exists.
1452  */
1453 #define UV_FS_COPYFILE_EXCL   0x0001
1454 
1455 /*
1456  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1457  * If copy-on-write is not supported, a fallback copy mechanism is used.
1458  */
1459 #define UV_FS_COPYFILE_FICLONE 0x0002
1460 
1461 /*
1462  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1463  * If copy-on-write is not supported, an error is returned.
1464  */
1465 #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
1466 
1467 UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
1468                              uv_fs_t* req,
1469                              const char* path,
1470                              const char* new_path,
1471                              int flags,
1472                              uv_fs_cb cb);
1473 UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
1474                           uv_fs_t* req,
1475                           const char* path,
1476                           int mode,
1477                           uv_fs_cb cb);
1478 UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
1479                             uv_fs_t* req,
1480                             const char* tpl,
1481                             uv_fs_cb cb);
1482 UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
1483                             uv_fs_t* req,
1484                             const char* tpl,
1485                             uv_fs_cb cb);
1486 UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
1487                           uv_fs_t* req,
1488                           const char* path,
1489                           uv_fs_cb cb);
1490 UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
1491                             uv_fs_t* req,
1492                             const char* path,
1493                             int flags,
1494                             uv_fs_cb cb);
1495 UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
1496                                  uv_dirent_t* ent);
1497 UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
1498                             uv_fs_t* req,
1499                             const char* path,
1500                             uv_fs_cb cb);
1501 UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
1502                             uv_fs_t* req,
1503                             uv_dir_t* dir,
1504                             uv_fs_cb cb);
1505 UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
1506                              uv_fs_t* req,
1507                              uv_dir_t* dir,
1508                              uv_fs_cb cb);
1509 UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
1510                          uv_fs_t* req,
1511                          const char* path,
1512                          uv_fs_cb cb);
1513 UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
1514                           uv_fs_t* req,
1515                           uv_file file,
1516                           uv_fs_cb cb);
1517 UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
1518                            uv_fs_t* req,
1519                            const char* path,
1520                            const char* new_path,
1521                            uv_fs_cb cb);
1522 UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
1523                           uv_fs_t* req,
1524                           uv_file file,
1525                           uv_fs_cb cb);
1526 UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
1527                               uv_fs_t* req,
1528                               uv_file file,
1529                               uv_fs_cb cb);
1530 UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
1531                               uv_fs_t* req,
1532                               uv_file file,
1533                               int64_t offset,
1534                               uv_fs_cb cb);
1535 UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
1536                              uv_fs_t* req,
1537                              uv_file out_fd,
1538                              uv_file in_fd,
1539                              int64_t in_offset,
1540                              size_t length,
1541                              uv_fs_cb cb);
1542 UV_EXTERN int uv_fs_access(uv_loop_t* loop,
1543                            uv_fs_t* req,
1544                            const char* path,
1545                            int mode,
1546                            uv_fs_cb cb);
1547 UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
1548                           uv_fs_t* req,
1549                           const char* path,
1550                           int mode,
1551                           uv_fs_cb cb);
1552 UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
1553                           uv_fs_t* req,
1554                           const char* path,
1555                           double atime,
1556                           double mtime,
1557                           uv_fs_cb cb);
1558 UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
1559                            uv_fs_t* req,
1560                            uv_file file,
1561                            double atime,
1562                            double mtime,
1563                            uv_fs_cb cb);
1564 UV_EXTERN int uv_fs_lutime(uv_loop_t* loop,
1565                            uv_fs_t* req,
1566                            const char* path,
1567                            double atime,
1568                            double mtime,
1569                            uv_fs_cb cb);
1570 UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
1571                           uv_fs_t* req,
1572                           const char* path,
1573                           uv_fs_cb cb);
1574 UV_EXTERN int uv_fs_link(uv_loop_t* loop,
1575                          uv_fs_t* req,
1576                          const char* path,
1577                          const char* new_path,
1578                          uv_fs_cb cb);
1579 
1580 /*
1581  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1582  * path argument points to a directory.
1583  */
1584 #define UV_FS_SYMLINK_DIR          0x0001
1585 
1586 /*
1587  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1588  * the symlink is to be created using junction points.
1589  */
1590 #define UV_FS_SYMLINK_JUNCTION     0x0002
1591 
1592 UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
1593                             uv_fs_t* req,
1594                             const char* path,
1595                             const char* new_path,
1596                             int flags,
1597                             uv_fs_cb cb);
1598 UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
1599                              uv_fs_t* req,
1600                              const char* path,
1601                              uv_fs_cb cb);
1602 UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
1603                              uv_fs_t* req,
1604                              const char* path,
1605                              uv_fs_cb cb);
1606 UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
1607                            uv_fs_t* req,
1608                            uv_file file,
1609                            int mode,
1610                            uv_fs_cb cb);
1611 UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
1612                           uv_fs_t* req,
1613                           const char* path,
1614                           uv_uid_t uid,
1615                           uv_gid_t gid,
1616                           uv_fs_cb cb);
1617 UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
1618                            uv_fs_t* req,
1619                            uv_file file,
1620                            uv_uid_t uid,
1621                            uv_gid_t gid,
1622                            uv_fs_cb cb);
1623 UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
1624                            uv_fs_t* req,
1625                            const char* path,
1626                            uv_uid_t uid,
1627                            uv_gid_t gid,
1628                            uv_fs_cb cb);
1629 UV_EXTERN int uv_fs_statfs(uv_loop_t* loop,
1630                            uv_fs_t* req,
1631                            const char* path,
1632                            uv_fs_cb cb);
1633 
1634 
1635 enum uv_fs_event {
1636   UV_RENAME = 1,
1637   UV_CHANGE = 2
1638 };
1639 
1640 
1641 struct uv_fs_event_s {
1642   UV_HANDLE_FIELDS
1643   /* private */
1644   char* path;
1645   UV_FS_EVENT_PRIVATE_FIELDS
1646 };
1647 
1648 
1649 /*
1650  * uv_fs_stat() based polling file watcher.
1651  */
1652 struct uv_fs_poll_s {
1653   UV_HANDLE_FIELDS
1654   /* Private, don't touch. */
1655   void* poll_ctx;
1656 };
1657 
1658 UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1659 UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1660                                uv_fs_poll_cb poll_cb,
1661                                const char* path,
1662                                unsigned int interval);
1663 UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1664 UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
1665                                  char* buffer,
1666                                  size_t* size);
1667 
1668 
1669 struct uv_signal_s {
1670   UV_HANDLE_FIELDS
1671   uv_signal_cb signal_cb;
1672   int signum;
1673   UV_SIGNAL_PRIVATE_FIELDS
1674 };
1675 
1676 UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
1677 UV_EXTERN int uv_signal_start(uv_signal_t* handle,
1678                               uv_signal_cb signal_cb,
1679                               int signum);
1680 UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
1681                                       uv_signal_cb signal_cb,
1682                                       int signum);
1683 UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
1684 
1685 UV_EXTERN void uv_loadavg(double avg[3]);
1686 
1687 
1688 /*
1689  * Flags to be passed to uv_fs_event_start().
1690  */
1691 enum uv_fs_event_flags {
1692   /*
1693    * By default, if the fs event watcher is given a directory name, we will
1694    * watch for all events in that directory. This flags overrides this behavior
1695    * and makes fs_event report only changes to the directory entry itself. This
1696    * flag does not affect individual files watched.
1697    * This flag is currently not implemented yet on any backend.
1698    */
1699   UV_FS_EVENT_WATCH_ENTRY = 1,
1700 
1701   /*
1702    * By default uv_fs_event will try to use a kernel interface such as inotify
1703    * or kqueue to detect events. This may not work on remote filesystems such
1704    * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1705    * regular interval.
1706    * This flag is currently not implemented yet on any backend.
1707    */
1708   UV_FS_EVENT_STAT = 2,
1709 
1710   /*
1711    * By default, event watcher, when watching directory, is not registering
1712    * (is ignoring) changes in it's subdirectories.
1713    * This flag will override this behaviour on platforms that support it.
1714    */
1715   UV_FS_EVENT_RECURSIVE = 4
1716 };
1717 
1718 
1719 UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
1720 UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
1721                                 uv_fs_event_cb cb,
1722                                 const char* path,
1723                                 unsigned int flags);
1724 UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
1725 UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
1726                                   char* buffer,
1727                                   size_t* size);
1728 
1729 UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
1730 UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
1731 
1732 UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
1733 UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
1734 UV_EXTERN int uv_ip_name(const struct sockaddr* src, char* dst, size_t size);
1735 
1736 UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
1737 UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
1738 
1739 
1740 struct uv_random_s {
1741   UV_REQ_FIELDS
1742   /* read-only */
1743   uv_loop_t* loop;
1744   /* private */
1745   int status;
1746   void* buf;
1747   size_t buflen;
1748   uv_random_cb cb;
1749   struct uv__work work_req;
1750 };
1751 
1752 UV_EXTERN int uv_random(uv_loop_t* loop,
1753                         uv_random_t* req,
1754                         void *buf,
1755                         size_t buflen,
1756                         unsigned flags,  /* For future extension; must be 0. */
1757                         uv_random_cb cb);
1758 
1759 #if defined(IF_NAMESIZE)
1760 # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
1761 #elif defined(IFNAMSIZ)
1762 # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
1763 #else
1764 # define UV_IF_NAMESIZE (16 + 1)
1765 #endif
1766 
1767 UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
1768                                 char* buffer,
1769                                 size_t* size);
1770 UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
1771                                char* buffer,
1772                                size_t* size);
1773 
1774 UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1775 
1776 UV_EXTERN int uv_cwd(char* buffer, size_t* size);
1777 
1778 UV_EXTERN int uv_chdir(const char* dir);
1779 
1780 UV_EXTERN uint64_t uv_get_free_memory(void);
1781 UV_EXTERN uint64_t uv_get_total_memory(void);
1782 UV_EXTERN uint64_t uv_get_constrained_memory(void);
1783 UV_EXTERN uint64_t uv_get_available_memory(void);
1784 
1785 UV_EXTERN int uv_clock_gettime(uv_clock_id clock_id, uv_timespec64_t* ts);
1786 UV_EXTERN uint64_t uv_hrtime(void);
1787 UV_EXTERN void uv_sleep(unsigned int msec);
1788 
1789 UV_EXTERN void uv_disable_stdio_inheritance(void);
1790 
1791 UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1792 UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1793 UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1794 UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
1795 
1796 UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1797 UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
1798 UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1799 UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1800 UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1801 UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1802 
1803 UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1804 UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1805 UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1806 UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1807 UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1808 UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1809 UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1810 UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1811 
1812 UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1813 UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1814 UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1815 UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1816 UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1817 
1818 UV_EXTERN int uv_cond_init(uv_cond_t* cond);
1819 UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
1820 UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
1821 UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
1822 
1823 UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
1824 UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
1825 UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
1826 
1827 UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
1828 UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
1829                                 uv_mutex_t* mutex,
1830                                 uint64_t timeout);
1831 
1832 UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1833 
1834 UV_EXTERN int uv_key_create(uv_key_t* key);
1835 UV_EXTERN void uv_key_delete(uv_key_t* key);
1836 UV_EXTERN void* uv_key_get(uv_key_t* key);
1837 UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
1838 
1839 UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
1840 
1841 typedef void (*uv_thread_cb)(void* arg);
1842 
1843 UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
1844 
1845 typedef enum {
1846   UV_THREAD_NO_FLAGS = 0x00,
1847   UV_THREAD_HAS_STACK_SIZE = 0x01
1848 } uv_thread_create_flags;
1849 
1850 struct uv_thread_options_s {
1851   unsigned int flags;
1852   size_t stack_size;
1853   /* More fields may be added at any time. */
1854 };
1855 
1856 typedef struct uv_thread_options_s uv_thread_options_t;
1857 
1858 UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
1859                                   const uv_thread_options_t* params,
1860                                   uv_thread_cb entry,
1861                                   void* arg);
1862 UV_EXTERN int uv_thread_setaffinity(uv_thread_t* tid,
1863                                     char* cpumask,
1864                                     char* oldmask,
1865                                     size_t mask_size);
1866 UV_EXTERN int uv_thread_getaffinity(uv_thread_t* tid,
1867                                     char* cpumask,
1868                                     size_t mask_size);
1869 UV_EXTERN int uv_thread_getcpu(void);
1870 UV_EXTERN uv_thread_t uv_thread_self(void);
1871 UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1872 UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
1873 
1874 /* The presence of these unions force similar struct layout. */
1875 #define XX(_, name) uv_ ## name ## _t name;
1876 union uv_any_handle {
1877   UV_HANDLE_TYPE_MAP(XX)
1878 };
1879 
1880 union uv_any_req {
1881   UV_REQ_TYPE_MAP(XX)
1882 };
1883 #undef XX
1884 
1885 
1886 struct uv_loop_s {
1887   /* User data - use this for whatever. */
1888   void* data;
1889   /* Loop reference counting. */
1890   unsigned int active_handles;
1891   struct uv__queue handle_queue;
1892   union {
1893     void* unused;
1894     unsigned int count;
1895   } active_reqs;
1896   /* Internal storage for future extensions. */
1897   void* internal_fields;
1898   /* Internal flag to signal loop stop. */
1899   unsigned int stop_flag;
1900   UV_LOOP_PRIVATE_FIELDS
1901 };
1902 
1903 UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
1904 UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
1905 
1906 /* String utilities needed internally for dealing with Windows. */
1907 size_t uv_utf16_length_as_wtf8(const uint16_t* utf16,
1908                                ssize_t utf16_len);
1909 int uv_utf16_to_wtf8(const uint16_t* utf16,
1910                      ssize_t utf16_len,
1911                      char** wtf8_ptr,
1912                      size_t* wtf8_len_ptr);
1913 ssize_t uv_wtf8_length_as_utf16(const char* wtf8);
1914 void uv_wtf8_to_utf16(const char* wtf8,
1915                       uint16_t* utf16,
1916                       size_t utf16_len);
1917 
1918 /* Don't export the private CPP symbols. */
1919 #undef UV_HANDLE_TYPE_PRIVATE
1920 #undef UV_REQ_TYPE_PRIVATE
1921 #undef UV_REQ_PRIVATE_FIELDS
1922 #undef UV_STREAM_PRIVATE_FIELDS
1923 #undef UV_TCP_PRIVATE_FIELDS
1924 #undef UV_PREPARE_PRIVATE_FIELDS
1925 #undef UV_CHECK_PRIVATE_FIELDS
1926 #undef UV_IDLE_PRIVATE_FIELDS
1927 #undef UV_ASYNC_PRIVATE_FIELDS
1928 #undef UV_TIMER_PRIVATE_FIELDS
1929 #undef UV_GETADDRINFO_PRIVATE_FIELDS
1930 #undef UV_GETNAMEINFO_PRIVATE_FIELDS
1931 #undef UV_FS_REQ_PRIVATE_FIELDS
1932 #undef UV_WORK_PRIVATE_FIELDS
1933 #undef UV_FS_EVENT_PRIVATE_FIELDS
1934 #undef UV_SIGNAL_PRIVATE_FIELDS
1935 #undef UV_LOOP_PRIVATE_FIELDS
1936 #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
1937 #undef UV__ERR
1938 
1939 #ifdef __cplusplus
1940 }
1941 #endif
1942 #endif /* UV_H */