uv.h 67 KB

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