uv.h 66 KB

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