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