uv.h 59 KB

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