Coverage Report

Created: 2026-10-28 06:38

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