libuv (1.47.0)

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