uv.h 63 KB

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