PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/deps/uv/include/uv.h

https://gitlab.com/GeekSir/node
C Header | 1455 lines | 1033 code | 191 blank | 231 comment | 2 complexity | 56c97c43bac95204de63c9286d6ce5e1 MD5 | raw file
Possible License(s): 0BSD, Apache-2.0, MPL-2.0-no-copyleft-exception, JSON, WTFPL, CC-BY-SA-3.0, Unlicense, ISC, BSD-3-Clause, MIT, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  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. /* See https://github.com/libuv/libuv#documentation for documentation. */
  22. #ifndef UV_H
  23. #define UV_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifdef _WIN32
  28. /* Windows - set up dll import/export decorators. */
  29. # if defined(BUILDING_UV_SHARED)
  30. /* Building shared library. */
  31. # define UV_EXTERN __declspec(dllexport)
  32. # elif defined(USING_UV_SHARED)
  33. /* Using shared library. */
  34. # define UV_EXTERN __declspec(dllimport)
  35. # else
  36. /* Building static library. */
  37. # define UV_EXTERN /* nothing */
  38. # endif
  39. #elif __GNUC__ >= 4
  40. # define UV_EXTERN __attribute__((visibility("default")))
  41. #else
  42. # define UV_EXTERN /* nothing */
  43. #endif
  44. #include "uv-errno.h"
  45. #include "uv-version.h"
  46. #include <stddef.h>
  47. #if defined(_MSC_VER) && _MSC_VER < 1600
  48. # include "stdint-msvc2008.h"
  49. #else
  50. # include <stdint.h>
  51. #endif
  52. #if defined(_WIN32)
  53. # include "uv-win.h"
  54. #else
  55. # include "uv-unix.h"
  56. #endif
  57. /* Expand this list if necessary. */
  58. #define UV_ERRNO_MAP(XX) \
  59. XX(E2BIG, "argument list too long") \
  60. XX(EACCES, "permission denied") \
  61. XX(EADDRINUSE, "address already in use") \
  62. XX(EADDRNOTAVAIL, "address not available") \
  63. XX(EAFNOSUPPORT, "address family not supported") \
  64. XX(EAGAIN, "resource temporarily unavailable") \
  65. XX(EAI_ADDRFAMILY, "address family not supported") \
  66. XX(EAI_AGAIN, "temporary failure") \
  67. XX(EAI_BADFLAGS, "bad ai_flags value") \
  68. XX(EAI_BADHINTS, "invalid value for hints") \
  69. XX(EAI_CANCELED, "request canceled") \
  70. XX(EAI_FAIL, "permanent failure") \
  71. XX(EAI_FAMILY, "ai_family not supported") \
  72. XX(EAI_MEMORY, "out of memory") \
  73. XX(EAI_NODATA, "no address") \
  74. XX(EAI_NONAME, "unknown node or service") \
  75. XX(EAI_OVERFLOW, "argument buffer overflow") \
  76. XX(EAI_PROTOCOL, "resolved protocol is unknown") \
  77. XX(EAI_SERVICE, "service not available for socket type") \
  78. XX(EAI_SOCKTYPE, "socket type not supported") \
  79. XX(EALREADY, "connection already in progress") \
  80. XX(EBADF, "bad file descriptor") \
  81. XX(EBUSY, "resource busy or locked") \
  82. XX(ECANCELED, "operation canceled") \
  83. XX(ECHARSET, "invalid Unicode character") \
  84. XX(ECONNABORTED, "software caused connection abort") \
  85. XX(ECONNREFUSED, "connection refused") \
  86. XX(ECONNRESET, "connection reset by peer") \
  87. XX(EDESTADDRREQ, "destination address required") \
  88. XX(EEXIST, "file already exists") \
  89. XX(EFAULT, "bad address in system call argument") \
  90. XX(EFBIG, "file too large") \
  91. XX(EHOSTUNREACH, "host is unreachable") \
  92. XX(EINTR, "interrupted system call") \
  93. XX(EINVAL, "invalid argument") \
  94. XX(EIO, "i/o error") \
  95. XX(EISCONN, "socket is already connected") \
  96. XX(EISDIR, "illegal operation on a directory") \
  97. XX(ELOOP, "too many symbolic links encountered") \
  98. XX(EMFILE, "too many open files") \
  99. XX(EMSGSIZE, "message too long") \
  100. XX(ENAMETOOLONG, "name too long") \
  101. XX(ENETDOWN, "network is down") \
  102. XX(ENETUNREACH, "network is unreachable") \
  103. XX(ENFILE, "file table overflow") \
  104. XX(ENOBUFS, "no buffer space available") \
  105. XX(ENODEV, "no such device") \
  106. XX(ENOENT, "no such file or directory") \
  107. XX(ENOMEM, "not enough memory") \
  108. XX(ENONET, "machine is not on the network") \
  109. XX(ENOPROTOOPT, "protocol not available") \
  110. XX(ENOSPC, "no space left on device") \
  111. XX(ENOSYS, "function not implemented") \
  112. XX(ENOTCONN, "socket is not connected") \
  113. XX(ENOTDIR, "not a directory") \
  114. XX(ENOTEMPTY, "directory not empty") \
  115. XX(ENOTSOCK, "socket operation on non-socket") \
  116. XX(ENOTSUP, "operation not supported on socket") \
  117. XX(EPERM, "operation not permitted") \
  118. XX(EPIPE, "broken pipe") \
  119. XX(EPROTO, "protocol error") \
  120. XX(EPROTONOSUPPORT, "protocol not supported") \
  121. XX(EPROTOTYPE, "protocol wrong type for socket") \
  122. XX(ERANGE, "result too large") \
  123. XX(EROFS, "read-only file system") \
  124. XX(ESHUTDOWN, "cannot send after transport endpoint shutdown") \
  125. XX(ESPIPE, "invalid seek") \
  126. XX(ESRCH, "no such process") \
  127. XX(ETIMEDOUT, "connection timed out") \
  128. XX(ETXTBSY, "text file is busy") \
  129. XX(EXDEV, "cross-device link not permitted") \
  130. XX(UNKNOWN, "unknown error") \
  131. XX(EOF, "end of file") \
  132. XX(ENXIO, "no such device or address") \
  133. XX(EMLINK, "too many links") \
  134. XX(EHOSTDOWN, "host is down") \
  135. #define UV_HANDLE_TYPE_MAP(XX) \
  136. XX(ASYNC, async) \
  137. XX(CHECK, check) \
  138. XX(FS_EVENT, fs_event) \
  139. XX(FS_POLL, fs_poll) \
  140. XX(HANDLE, handle) \
  141. XX(IDLE, idle) \
  142. XX(NAMED_PIPE, pipe) \
  143. XX(POLL, poll) \
  144. XX(PREPARE, prepare) \
  145. XX(PROCESS, process) \
  146. XX(STREAM, stream) \
  147. XX(TCP, tcp) \
  148. XX(TIMER, timer) \
  149. XX(TTY, tty) \
  150. XX(UDP, udp) \
  151. XX(SIGNAL, signal) \
  152. #define UV_REQ_TYPE_MAP(XX) \
  153. XX(REQ, req) \
  154. XX(CONNECT, connect) \
  155. XX(WRITE, write) \
  156. XX(SHUTDOWN, shutdown) \
  157. XX(UDP_SEND, udp_send) \
  158. XX(FS, fs) \
  159. XX(WORK, work) \
  160. XX(GETADDRINFO, getaddrinfo) \
  161. XX(GETNAMEINFO, getnameinfo) \
  162. typedef enum {
  163. #define XX(code, _) UV_ ## code = UV__ ## code,
  164. UV_ERRNO_MAP(XX)
  165. #undef XX
  166. UV_ERRNO_MAX = UV__EOF - 1
  167. } uv_errno_t;
  168. typedef enum {
  169. UV_UNKNOWN_HANDLE = 0,
  170. #define XX(uc, lc) UV_##uc,
  171. UV_HANDLE_TYPE_MAP(XX)
  172. #undef XX
  173. UV_FILE,
  174. UV_HANDLE_TYPE_MAX
  175. } uv_handle_type;
  176. typedef enum {
  177. UV_UNKNOWN_REQ = 0,
  178. #define XX(uc, lc) UV_##uc,
  179. UV_REQ_TYPE_MAP(XX)
  180. #undef XX
  181. UV_REQ_TYPE_PRIVATE
  182. UV_REQ_TYPE_MAX
  183. } uv_req_type;
  184. /* Handle types. */
  185. typedef struct uv_loop_s uv_loop_t;
  186. typedef struct uv_handle_s uv_handle_t;
  187. typedef struct uv_stream_s uv_stream_t;
  188. typedef struct uv_tcp_s uv_tcp_t;
  189. typedef struct uv_udp_s uv_udp_t;
  190. typedef struct uv_pipe_s uv_pipe_t;
  191. typedef struct uv_tty_s uv_tty_t;
  192. typedef struct uv_poll_s uv_poll_t;
  193. typedef struct uv_timer_s uv_timer_t;
  194. typedef struct uv_prepare_s uv_prepare_t;
  195. typedef struct uv_check_s uv_check_t;
  196. typedef struct uv_idle_s uv_idle_t;
  197. typedef struct uv_async_s uv_async_t;
  198. typedef struct uv_process_s uv_process_t;
  199. typedef struct uv_fs_event_s uv_fs_event_t;
  200. typedef struct uv_fs_poll_s uv_fs_poll_t;
  201. typedef struct uv_signal_s uv_signal_t;
  202. /* Request types. */
  203. typedef struct uv_req_s uv_req_t;
  204. typedef struct uv_getaddrinfo_s uv_getaddrinfo_t;
  205. typedef struct uv_getnameinfo_s uv_getnameinfo_t;
  206. typedef struct uv_shutdown_s uv_shutdown_t;
  207. typedef struct uv_write_s uv_write_t;
  208. typedef struct uv_connect_s uv_connect_t;
  209. typedef struct uv_udp_send_s uv_udp_send_t;
  210. typedef struct uv_fs_s uv_fs_t;
  211. typedef struct uv_work_s uv_work_t;
  212. /* None of the above. */
  213. typedef struct uv_cpu_info_s uv_cpu_info_t;
  214. typedef struct uv_interface_address_s uv_interface_address_t;
  215. typedef struct uv_dirent_s uv_dirent_t;
  216. typedef enum {
  217. UV_LOOP_BLOCK_SIGNAL
  218. } uv_loop_option;
  219. typedef enum {
  220. UV_RUN_DEFAULT = 0,
  221. UV_RUN_ONCE,
  222. UV_RUN_NOWAIT
  223. } uv_run_mode;
  224. UV_EXTERN unsigned int uv_version(void);
  225. UV_EXTERN const char* uv_version_string(void);
  226. UV_EXTERN uv_loop_t* uv_default_loop(void);
  227. UV_EXTERN int uv_loop_init(uv_loop_t* loop);
  228. UV_EXTERN int uv_loop_close(uv_loop_t* loop);
  229. /*
  230. * NOTE:
  231. * This function is DEPRECATED (to be removed after 0.12), users should
  232. * allocate the loop manually and use uv_loop_init instead.
  233. */
  234. UV_EXTERN uv_loop_t* uv_loop_new(void);
  235. /*
  236. * NOTE:
  237. * This function is DEPRECATED (to be removed after 0.12). Users should use
  238. * uv_loop_close and free the memory manually instead.
  239. */
  240. UV_EXTERN void uv_loop_delete(uv_loop_t*);
  241. UV_EXTERN size_t uv_loop_size(void);
  242. UV_EXTERN int uv_loop_alive(const uv_loop_t* loop);
  243. UV_EXTERN int uv_loop_configure(uv_loop_t* loop, uv_loop_option option, ...);
  244. UV_EXTERN int uv_run(uv_loop_t*, uv_run_mode mode);
  245. UV_EXTERN void uv_stop(uv_loop_t*);
  246. UV_EXTERN void uv_ref(uv_handle_t*);
  247. UV_EXTERN void uv_unref(uv_handle_t*);
  248. UV_EXTERN int uv_has_ref(const uv_handle_t*);
  249. UV_EXTERN void uv_update_time(uv_loop_t*);
  250. UV_EXTERN uint64_t uv_now(const uv_loop_t*);
  251. UV_EXTERN int uv_backend_fd(const uv_loop_t*);
  252. UV_EXTERN int uv_backend_timeout(const uv_loop_t*);
  253. typedef void (*uv_alloc_cb)(uv_handle_t* handle,
  254. size_t suggested_size,
  255. uv_buf_t* buf);
  256. typedef void (*uv_read_cb)(uv_stream_t* stream,
  257. ssize_t nread,
  258. const uv_buf_t* buf);
  259. typedef void (*uv_write_cb)(uv_write_t* req, int status);
  260. typedef void (*uv_connect_cb)(uv_connect_t* req, int status);
  261. typedef void (*uv_shutdown_cb)(uv_shutdown_t* req, int status);
  262. typedef void (*uv_connection_cb)(uv_stream_t* server, int status);
  263. typedef void (*uv_close_cb)(uv_handle_t* handle);
  264. typedef void (*uv_poll_cb)(uv_poll_t* handle, int status, int events);
  265. typedef void (*uv_timer_cb)(uv_timer_t* handle);
  266. typedef void (*uv_async_cb)(uv_async_t* handle);
  267. typedef void (*uv_prepare_cb)(uv_prepare_t* handle);
  268. typedef void (*uv_check_cb)(uv_check_t* handle);
  269. typedef void (*uv_idle_cb)(uv_idle_t* handle);
  270. typedef void (*uv_exit_cb)(uv_process_t*, int64_t exit_status, int term_signal);
  271. typedef void (*uv_walk_cb)(uv_handle_t* handle, void* arg);
  272. typedef void (*uv_fs_cb)(uv_fs_t* req);
  273. typedef void (*uv_work_cb)(uv_work_t* req);
  274. typedef void (*uv_after_work_cb)(uv_work_t* req, int status);
  275. typedef void (*uv_getaddrinfo_cb)(uv_getaddrinfo_t* req,
  276. int status,
  277. struct addrinfo* res);
  278. typedef void (*uv_getnameinfo_cb)(uv_getnameinfo_t* req,
  279. int status,
  280. const char* hostname,
  281. const char* service);
  282. typedef struct {
  283. long tv_sec;
  284. long tv_nsec;
  285. } uv_timespec_t;
  286. typedef struct {
  287. uint64_t st_dev;
  288. uint64_t st_mode;
  289. uint64_t st_nlink;
  290. uint64_t st_uid;
  291. uint64_t st_gid;
  292. uint64_t st_rdev;
  293. uint64_t st_ino;
  294. uint64_t st_size;
  295. uint64_t st_blksize;
  296. uint64_t st_blocks;
  297. uint64_t st_flags;
  298. uint64_t st_gen;
  299. uv_timespec_t st_atim;
  300. uv_timespec_t st_mtim;
  301. uv_timespec_t st_ctim;
  302. uv_timespec_t st_birthtim;
  303. } uv_stat_t;
  304. typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle,
  305. const char* filename,
  306. int events,
  307. int status);
  308. typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
  309. int status,
  310. const uv_stat_t* prev,
  311. const uv_stat_t* curr);
  312. typedef void (*uv_signal_cb)(uv_signal_t* handle, int signum);
  313. typedef enum {
  314. UV_LEAVE_GROUP = 0,
  315. UV_JOIN_GROUP
  316. } uv_membership;
  317. UV_EXTERN const char* uv_strerror(int err);
  318. UV_EXTERN const char* uv_err_name(int err);
  319. #define UV_REQ_FIELDS \
  320. /* public */ \
  321. void* data; \
  322. /* read-only */ \
  323. uv_req_type type; \
  324. /* private */ \
  325. void* active_queue[2]; \
  326. void* reserved[4]; \
  327. UV_REQ_PRIVATE_FIELDS \
  328. /* Abstract base class of all requests. */
  329. struct uv_req_s {
  330. UV_REQ_FIELDS
  331. };
  332. /* Platform-specific request types. */
  333. UV_PRIVATE_REQ_TYPES
  334. UV_EXTERN int uv_shutdown(uv_shutdown_t* req,
  335. uv_stream_t* handle,
  336. uv_shutdown_cb cb);
  337. struct uv_shutdown_s {
  338. UV_REQ_FIELDS
  339. uv_stream_t* handle;
  340. uv_shutdown_cb cb;
  341. UV_SHUTDOWN_PRIVATE_FIELDS
  342. };
  343. #define UV_HANDLE_FIELDS \
  344. /* public */ \
  345. void* data; \
  346. /* read-only */ \
  347. uv_loop_t* loop; \
  348. uv_handle_type type; \
  349. /* private */ \
  350. uv_close_cb close_cb; \
  351. void* handle_queue[2]; \
  352. void* reserved[4]; \
  353. UV_HANDLE_PRIVATE_FIELDS \
  354. /* The abstract base class of all handles. */
  355. struct uv_handle_s {
  356. UV_HANDLE_FIELDS
  357. };
  358. UV_EXTERN size_t uv_handle_size(uv_handle_type type);
  359. UV_EXTERN size_t uv_req_size(uv_req_type type);
  360. UV_EXTERN int uv_is_active(const uv_handle_t* handle);
  361. UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
  362. UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
  363. UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value);
  364. UV_EXTERN int uv_recv_buffer_size(uv_handle_t* handle, int* value);
  365. UV_EXTERN int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd);
  366. UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
  367. #define UV_STREAM_FIELDS \
  368. /* number of bytes queued for writing */ \
  369. size_t write_queue_size; \
  370. uv_alloc_cb alloc_cb; \
  371. uv_read_cb read_cb; \
  372. /* private */ \
  373. UV_STREAM_PRIVATE_FIELDS
  374. /*
  375. * uv_stream_t is a subclass of uv_handle_t.
  376. *
  377. * uv_stream is an abstract class.
  378. *
  379. * uv_stream_t is the parent class of uv_tcp_t, uv_pipe_t and uv_tty_t.
  380. */
  381. struct uv_stream_s {
  382. UV_HANDLE_FIELDS
  383. UV_STREAM_FIELDS
  384. };
  385. UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
  386. UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
  387. UV_EXTERN int uv_read_start(uv_stream_t*,
  388. uv_alloc_cb alloc_cb,
  389. uv_read_cb read_cb);
  390. UV_EXTERN int uv_read_stop(uv_stream_t*);
  391. UV_EXTERN int uv_write(uv_write_t* req,
  392. uv_stream_t* handle,
  393. const uv_buf_t bufs[],
  394. unsigned int nbufs,
  395. uv_write_cb cb);
  396. UV_EXTERN int uv_write2(uv_write_t* req,
  397. uv_stream_t* handle,
  398. const uv_buf_t bufs[],
  399. unsigned int nbufs,
  400. uv_stream_t* send_handle,
  401. uv_write_cb cb);
  402. UV_EXTERN int uv_try_write(uv_stream_t* handle,
  403. const uv_buf_t bufs[],
  404. unsigned int nbufs);
  405. /* uv_write_t is a subclass of uv_req_t. */
  406. struct uv_write_s {
  407. UV_REQ_FIELDS
  408. uv_write_cb cb;
  409. uv_stream_t* send_handle;
  410. uv_stream_t* handle;
  411. UV_WRITE_PRIVATE_FIELDS
  412. };
  413. UV_EXTERN int uv_is_readable(const uv_stream_t* handle);
  414. UV_EXTERN int uv_is_writable(const uv_stream_t* handle);
  415. UV_EXTERN int uv_stream_set_blocking(uv_stream_t* handle, int blocking);
  416. UV_EXTERN int uv_is_closing(const uv_handle_t* handle);
  417. /*
  418. * uv_tcp_t is a subclass of uv_stream_t.
  419. *
  420. * Represents a TCP stream or TCP server.
  421. */
  422. struct uv_tcp_s {
  423. UV_HANDLE_FIELDS
  424. UV_STREAM_FIELDS
  425. UV_TCP_PRIVATE_FIELDS
  426. };
  427. UV_EXTERN int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle);
  428. UV_EXTERN int uv_tcp_open(uv_tcp_t* handle, uv_os_sock_t sock);
  429. UV_EXTERN int uv_tcp_nodelay(uv_tcp_t* handle, int enable);
  430. UV_EXTERN int uv_tcp_keepalive(uv_tcp_t* handle,
  431. int enable,
  432. unsigned int delay);
  433. UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable);
  434. enum uv_tcp_flags {
  435. /* Used with uv_tcp_bind, when an IPv6 address is used. */
  436. UV_TCP_IPV6ONLY = 1
  437. };
  438. UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle,
  439. const struct sockaddr* addr,
  440. unsigned int flags);
  441. UV_EXTERN int uv_tcp_getsockname(const uv_tcp_t* handle,
  442. struct sockaddr* name,
  443. int* namelen);
  444. UV_EXTERN int uv_tcp_getpeername(const uv_tcp_t* handle,
  445. struct sockaddr* name,
  446. int* namelen);
  447. UV_EXTERN int uv_tcp_connect(uv_connect_t* req,
  448. uv_tcp_t* handle,
  449. const struct sockaddr* addr,
  450. uv_connect_cb cb);
  451. /* uv_connect_t is a subclass of uv_req_t. */
  452. struct uv_connect_s {
  453. UV_REQ_FIELDS
  454. uv_connect_cb cb;
  455. uv_stream_t* handle;
  456. UV_CONNECT_PRIVATE_FIELDS
  457. };
  458. /*
  459. * UDP support.
  460. */
  461. enum uv_udp_flags {
  462. /* Disables dual stack mode. */
  463. UV_UDP_IPV6ONLY = 1,
  464. /*
  465. * Indicates message was truncated because read buffer was too small. The
  466. * remainder was discarded by the OS. Used in uv_udp_recv_cb.
  467. */
  468. UV_UDP_PARTIAL = 2,
  469. /*
  470. * Indicates if SO_REUSEADDR will be set when binding the handle.
  471. * This sets the SO_REUSEPORT socket flag on the BSDs and OS X. On other
  472. * Unix platforms, it sets the SO_REUSEADDR flag. What that means is that
  473. * multiple threads or processes can bind to the same address without error
  474. * (provided they all set the flag) but only the last one to bind will receive
  475. * any traffic, in effect "stealing" the port from the previous listener.
  476. */
  477. UV_UDP_REUSEADDR = 4
  478. };
  479. typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
  480. typedef void (*uv_udp_recv_cb)(uv_udp_t* handle,
  481. ssize_t nread,
  482. const uv_buf_t* buf,
  483. const struct sockaddr* addr,
  484. unsigned flags);
  485. /* uv_udp_t is a subclass of uv_handle_t. */
  486. struct uv_udp_s {
  487. UV_HANDLE_FIELDS
  488. /* read-only */
  489. /*
  490. * Number of bytes queued for sending. This field strictly shows how much
  491. * information is currently queued.
  492. */
  493. size_t send_queue_size;
  494. /*
  495. * Number of send requests currently in the queue awaiting to be processed.
  496. */
  497. size_t send_queue_count;
  498. UV_UDP_PRIVATE_FIELDS
  499. };
  500. /* uv_udp_send_t is a subclass of uv_req_t. */
  501. struct uv_udp_send_s {
  502. UV_REQ_FIELDS
  503. uv_udp_t* handle;
  504. uv_udp_send_cb cb;
  505. UV_UDP_SEND_PRIVATE_FIELDS
  506. };
  507. UV_EXTERN int uv_udp_init(uv_loop_t*, uv_udp_t* handle);
  508. UV_EXTERN int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock);
  509. UV_EXTERN int uv_udp_bind(uv_udp_t* handle,
  510. const struct sockaddr* addr,
  511. unsigned int flags);
  512. UV_EXTERN int uv_udp_getsockname(const uv_udp_t* handle,
  513. struct sockaddr* name,
  514. int* namelen);
  515. UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
  516. const char* multicast_addr,
  517. const char* interface_addr,
  518. uv_membership membership);
  519. UV_EXTERN int uv_udp_set_multicast_loop(uv_udp_t* handle, int on);
  520. UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
  521. UV_EXTERN int uv_udp_set_multicast_interface(uv_udp_t* handle,
  522. const char* interface_addr);
  523. UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
  524. UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
  525. UV_EXTERN int uv_udp_send(uv_udp_send_t* req,
  526. uv_udp_t* handle,
  527. const uv_buf_t bufs[],
  528. unsigned int nbufs,
  529. const struct sockaddr* addr,
  530. uv_udp_send_cb send_cb);
  531. UV_EXTERN int uv_udp_try_send(uv_udp_t* handle,
  532. const uv_buf_t bufs[],
  533. unsigned int nbufs,
  534. const struct sockaddr* addr);
  535. UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
  536. uv_alloc_cb alloc_cb,
  537. uv_udp_recv_cb recv_cb);
  538. UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
  539. /*
  540. * uv_tty_t is a subclass of uv_stream_t.
  541. *
  542. * Representing a stream for the console.
  543. */
  544. struct uv_tty_s {
  545. UV_HANDLE_FIELDS
  546. UV_STREAM_FIELDS
  547. UV_TTY_PRIVATE_FIELDS
  548. };
  549. typedef enum {
  550. /* Initial/normal terminal mode */
  551. UV_TTY_MODE_NORMAL,
  552. /* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
  553. UV_TTY_MODE_RAW,
  554. /* Binary-safe I/O mode for IPC (Unix-only) */
  555. UV_TTY_MODE_IO
  556. } uv_tty_mode_t;
  557. UV_EXTERN int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd, int readable);
  558. UV_EXTERN int uv_tty_set_mode(uv_tty_t*, uv_tty_mode_t mode);
  559. UV_EXTERN int uv_tty_reset_mode(void);
  560. UV_EXTERN int uv_tty_get_winsize(uv_tty_t*, int* width, int* height);
  561. #ifdef __cplusplus
  562. extern "C++" {
  563. inline int uv_tty_set_mode(uv_tty_t* handle, int mode) {
  564. return uv_tty_set_mode(handle, static_cast<uv_tty_mode_t>(mode));
  565. }
  566. }
  567. #endif
  568. UV_EXTERN uv_handle_type uv_guess_handle(uv_file file);
  569. /*
  570. * uv_pipe_t is a subclass of uv_stream_t.
  571. *
  572. * Representing a pipe stream or pipe server. On Windows this is a Named
  573. * Pipe. On Unix this is a Unix domain socket.
  574. */
  575. struct uv_pipe_s {
  576. UV_HANDLE_FIELDS
  577. UV_STREAM_FIELDS
  578. int ipc; /* non-zero if this pipe is used for passing handles */
  579. UV_PIPE_PRIVATE_FIELDS
  580. };
  581. UV_EXTERN int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle, int ipc);
  582. UV_EXTERN int uv_pipe_open(uv_pipe_t*, uv_file file);
  583. UV_EXTERN int uv_pipe_bind(uv_pipe_t* handle, const char* name);
  584. UV_EXTERN void uv_pipe_connect(uv_connect_t* req,
  585. uv_pipe_t* handle,
  586. const char* name,
  587. uv_connect_cb cb);
  588. UV_EXTERN int uv_pipe_getsockname(const uv_pipe_t* handle,
  589. char* buffer,
  590. size_t* size);
  591. UV_EXTERN int uv_pipe_getpeername(const uv_pipe_t* handle,
  592. char* buffer,
  593. size_t* size);
  594. UV_EXTERN void uv_pipe_pending_instances(uv_pipe_t* handle, int count);
  595. UV_EXTERN int uv_pipe_pending_count(uv_pipe_t* handle);
  596. UV_EXTERN uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle);
  597. struct uv_poll_s {
  598. UV_HANDLE_FIELDS
  599. uv_poll_cb poll_cb;
  600. UV_POLL_PRIVATE_FIELDS
  601. };
  602. enum uv_poll_event {
  603. UV_READABLE = 1,
  604. UV_WRITABLE = 2
  605. };
  606. UV_EXTERN int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd);
  607. UV_EXTERN int uv_poll_init_socket(uv_loop_t* loop,
  608. uv_poll_t* handle,
  609. uv_os_sock_t socket);
  610. UV_EXTERN int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb);
  611. UV_EXTERN int uv_poll_stop(uv_poll_t* handle);
  612. struct uv_prepare_s {
  613. UV_HANDLE_FIELDS
  614. UV_PREPARE_PRIVATE_FIELDS
  615. };
  616. UV_EXTERN int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare);
  617. UV_EXTERN int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb);
  618. UV_EXTERN int uv_prepare_stop(uv_prepare_t* prepare);
  619. struct uv_check_s {
  620. UV_HANDLE_FIELDS
  621. UV_CHECK_PRIVATE_FIELDS
  622. };
  623. UV_EXTERN int uv_check_init(uv_loop_t*, uv_check_t* check);
  624. UV_EXTERN int uv_check_start(uv_check_t* check, uv_check_cb cb);
  625. UV_EXTERN int uv_check_stop(uv_check_t* check);
  626. struct uv_idle_s {
  627. UV_HANDLE_FIELDS
  628. UV_IDLE_PRIVATE_FIELDS
  629. };
  630. UV_EXTERN int uv_idle_init(uv_loop_t*, uv_idle_t* idle);
  631. UV_EXTERN int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb);
  632. UV_EXTERN int uv_idle_stop(uv_idle_t* idle);
  633. struct uv_async_s {
  634. UV_HANDLE_FIELDS
  635. UV_ASYNC_PRIVATE_FIELDS
  636. };
  637. UV_EXTERN int uv_async_init(uv_loop_t*,
  638. uv_async_t* async,
  639. uv_async_cb async_cb);
  640. UV_EXTERN int uv_async_send(uv_async_t* async);
  641. /*
  642. * uv_timer_t is a subclass of uv_handle_t.
  643. *
  644. * Used to get woken up at a specified time in the future.
  645. */
  646. struct uv_timer_s {
  647. UV_HANDLE_FIELDS
  648. UV_TIMER_PRIVATE_FIELDS
  649. };
  650. UV_EXTERN int uv_timer_init(uv_loop_t*, uv_timer_t* handle);
  651. UV_EXTERN int uv_timer_start(uv_timer_t* handle,
  652. uv_timer_cb cb,
  653. uint64_t timeout,
  654. uint64_t repeat);
  655. UV_EXTERN int uv_timer_stop(uv_timer_t* handle);
  656. UV_EXTERN int uv_timer_again(uv_timer_t* handle);
  657. UV_EXTERN void uv_timer_set_repeat(uv_timer_t* handle, uint64_t repeat);
  658. UV_EXTERN uint64_t uv_timer_get_repeat(const uv_timer_t* handle);
  659. /*
  660. * uv_getaddrinfo_t is a subclass of uv_req_t.
  661. *
  662. * Request object for uv_getaddrinfo.
  663. */
  664. struct uv_getaddrinfo_s {
  665. UV_REQ_FIELDS
  666. /* read-only */
  667. uv_loop_t* loop;
  668. /* struct addrinfo* addrinfo is marked as private, but it really isn't. */
  669. UV_GETADDRINFO_PRIVATE_FIELDS
  670. };
  671. UV_EXTERN int uv_getaddrinfo(uv_loop_t* loop,
  672. uv_getaddrinfo_t* req,
  673. uv_getaddrinfo_cb getaddrinfo_cb,
  674. const char* node,
  675. const char* service,
  676. const struct addrinfo* hints);
  677. UV_EXTERN void uv_freeaddrinfo(struct addrinfo* ai);
  678. /*
  679. * uv_getnameinfo_t is a subclass of uv_req_t.
  680. *
  681. * Request object for uv_getnameinfo.
  682. */
  683. struct uv_getnameinfo_s {
  684. UV_REQ_FIELDS
  685. /* read-only */
  686. uv_loop_t* loop;
  687. /* host and service are marked as private, but they really aren't. */
  688. UV_GETNAMEINFO_PRIVATE_FIELDS
  689. };
  690. UV_EXTERN int uv_getnameinfo(uv_loop_t* loop,
  691. uv_getnameinfo_t* req,
  692. uv_getnameinfo_cb getnameinfo_cb,
  693. const struct sockaddr* addr,
  694. int flags);
  695. /* uv_spawn() options. */
  696. typedef enum {
  697. UV_IGNORE = 0x00,
  698. UV_CREATE_PIPE = 0x01,
  699. UV_INHERIT_FD = 0x02,
  700. UV_INHERIT_STREAM = 0x04,
  701. /*
  702. * When UV_CREATE_PIPE is specified, UV_READABLE_PIPE and UV_WRITABLE_PIPE
  703. * determine the direction of flow, from the child process' perspective. Both
  704. * flags may be specified to create a duplex data stream.
  705. */
  706. UV_READABLE_PIPE = 0x10,
  707. UV_WRITABLE_PIPE = 0x20
  708. } uv_stdio_flags;
  709. typedef struct uv_stdio_container_s {
  710. uv_stdio_flags flags;
  711. union {
  712. uv_stream_t* stream;
  713. int fd;
  714. } data;
  715. } uv_stdio_container_t;
  716. typedef struct uv_process_options_s {
  717. uv_exit_cb exit_cb; /* Called after the process exits. */
  718. const char* file; /* Path to program to execute. */
  719. /*
  720. * Command line arguments. args[0] should be the path to the program. On
  721. * Windows this uses CreateProcess which concatenates the arguments into a
  722. * string this can cause some strange errors. See the note at
  723. * windows_verbatim_arguments.
  724. */
  725. char** args;
  726. /*
  727. * This will be set as the environ variable in the subprocess. If this is
  728. * NULL then the parents environ will be used.
  729. */
  730. char** env;
  731. /*
  732. * If non-null this represents a directory the subprocess should execute
  733. * in. Stands for current working directory.
  734. */
  735. const char* cwd;
  736. /*
  737. * Various flags that control how uv_spawn() behaves. See the definition of
  738. * `enum uv_process_flags` below.
  739. */
  740. unsigned int flags;
  741. /*
  742. * The `stdio` field points to an array of uv_stdio_container_t structs that
  743. * describe the file descriptors that will be made available to the child
  744. * process. The convention is that stdio[0] points to stdin, fd 1 is used for
  745. * stdout, and fd 2 is stderr.
  746. *
  747. * Note that on windows file descriptors greater than 2 are available to the
  748. * child process only if the child processes uses the MSVCRT runtime.
  749. */
  750. int stdio_count;
  751. uv_stdio_container_t* stdio;
  752. /*
  753. * Libuv can change the child process' user/group id. This happens only when
  754. * the appropriate bits are set in the flags fields. This is not supported on
  755. * windows; uv_spawn() will fail and set the error to UV_ENOTSUP.
  756. */
  757. uv_uid_t uid;
  758. uv_gid_t gid;
  759. } uv_process_options_t;
  760. /*
  761. * These are the flags that can be used for the uv_process_options.flags field.
  762. */
  763. enum uv_process_flags {
  764. /*
  765. * Set the child process' user id. The user id is supplied in the `uid` field
  766. * of the options struct. This does not work on windows; setting this flag
  767. * will cause uv_spawn() to fail.
  768. */
  769. UV_PROCESS_SETUID = (1 << 0),
  770. /*
  771. * Set the child process' group id. The user id is supplied in the `gid`
  772. * field of the options struct. This does not work on windows; setting this
  773. * flag will cause uv_spawn() to fail.
  774. */
  775. UV_PROCESS_SETGID = (1 << 1),
  776. /*
  777. * Do not wrap any arguments in quotes, or perform any other escaping, when
  778. * converting the argument list into a command line string. This option is
  779. * only meaningful on Windows systems. On Unix it is silently ignored.
  780. */
  781. UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2),
  782. /*
  783. * Spawn the child process in a detached state - this will make it a process
  784. * group leader, and will effectively enable the child to keep running after
  785. * the parent exits. Note that the child process will still keep the
  786. * parent's event loop alive unless the parent process calls uv_unref() on
  787. * the child's process handle.
  788. */
  789. UV_PROCESS_DETACHED = (1 << 3),
  790. /*
  791. * Hide the subprocess console window that would normally be created. This
  792. * option is only meaningful on Windows systems. On Unix it is silently
  793. * ignored.
  794. */
  795. UV_PROCESS_WINDOWS_HIDE = (1 << 4)
  796. };
  797. /*
  798. * uv_process_t is a subclass of uv_handle_t.
  799. */
  800. struct uv_process_s {
  801. UV_HANDLE_FIELDS
  802. uv_exit_cb exit_cb;
  803. int pid;
  804. UV_PROCESS_PRIVATE_FIELDS
  805. };
  806. UV_EXTERN int uv_spawn(uv_loop_t* loop,
  807. uv_process_t* handle,
  808. const uv_process_options_t* options);
  809. UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
  810. UV_EXTERN int uv_kill(int pid, int signum);
  811. /*
  812. * uv_work_t is a subclass of uv_req_t.
  813. */
  814. struct uv_work_s {
  815. UV_REQ_FIELDS
  816. uv_loop_t* loop;
  817. uv_work_cb work_cb;
  818. uv_after_work_cb after_work_cb;
  819. UV_WORK_PRIVATE_FIELDS
  820. };
  821. UV_EXTERN int uv_queue_work(uv_loop_t* loop,
  822. uv_work_t* req,
  823. uv_work_cb work_cb,
  824. uv_after_work_cb after_work_cb);
  825. UV_EXTERN int uv_cancel(uv_req_t* req);
  826. struct uv_cpu_info_s {
  827. char* model;
  828. int speed;
  829. struct uv_cpu_times_s {
  830. uint64_t user;
  831. uint64_t nice;
  832. uint64_t sys;
  833. uint64_t idle;
  834. uint64_t irq;
  835. } cpu_times;
  836. };
  837. struct uv_interface_address_s {
  838. char* name;
  839. char phys_addr[6];
  840. int is_internal;
  841. union {
  842. struct sockaddr_in address4;
  843. struct sockaddr_in6 address6;
  844. } address;
  845. union {
  846. struct sockaddr_in netmask4;
  847. struct sockaddr_in6 netmask6;
  848. } netmask;
  849. };
  850. typedef enum {
  851. UV_DIRENT_UNKNOWN,
  852. UV_DIRENT_FILE,
  853. UV_DIRENT_DIR,
  854. UV_DIRENT_LINK,
  855. UV_DIRENT_FIFO,
  856. UV_DIRENT_SOCKET,
  857. UV_DIRENT_CHAR,
  858. UV_DIRENT_BLOCK
  859. } uv_dirent_type_t;
  860. struct uv_dirent_s {
  861. const char* name;
  862. uv_dirent_type_t type;
  863. };
  864. UV_EXTERN char** uv_setup_args(int argc, char** argv);
  865. UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
  866. UV_EXTERN int uv_set_process_title(const char* title);
  867. UV_EXTERN int uv_resident_set_memory(size_t* rss);
  868. UV_EXTERN int uv_uptime(double* uptime);
  869. typedef struct {
  870. long tv_sec;
  871. long tv_usec;
  872. } uv_timeval_t;
  873. typedef struct {
  874. uv_timeval_t ru_utime; /* user CPU time used */
  875. uv_timeval_t ru_stime; /* system CPU time used */
  876. uint64_t ru_maxrss; /* maximum resident set size */
  877. uint64_t ru_ixrss; /* integral shared memory size */
  878. uint64_t ru_idrss; /* integral unshared data size */
  879. uint64_t ru_isrss; /* integral unshared stack size */
  880. uint64_t ru_minflt; /* page reclaims (soft page faults) */
  881. uint64_t ru_majflt; /* page faults (hard page faults) */
  882. uint64_t ru_nswap; /* swaps */
  883. uint64_t ru_inblock; /* block input operations */
  884. uint64_t ru_oublock; /* block output operations */
  885. uint64_t ru_msgsnd; /* IPC messages sent */
  886. uint64_t ru_msgrcv; /* IPC messages received */
  887. uint64_t ru_nsignals; /* signals received */
  888. uint64_t ru_nvcsw; /* voluntary context switches */
  889. uint64_t ru_nivcsw; /* involuntary context switches */
  890. } uv_rusage_t;
  891. UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
  892. UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
  893. UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
  894. UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
  895. int* count);
  896. UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
  897. int count);
  898. typedef enum {
  899. UV_FS_UNKNOWN = -1,
  900. UV_FS_CUSTOM,
  901. UV_FS_OPEN,
  902. UV_FS_CLOSE,
  903. UV_FS_READ,
  904. UV_FS_WRITE,
  905. UV_FS_SENDFILE,
  906. UV_FS_STAT,
  907. UV_FS_LSTAT,
  908. UV_FS_FSTAT,
  909. UV_FS_FTRUNCATE,
  910. UV_FS_UTIME,
  911. UV_FS_FUTIME,
  912. UV_FS_ACCESS,
  913. UV_FS_CHMOD,
  914. UV_FS_FCHMOD,
  915. UV_FS_FSYNC,
  916. UV_FS_FDATASYNC,
  917. UV_FS_UNLINK,
  918. UV_FS_RMDIR,
  919. UV_FS_MKDIR,
  920. UV_FS_MKDTEMP,
  921. UV_FS_RENAME,
  922. UV_FS_SCANDIR,
  923. UV_FS_LINK,
  924. UV_FS_SYMLINK,
  925. UV_FS_READLINK,
  926. UV_FS_CHOWN,
  927. UV_FS_FCHOWN
  928. } uv_fs_type;
  929. /* uv_fs_t is a subclass of uv_req_t. */
  930. struct uv_fs_s {
  931. UV_REQ_FIELDS
  932. uv_fs_type fs_type;
  933. uv_loop_t* loop;
  934. uv_fs_cb cb;
  935. ssize_t result;
  936. void* ptr;
  937. const char* path;
  938. uv_stat_t statbuf; /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
  939. UV_FS_PRIVATE_FIELDS
  940. };
  941. UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
  942. UV_EXTERN int uv_fs_close(uv_loop_t* loop,
  943. uv_fs_t* req,
  944. uv_file file,
  945. uv_fs_cb cb);
  946. UV_EXTERN int uv_fs_open(uv_loop_t* loop,
  947. uv_fs_t* req,
  948. const char* path,
  949. int flags,
  950. int mode,
  951. uv_fs_cb cb);
  952. UV_EXTERN int uv_fs_read(uv_loop_t* loop,
  953. uv_fs_t* req,
  954. uv_file file,
  955. const uv_buf_t bufs[],
  956. unsigned int nbufs,
  957. int64_t offset,
  958. uv_fs_cb cb);
  959. UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
  960. uv_fs_t* req,
  961. const char* path,
  962. uv_fs_cb cb);
  963. UV_EXTERN int uv_fs_write(uv_loop_t* loop,
  964. uv_fs_t* req,
  965. uv_file file,
  966. const uv_buf_t bufs[],
  967. unsigned int nbufs,
  968. int64_t offset,
  969. uv_fs_cb cb);
  970. UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
  971. uv_fs_t* req,
  972. const char* path,
  973. int mode,
  974. uv_fs_cb cb);
  975. UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
  976. uv_fs_t* req,
  977. const char* tpl,
  978. uv_fs_cb cb);
  979. UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
  980. uv_fs_t* req,
  981. const char* path,
  982. uv_fs_cb cb);
  983. UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
  984. uv_fs_t* req,
  985. const char* path,
  986. int flags,
  987. uv_fs_cb cb);
  988. UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
  989. uv_dirent_t* ent);
  990. UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
  991. uv_fs_t* req,
  992. const char* path,
  993. uv_fs_cb cb);
  994. UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
  995. uv_fs_t* req,
  996. uv_file file,
  997. uv_fs_cb cb);
  998. UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
  999. uv_fs_t* req,
  1000. const char* path,
  1001. const char* new_path,
  1002. uv_fs_cb cb);
  1003. UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
  1004. uv_fs_t* req,
  1005. uv_file file,
  1006. uv_fs_cb cb);
  1007. UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
  1008. uv_fs_t* req,
  1009. uv_file file,
  1010. uv_fs_cb cb);
  1011. UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
  1012. uv_fs_t* req,
  1013. uv_file file,
  1014. int64_t offset,
  1015. uv_fs_cb cb);
  1016. UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
  1017. uv_fs_t* req,
  1018. uv_file out_fd,
  1019. uv_file in_fd,
  1020. int64_t in_offset,
  1021. size_t length,
  1022. uv_fs_cb cb);
  1023. UV_EXTERN int uv_fs_access(uv_loop_t* loop,
  1024. uv_fs_t* req,
  1025. const char* path,
  1026. int mode,
  1027. uv_fs_cb cb);
  1028. UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
  1029. uv_fs_t* req,
  1030. const char* path,
  1031. int mode,
  1032. uv_fs_cb cb);
  1033. UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
  1034. uv_fs_t* req,
  1035. const char* path,
  1036. double atime,
  1037. double mtime,
  1038. uv_fs_cb cb);
  1039. UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
  1040. uv_fs_t* req,
  1041. uv_file file,
  1042. double atime,
  1043. double mtime,
  1044. uv_fs_cb cb);
  1045. UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
  1046. uv_fs_t* req,
  1047. const char* path,
  1048. uv_fs_cb cb);
  1049. UV_EXTERN int uv_fs_link(uv_loop_t* loop,
  1050. uv_fs_t* req,
  1051. const char* path,
  1052. const char* new_path,
  1053. uv_fs_cb cb);
  1054. /*
  1055. * This flag can be used with uv_fs_symlink() on Windows to specify whether
  1056. * path argument points to a directory.
  1057. */
  1058. #define UV_FS_SYMLINK_DIR 0x0001
  1059. /*
  1060. * This flag can be used with uv_fs_symlink() on Windows to specify whether
  1061. * the symlink is to be created using junction points.
  1062. */
  1063. #define UV_FS_SYMLINK_JUNCTION 0x0002
  1064. UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
  1065. uv_fs_t* req,
  1066. const char* path,
  1067. const char* new_path,
  1068. int flags,
  1069. uv_fs_cb cb);
  1070. UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
  1071. uv_fs_t* req,
  1072. const char* path,
  1073. uv_fs_cb cb);
  1074. UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
  1075. uv_fs_t* req,
  1076. uv_file file,
  1077. int mode,
  1078. uv_fs_cb cb);
  1079. UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
  1080. uv_fs_t* req,
  1081. const char* path,
  1082. uv_uid_t uid,
  1083. uv_gid_t gid,
  1084. uv_fs_cb cb);
  1085. UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
  1086. uv_fs_t* req,
  1087. uv_file file,
  1088. uv_uid_t uid,
  1089. uv_gid_t gid,
  1090. uv_fs_cb cb);
  1091. enum uv_fs_event {
  1092. UV_RENAME = 1,
  1093. UV_CHANGE = 2
  1094. };
  1095. struct uv_fs_event_s {
  1096. UV_HANDLE_FIELDS
  1097. /* private */
  1098. char* path;
  1099. UV_FS_EVENT_PRIVATE_FIELDS
  1100. };
  1101. /*
  1102. * uv_fs_stat() based polling file watcher.
  1103. */
  1104. struct uv_fs_poll_s {
  1105. UV_HANDLE_FIELDS
  1106. /* Private, don't touch. */
  1107. void* poll_ctx;
  1108. };
  1109. UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
  1110. UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
  1111. uv_fs_poll_cb poll_cb,
  1112. const char* path,
  1113. unsigned int interval);
  1114. UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
  1115. UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
  1116. char* buffer,
  1117. size_t* size);
  1118. struct uv_signal_s {
  1119. UV_HANDLE_FIELDS
  1120. uv_signal_cb signal_cb;
  1121. int signum;
  1122. UV_SIGNAL_PRIVATE_FIELDS
  1123. };
  1124. UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
  1125. UV_EXTERN int uv_signal_start(uv_signal_t* handle,
  1126. uv_signal_cb signal_cb,
  1127. int signum);
  1128. UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
  1129. UV_EXTERN void uv_loadavg(double avg[3]);
  1130. /*
  1131. * Flags to be passed to uv_fs_event_start().
  1132. */
  1133. enum uv_fs_event_flags {
  1134. /*
  1135. * By default, if the fs event watcher is given a directory name, we will
  1136. * watch for all events in that directory. This flags overrides this behavior
  1137. * and makes fs_event report only changes to the directory entry itself. This
  1138. * flag does not affect individual files watched.
  1139. * This flag is currently not implemented yet on any backend.
  1140. */
  1141. UV_FS_EVENT_WATCH_ENTRY = 1,
  1142. /*
  1143. * By default uv_fs_event will try to use a kernel interface such as inotify
  1144. * or kqueue to detect events. This may not work on remote filesystems such
  1145. * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
  1146. * regular interval.
  1147. * This flag is currently not implemented yet on any backend.
  1148. */
  1149. UV_FS_EVENT_STAT = 2,
  1150. /*
  1151. * By default, event watcher, when watching directory, is not registering
  1152. * (is ignoring) changes in it's subdirectories.
  1153. * This flag will override this behaviour on platforms that support it.
  1154. */
  1155. UV_FS_EVENT_RECURSIVE = 4
  1156. };
  1157. UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
  1158. UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
  1159. uv_fs_event_cb cb,
  1160. const char* path,
  1161. unsigned int flags);
  1162. UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
  1163. UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
  1164. char* buffer,
  1165. size_t* size);
  1166. UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
  1167. UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
  1168. UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
  1169. UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
  1170. UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
  1171. UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
  1172. UV_EXTERN int uv_exepath(char* buffer, size_t* size);
  1173. UV_EXTERN int uv_cwd(char* buffer, size_t* size);
  1174. UV_EXTERN int uv_chdir(const char* dir);
  1175. UV_EXTERN uint64_t uv_get_free_memory(void);
  1176. UV_EXTERN uint64_t uv_get_total_memory(void);
  1177. UV_EXTERN extern uint64_t uv_hrtime(void);
  1178. UV_EXTERN void uv_disable_stdio_inheritance(void);
  1179. UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
  1180. UV_EXTERN void uv_dlclose(uv_lib_t* lib);
  1181. UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
  1182. UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
  1183. UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
  1184. UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
  1185. UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
  1186. UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
  1187. UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
  1188. UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
  1189. UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
  1190. UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
  1191. UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
  1192. UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
  1193. UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
  1194. UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
  1195. UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
  1196. UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
  1197. UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
  1198. UV_EXTERN void uv_sem_post(uv_sem_t* sem);
  1199. UV_EXTERN void uv_sem_wait(uv_sem_t*

Large files files are truncated, but you can click here to view the full file