747095f1f4047e3ed8ab80938ed56c96cca1c79f
[platform/upstream/cmake.git] / Utilities / cmlibuv / include / uv.h
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21
22 /* See https://github.com/libuv/libuv#documentation for documentation. */
23
24 #ifndef UV_H
25 #define UV_H
26
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
1086 /*
1087  * uv_process_t is a subclass of uv_handle_t.
1088  */
1089 struct uv_process_s {
1090   UV_HANDLE_FIELDS
1091   uv_exit_cb exit_cb;
1092   int pid;
1093   UV_PROCESS_PRIVATE_FIELDS
1094 };
1095
1096 UV_EXTERN int uv_spawn(uv_loop_t* loop,
1097                        uv_process_t* handle,
1098                        const uv_process_options_t* options);
1099 UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
1100 UV_EXTERN int uv_kill(int pid, int signum);
1101 UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
1102
1103
1104 /*
1105  * uv_work_t is a subclass of uv_req_t.
1106  */
1107 struct uv_work_s {
1108   UV_REQ_FIELDS
1109   uv_loop_t* loop;
1110   uv_work_cb work_cb;
1111   uv_after_work_cb after_work_cb;
1112   UV_WORK_PRIVATE_FIELDS
1113 };
1114
1115 UV_EXTERN int uv_queue_work(uv_loop_t* loop,
1116                             uv_work_t* req,
1117                             uv_work_cb work_cb,
1118                             uv_after_work_cb after_work_cb);
1119
1120 UV_EXTERN int uv_cancel(uv_req_t* req);
1121
1122
1123 struct uv_cpu_times_s {
1124   uint64_t user; /* milliseconds */
1125   uint64_t nice; /* milliseconds */
1126   uint64_t sys; /* milliseconds */
1127   uint64_t idle; /* milliseconds */
1128   uint64_t irq; /* milliseconds */
1129 };
1130
1131 struct uv_cpu_info_s {
1132   char* model;
1133   int speed;
1134   struct uv_cpu_times_s cpu_times;
1135 };
1136
1137 struct uv_interface_address_s {
1138   char* name;
1139   char phys_addr[6];
1140   int is_internal;
1141   union {
1142     struct sockaddr_in address4;
1143     struct sockaddr_in6 address6;
1144   } address;
1145   union {
1146     struct sockaddr_in netmask4;
1147     struct sockaddr_in6 netmask6;
1148   } netmask;
1149 };
1150
1151 struct uv_passwd_s {
1152   char* username;
1153   long uid;
1154   long gid;
1155   char* shell;
1156   char* homedir;
1157 };
1158
1159 struct uv_utsname_s {
1160   char sysname[256];
1161   char release[256];
1162   char version[256];
1163   char machine[256];
1164   /* This struct does not contain the nodename and domainname fields present in
1165      the utsname type. domainname is a GNU extension. Both fields are referred
1166      to as meaningless in the docs. */
1167 };
1168
1169 struct uv_statfs_s {
1170   uint64_t f_type;
1171   uint64_t f_bsize;
1172   uint64_t f_blocks;
1173   uint64_t f_bfree;
1174   uint64_t f_bavail;
1175   uint64_t f_files;
1176   uint64_t f_ffree;
1177   uint64_t f_spare[4];
1178 };
1179
1180 typedef enum {
1181   UV_DIRENT_UNKNOWN,
1182   UV_DIRENT_FILE,
1183   UV_DIRENT_DIR,
1184   UV_DIRENT_LINK,
1185   UV_DIRENT_FIFO,
1186   UV_DIRENT_SOCKET,
1187   UV_DIRENT_CHAR,
1188   UV_DIRENT_BLOCK
1189 } uv_dirent_type_t;
1190
1191 struct uv_dirent_s {
1192   const char* name;
1193   uv_dirent_type_t type;
1194 };
1195
1196 UV_EXTERN char** uv_setup_args(int argc, char** argv);
1197 UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
1198 UV_EXTERN int uv_set_process_title(const char* title);
1199 UV_EXTERN int uv_resident_set_memory(size_t* rss);
1200 UV_EXTERN int uv_uptime(double* uptime);
1201 UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
1202 UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
1203
1204 typedef struct {
1205   long tv_sec;
1206   long tv_usec;
1207 } uv_timeval_t;
1208
1209 typedef struct {
1210   int64_t tv_sec;
1211   int32_t tv_usec;
1212 } uv_timeval64_t;
1213
1214 typedef struct {
1215    uv_timeval_t ru_utime; /* user CPU time used */
1216    uv_timeval_t ru_stime; /* system CPU time used */
1217    uint64_t ru_maxrss;    /* maximum resident set size */
1218    uint64_t ru_ixrss;     /* integral shared memory size */
1219    uint64_t ru_idrss;     /* integral unshared data size */
1220    uint64_t ru_isrss;     /* integral unshared stack size */
1221    uint64_t ru_minflt;    /* page reclaims (soft page faults) */
1222    uint64_t ru_majflt;    /* page faults (hard page faults) */
1223    uint64_t ru_nswap;     /* swaps */
1224    uint64_t ru_inblock;   /* block input operations */
1225    uint64_t ru_oublock;   /* block output operations */
1226    uint64_t ru_msgsnd;    /* IPC messages sent */
1227    uint64_t ru_msgrcv;    /* IPC messages received */
1228    uint64_t ru_nsignals;  /* signals received */
1229    uint64_t ru_nvcsw;     /* voluntary context switches */
1230    uint64_t ru_nivcsw;    /* involuntary context switches */
1231 } uv_rusage_t;
1232
1233 UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
1234
1235 UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
1236 UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
1237 UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
1238 UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
1239 UV_EXTERN uv_pid_t uv_os_getpid(void);
1240 UV_EXTERN uv_pid_t uv_os_getppid(void);
1241
1242 #if defined(__PASE__)
1243 /* On IBM i PASE, the highest process priority is -10 */
1244 # define UV_PRIORITY_LOW 39          /* RUNPTY(99) */
1245 # define UV_PRIORITY_BELOW_NORMAL 15 /* RUNPTY(50) */
1246 # define UV_PRIORITY_NORMAL 0        /* RUNPTY(20) */
1247 # define UV_PRIORITY_ABOVE_NORMAL -4 /* RUNTY(12) */
1248 # define UV_PRIORITY_HIGH -7         /* RUNPTY(6) */
1249 # define UV_PRIORITY_HIGHEST -10     /* RUNPTY(1) */
1250 #else
1251 # define UV_PRIORITY_LOW 19
1252 # define UV_PRIORITY_BELOW_NORMAL 10
1253 # define UV_PRIORITY_NORMAL 0
1254 # define UV_PRIORITY_ABOVE_NORMAL -7
1255 # define UV_PRIORITY_HIGH -14
1256 # define UV_PRIORITY_HIGHEST -20
1257 #endif
1258
1259 UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
1260 UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
1261
1262 UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
1263 UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
1264 UV_EXTERN int uv_cpumask_size(void);
1265
1266 UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
1267                                      int* count);
1268 UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
1269                                            int count);
1270
1271 struct uv_env_item_s {
1272   char* name;
1273   char* value;
1274 };
1275
1276 UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
1277 UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
1278 UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
1279 UV_EXTERN int uv_os_setenv(const char* name, const char* value);
1280 UV_EXTERN int uv_os_unsetenv(const char* name);
1281
1282 #ifdef MAXHOSTNAMELEN
1283 # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
1284 #else
1285   /*
1286     Fallback for the maximum hostname size, including the null terminator. The
1287     Windows gethostname() documentation states that 256 bytes will always be
1288     large enough to hold the null-terminated hostname.
1289   */
1290 # define UV_MAXHOSTNAMESIZE 256
1291 #endif
1292
1293 UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
1294
1295 UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
1296
1297 UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
1298
1299 typedef enum {
1300   UV_FS_UNKNOWN = -1,
1301   UV_FS_CUSTOM,
1302   UV_FS_OPEN,
1303   UV_FS_CLOSE,
1304   UV_FS_READ,
1305   UV_FS_WRITE,
1306   UV_FS_SENDFILE,
1307   UV_FS_STAT,
1308   UV_FS_LSTAT,
1309   UV_FS_FSTAT,
1310   UV_FS_FTRUNCATE,
1311   UV_FS_UTIME,
1312   UV_FS_FUTIME,
1313   UV_FS_ACCESS,
1314   UV_FS_CHMOD,
1315   UV_FS_FCHMOD,
1316   UV_FS_FSYNC,
1317   UV_FS_FDATASYNC,
1318   UV_FS_UNLINK,
1319   UV_FS_RMDIR,
1320   UV_FS_MKDIR,
1321   UV_FS_MKDTEMP,
1322   UV_FS_RENAME,
1323   UV_FS_SCANDIR,
1324   UV_FS_LINK,
1325   UV_FS_SYMLINK,
1326   UV_FS_READLINK,
1327   UV_FS_CHOWN,
1328   UV_FS_FCHOWN,
1329   UV_FS_REALPATH,
1330   UV_FS_COPYFILE,
1331   UV_FS_LCHOWN,
1332   UV_FS_OPENDIR,
1333   UV_FS_READDIR,
1334   UV_FS_CLOSEDIR,
1335   UV_FS_STATFS,
1336   UV_FS_MKSTEMP,
1337   UV_FS_LUTIME
1338 } uv_fs_type;
1339
1340 struct uv_dir_s {
1341   uv_dirent_t* dirents;
1342   size_t nentries;
1343   void* reserved[4];
1344   UV_DIR_PRIVATE_FIELDS
1345 };
1346
1347 /* uv_fs_t is a subclass of uv_req_t. */
1348 struct uv_fs_s {
1349   UV_REQ_FIELDS
1350   uv_fs_type fs_type;
1351   uv_loop_t* loop;
1352   uv_fs_cb cb;
1353   ssize_t result;
1354   void* ptr;
1355   const char* path;
1356   uv_stat_t statbuf;  /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
1357   UV_FS_PRIVATE_FIELDS
1358 };
1359
1360 UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
1361 UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
1362 UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
1363 UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
1364 UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
1365 UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
1366
1367 UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
1368 UV_EXTERN int uv_fs_close(uv_loop_t* loop,
1369                           uv_fs_t* req,
1370                           uv_file file,
1371                           uv_fs_cb cb);
1372 UV_EXTERN int uv_fs_open(uv_loop_t* loop,
1373                          uv_fs_t* req,
1374                          const char* path,
1375                          int flags,
1376                          int mode,
1377                          uv_fs_cb cb);
1378 UV_EXTERN int uv_fs_read(uv_loop_t* loop,
1379                          uv_fs_t* req,
1380                          uv_file file,
1381                          const uv_buf_t bufs[],
1382                          unsigned int nbufs,
1383                          int64_t offset,
1384                          uv_fs_cb cb);
1385 UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
1386                            uv_fs_t* req,
1387                            const char* path,
1388                            uv_fs_cb cb);
1389 UV_EXTERN int uv_fs_write(uv_loop_t* loop,
1390                           uv_fs_t* req,
1391                           uv_file file,
1392                           const uv_buf_t bufs[],
1393                           unsigned int nbufs,
1394                           int64_t offset,
1395                           uv_fs_cb cb);
1396 /*
1397  * This flag can be used with uv_fs_copyfile() to return an error if the
1398  * destination already exists.
1399  */
1400 #define UV_FS_COPYFILE_EXCL   0x0001
1401
1402 /*
1403  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1404  * If copy-on-write is not supported, a fallback copy mechanism is used.
1405  */
1406 #define UV_FS_COPYFILE_FICLONE 0x0002
1407
1408 /*
1409  * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
1410  * If copy-on-write is not supported, an error is returned.
1411  */
1412 #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
1413
1414 UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
1415                              uv_fs_t* req,
1416                              const char* path,
1417                              const char* new_path,
1418                              int flags,
1419                              uv_fs_cb cb);
1420 UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
1421                           uv_fs_t* req,
1422                           const char* path,
1423                           int mode,
1424                           uv_fs_cb cb);
1425 UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
1426                             uv_fs_t* req,
1427                             const char* tpl,
1428                             uv_fs_cb cb);
1429 UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
1430                             uv_fs_t* req,
1431                             const char* tpl,
1432                             uv_fs_cb cb);
1433 UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
1434                           uv_fs_t* req,
1435                           const char* path,
1436                           uv_fs_cb cb);
1437 UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
1438                             uv_fs_t* req,
1439                             const char* path,
1440                             int flags,
1441                             uv_fs_cb cb);
1442 UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
1443                                  uv_dirent_t* ent);
1444 UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
1445                             uv_fs_t* req,
1446                             const char* path,
1447                             uv_fs_cb cb);
1448 UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
1449                             uv_fs_t* req,
1450                             uv_dir_t* dir,
1451                             uv_fs_cb cb);
1452 UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
1453                              uv_fs_t* req,
1454                              uv_dir_t* dir,
1455                              uv_fs_cb cb);
1456 UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
1457                          uv_fs_t* req,
1458                          const char* path,
1459                          uv_fs_cb cb);
1460 UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
1461                           uv_fs_t* req,
1462                           uv_file file,
1463                           uv_fs_cb cb);
1464 UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
1465                            uv_fs_t* req,
1466                            const char* path,
1467                            const char* new_path,
1468                            uv_fs_cb cb);
1469 UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
1470                           uv_fs_t* req,
1471                           uv_file file,
1472                           uv_fs_cb cb);
1473 UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
1474                               uv_fs_t* req,
1475                               uv_file file,
1476                               uv_fs_cb cb);
1477 UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
1478                               uv_fs_t* req,
1479                               uv_file file,
1480                               int64_t offset,
1481                               uv_fs_cb cb);
1482 UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
1483                              uv_fs_t* req,
1484                              uv_file out_fd,
1485                              uv_file in_fd,
1486                              int64_t in_offset,
1487                              size_t length,
1488                              uv_fs_cb cb);
1489 UV_EXTERN int uv_fs_access(uv_loop_t* loop,
1490                            uv_fs_t* req,
1491                            const char* path,
1492                            int mode,
1493                            uv_fs_cb cb);
1494 UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
1495                           uv_fs_t* req,
1496                           const char* path,
1497                           int mode,
1498                           uv_fs_cb cb);
1499 UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
1500                           uv_fs_t* req,
1501                           const char* path,
1502                           double atime,
1503                           double mtime,
1504                           uv_fs_cb cb);
1505 UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
1506                            uv_fs_t* req,
1507                            uv_file file,
1508                            double atime,
1509                            double mtime,
1510                            uv_fs_cb cb);
1511 UV_EXTERN int uv_fs_lutime(uv_loop_t* loop,
1512                            uv_fs_t* req,
1513                            const char* path,
1514                            double atime,
1515                            double mtime,
1516                            uv_fs_cb cb);
1517 UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
1518                           uv_fs_t* req,
1519                           const char* path,
1520                           uv_fs_cb cb);
1521 UV_EXTERN int uv_fs_link(uv_loop_t* loop,
1522                          uv_fs_t* req,
1523                          const char* path,
1524                          const char* new_path,
1525                          uv_fs_cb cb);
1526
1527 /*
1528  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1529  * path argument points to a directory.
1530  */
1531 #define UV_FS_SYMLINK_DIR          0x0001
1532
1533 /*
1534  * This flag can be used with uv_fs_symlink() on Windows to specify whether
1535  * the symlink is to be created using junction points.
1536  */
1537 #define UV_FS_SYMLINK_JUNCTION     0x0002
1538
1539 UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
1540                             uv_fs_t* req,
1541                             const char* path,
1542                             const char* new_path,
1543                             int flags,
1544                             uv_fs_cb cb);
1545 UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
1546                              uv_fs_t* req,
1547                              const char* path,
1548                              uv_fs_cb cb);
1549 UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
1550                              uv_fs_t* req,
1551                              const char* path,
1552                              uv_fs_cb cb);
1553 UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
1554                            uv_fs_t* req,
1555                            uv_file file,
1556                            int mode,
1557                            uv_fs_cb cb);
1558 UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
1559                           uv_fs_t* req,
1560                           const char* path,
1561                           uv_uid_t uid,
1562                           uv_gid_t gid,
1563                           uv_fs_cb cb);
1564 UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
1565                            uv_fs_t* req,
1566                            uv_file file,
1567                            uv_uid_t uid,
1568                            uv_gid_t gid,
1569                            uv_fs_cb cb);
1570 UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
1571                            uv_fs_t* req,
1572                            const char* path,
1573                            uv_uid_t uid,
1574                            uv_gid_t gid,
1575                            uv_fs_cb cb);
1576 UV_EXTERN int uv_fs_statfs(uv_loop_t* loop,
1577                            uv_fs_t* req,
1578                            const char* path,
1579                            uv_fs_cb cb);
1580
1581
1582 enum uv_fs_event {
1583   UV_RENAME = 1,
1584   UV_CHANGE = 2
1585 };
1586
1587
1588 struct uv_fs_event_s {
1589   UV_HANDLE_FIELDS
1590   /* private */
1591   char* path;
1592   UV_FS_EVENT_PRIVATE_FIELDS
1593 };
1594
1595
1596 /*
1597  * uv_fs_stat() based polling file watcher.
1598  */
1599 struct uv_fs_poll_s {
1600   UV_HANDLE_FIELDS
1601   /* Private, don't touch. */
1602   void* poll_ctx;
1603 };
1604
1605 UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
1606 UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
1607                                uv_fs_poll_cb poll_cb,
1608                                const char* path,
1609                                unsigned int interval);
1610 UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
1611 UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
1612                                  char* buffer,
1613                                  size_t* size);
1614
1615
1616 struct uv_signal_s {
1617   UV_HANDLE_FIELDS
1618   uv_signal_cb signal_cb;
1619   int signum;
1620   UV_SIGNAL_PRIVATE_FIELDS
1621 };
1622
1623 UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
1624 UV_EXTERN int uv_signal_start(uv_signal_t* handle,
1625                               uv_signal_cb signal_cb,
1626                               int signum);
1627 UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
1628                                       uv_signal_cb signal_cb,
1629                                       int signum);
1630 UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
1631
1632 UV_EXTERN void uv_loadavg(double avg[3]);
1633
1634
1635 /*
1636  * Flags to be passed to uv_fs_event_start().
1637  */
1638 enum uv_fs_event_flags {
1639   /*
1640    * By default, if the fs event watcher is given a directory name, we will
1641    * watch for all events in that directory. This flags overrides this behavior
1642    * and makes fs_event report only changes to the directory entry itself. This
1643    * flag does not affect individual files watched.
1644    * This flag is currently not implemented yet on any backend.
1645    */
1646   UV_FS_EVENT_WATCH_ENTRY = 1,
1647
1648   /*
1649    * By default uv_fs_event will try to use a kernel interface such as inotify
1650    * or kqueue to detect events. This may not work on remote filesystems such
1651    * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
1652    * regular interval.
1653    * This flag is currently not implemented yet on any backend.
1654    */
1655   UV_FS_EVENT_STAT = 2,
1656
1657   /*
1658    * By default, event watcher, when watching directory, is not registering
1659    * (is ignoring) changes in it's subdirectories.
1660    * This flag will override this behaviour on platforms that support it.
1661    */
1662   UV_FS_EVENT_RECURSIVE = 4
1663 };
1664
1665
1666 UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
1667 UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
1668                                 uv_fs_event_cb cb,
1669                                 const char* path,
1670                                 unsigned int flags);
1671 UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
1672 UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
1673                                   char* buffer,
1674                                   size_t* size);
1675
1676 UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
1677 UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
1678
1679 UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
1680 UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
1681 UV_EXTERN int uv_ip_name(const struct sockaddr* src, char* dst, size_t size);
1682
1683 UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
1684 UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
1685
1686
1687 struct uv_random_s {
1688   UV_REQ_FIELDS
1689   /* read-only */
1690   uv_loop_t* loop;
1691   /* private */
1692   int status;
1693   void* buf;
1694   size_t buflen;
1695   uv_random_cb cb;
1696   struct uv__work work_req;
1697 };
1698
1699 UV_EXTERN int uv_random(uv_loop_t* loop,
1700                         uv_random_t* req,
1701                         void *buf,
1702                         size_t buflen,
1703                         unsigned flags,  /* For future extension; must be 0. */
1704                         uv_random_cb cb);
1705
1706 #if defined(IF_NAMESIZE)
1707 # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
1708 #elif defined(IFNAMSIZ)
1709 # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
1710 #else
1711 # define UV_IF_NAMESIZE (16 + 1)
1712 #endif
1713
1714 UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
1715                                 char* buffer,
1716                                 size_t* size);
1717 UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
1718                                char* buffer,
1719                                size_t* size);
1720
1721 UV_EXTERN int uv_exepath(char* buffer, size_t* size);
1722
1723 UV_EXTERN int uv_cwd(char* buffer, size_t* size);
1724
1725 UV_EXTERN int uv_chdir(const char* dir);
1726
1727 UV_EXTERN uint64_t uv_get_free_memory(void);
1728 UV_EXTERN uint64_t uv_get_total_memory(void);
1729 UV_EXTERN uint64_t uv_get_constrained_memory(void);
1730
1731 UV_EXTERN uint64_t uv_hrtime(void);
1732 UV_EXTERN void uv_sleep(unsigned int msec);
1733
1734 UV_EXTERN void uv_disable_stdio_inheritance(void);
1735
1736 UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
1737 UV_EXTERN void uv_dlclose(uv_lib_t* lib);
1738 UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
1739 UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
1740
1741 UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
1742 UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
1743 UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
1744 UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
1745 UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
1746 UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
1747
1748 UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
1749 UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
1750 UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
1751 UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
1752 UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
1753 UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
1754 UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
1755 UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
1756
1757 UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
1758 UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
1759 UV_EXTERN void uv_sem_post(uv_sem_t* sem);
1760 UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
1761 UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
1762
1763 UV_EXTERN int uv_cond_init(uv_cond_t* cond);
1764 UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
1765 UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
1766 UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
1767
1768 UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
1769 UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
1770 UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
1771
1772 UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
1773 UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
1774                                 uv_mutex_t* mutex,
1775                                 uint64_t timeout);
1776
1777 UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
1778
1779 UV_EXTERN int uv_key_create(uv_key_t* key);
1780 UV_EXTERN void uv_key_delete(uv_key_t* key);
1781 UV_EXTERN void* uv_key_get(uv_key_t* key);
1782 UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
1783
1784 UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
1785
1786 typedef void (*uv_thread_cb)(void* arg);
1787
1788 UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
1789
1790 typedef enum {
1791   UV_THREAD_NO_FLAGS = 0x00,
1792   UV_THREAD_HAS_STACK_SIZE = 0x01
1793 } uv_thread_create_flags;
1794
1795 struct uv_thread_options_s {
1796   unsigned int flags;
1797   size_t stack_size;
1798   /* More fields may be added at any time. */
1799 };
1800
1801 typedef struct uv_thread_options_s uv_thread_options_t;
1802
1803 UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
1804                                   const uv_thread_options_t* params,
1805                                   uv_thread_cb entry,
1806                                   void* arg);
1807 UV_EXTERN uv_thread_t uv_thread_self(void);
1808 UV_EXTERN int uv_thread_join(uv_thread_t *tid);
1809 UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
1810
1811 /* The presence of these unions force similar struct layout. */
1812 #define XX(_, name) uv_ ## name ## _t name;
1813 union uv_any_handle {
1814   UV_HANDLE_TYPE_MAP(XX)
1815 };
1816
1817 union uv_any_req {
1818   UV_REQ_TYPE_MAP(XX)
1819 };
1820 #undef XX
1821
1822
1823 struct uv_loop_s {
1824   /* User data - use this for whatever. */
1825   void* data;
1826   /* Loop reference counting. */
1827   unsigned int active_handles;
1828   void* handle_queue[2];
1829   union {
1830     void* unused;
1831     unsigned int count;
1832   } active_reqs;
1833   /* Internal storage for future extensions. */
1834   void* internal_fields;
1835   /* Internal flag to signal loop stop. */
1836   unsigned int stop_flag;
1837   UV_LOOP_PRIVATE_FIELDS
1838 };
1839
1840 UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
1841 UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
1842
1843 /* Don't export the private CPP symbols. */
1844 #undef UV_HANDLE_TYPE_PRIVATE
1845 #undef UV_REQ_TYPE_PRIVATE
1846 #undef UV_REQ_PRIVATE_FIELDS
1847 #undef UV_STREAM_PRIVATE_FIELDS
1848 #undef UV_TCP_PRIVATE_FIELDS
1849 #undef UV_PREPARE_PRIVATE_FIELDS
1850 #undef UV_CHECK_PRIVATE_FIELDS
1851 #undef UV_IDLE_PRIVATE_FIELDS
1852 #undef UV_ASYNC_PRIVATE_FIELDS
1853 #undef UV_TIMER_PRIVATE_FIELDS
1854 #undef UV_GETADDRINFO_PRIVATE_FIELDS
1855 #undef UV_GETNAMEINFO_PRIVATE_FIELDS
1856 #undef UV_FS_REQ_PRIVATE_FIELDS
1857 #undef UV_WORK_PRIVATE_FIELDS
1858 #undef UV_FS_EVENT_PRIVATE_FIELDS
1859 #undef UV_SIGNAL_PRIVATE_FIELDS
1860 #undef UV_LOOP_PRIVATE_FIELDS
1861 #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
1862 #undef UV__ERR
1863
1864 #ifdef __cplusplus
1865 }
1866 #endif
1867 #endif /* UV_H */