uv.h 71 KB

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