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