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