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