uv.h 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  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. /*
  948. * uv_process_t is a subclass of uv_handle_t.
  949. */
  950. struct uv_process_s {
  951. UV_HANDLE_FIELDS
  952. uv_exit_cb exit_cb;
  953. int pid;
  954. UV_PROCESS_PRIVATE_FIELDS
  955. };
  956. UV_EXTERN int uv_spawn(uv_loop_t* loop,
  957. uv_process_t* handle,
  958. const uv_process_options_t* options);
  959. UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
  960. UV_EXTERN int uv_kill(int pid, int signum);
  961. UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
  962. /*
  963. * uv_work_t is a subclass of uv_req_t.
  964. */
  965. struct uv_work_s {
  966. UV_REQ_FIELDS
  967. uv_loop_t* loop;
  968. uv_work_cb work_cb;
  969. uv_after_work_cb after_work_cb;
  970. UV_WORK_PRIVATE_FIELDS
  971. };
  972. UV_EXTERN int uv_queue_work(uv_loop_t* loop,
  973. uv_work_t* req,
  974. uv_work_cb work_cb,
  975. uv_after_work_cb after_work_cb);
  976. UV_EXTERN int uv_cancel(uv_req_t* req);
  977. struct uv_cpu_times_s {
  978. uint64_t user; /* milliseconds */
  979. uint64_t nice; /* milliseconds */
  980. uint64_t sys; /* milliseconds */
  981. uint64_t idle; /* milliseconds */
  982. uint64_t irq; /* milliseconds */
  983. };
  984. struct uv_cpu_info_s {
  985. char* model;
  986. int speed;
  987. struct uv_cpu_times_s cpu_times;
  988. };
  989. struct uv_interface_address_s {
  990. char* name;
  991. char phys_addr[6];
  992. int is_internal;
  993. union {
  994. struct sockaddr_in address4;
  995. struct sockaddr_in6 address6;
  996. } address;
  997. union {
  998. struct sockaddr_in netmask4;
  999. struct sockaddr_in6 netmask6;
  1000. } netmask;
  1001. };
  1002. struct uv_passwd_s {
  1003. char* username;
  1004. unsigned long uid;
  1005. unsigned long gid;
  1006. char* shell;
  1007. char* homedir;
  1008. };
  1009. struct uv_utsname_s {
  1010. char sysname[256];
  1011. char release[256];
  1012. char version[256];
  1013. char machine[256];
  1014. /* This struct does not contain the nodename and domainname fields present in
  1015. the utsname type. domainname is a GNU extension. Both fields are referred
  1016. to as meaningless in the docs. */
  1017. };
  1018. struct uv_statfs_s {
  1019. uint64_t f_type;
  1020. uint64_t f_bsize;
  1021. uint64_t f_blocks;
  1022. uint64_t f_bfree;
  1023. uint64_t f_bavail;
  1024. uint64_t f_files;
  1025. uint64_t f_ffree;
  1026. uint64_t f_spare[4];
  1027. };
  1028. typedef enum {
  1029. UV_DIRENT_UNKNOWN,
  1030. UV_DIRENT_FILE,
  1031. UV_DIRENT_DIR,
  1032. UV_DIRENT_LINK,
  1033. UV_DIRENT_FIFO,
  1034. UV_DIRENT_SOCKET,
  1035. UV_DIRENT_CHAR,
  1036. UV_DIRENT_BLOCK
  1037. } uv_dirent_type_t;
  1038. struct uv_dirent_s {
  1039. const char* name;
  1040. uv_dirent_type_t type;
  1041. };
  1042. UV_EXTERN char** uv_setup_args(int argc, char** argv);
  1043. UV_EXTERN int uv_get_process_title(char* buffer, size_t size);
  1044. UV_EXTERN int uv_set_process_title(const char* title);
  1045. UV_EXTERN int uv_resident_set_memory(size_t* rss);
  1046. UV_EXTERN int uv_uptime(double* uptime);
  1047. UV_EXTERN uv_os_fd_t uv_get_osfhandle(int fd);
  1048. UV_EXTERN int uv_open_osfhandle(uv_os_fd_t os_fd);
  1049. typedef struct {
  1050. long tv_sec;
  1051. long tv_usec;
  1052. } uv_timeval_t;
  1053. typedef struct {
  1054. int64_t tv_sec;
  1055. int32_t tv_usec;
  1056. } uv_timeval64_t;
  1057. typedef struct {
  1058. uv_timeval_t ru_utime; /* user CPU time used */
  1059. uv_timeval_t ru_stime; /* system CPU time used */
  1060. uint64_t ru_maxrss; /* maximum resident set size */
  1061. uint64_t ru_ixrss; /* integral shared memory size */
  1062. uint64_t ru_idrss; /* integral unshared data size */
  1063. uint64_t ru_isrss; /* integral unshared stack size */
  1064. uint64_t ru_minflt; /* page reclaims (soft page faults) */
  1065. uint64_t ru_majflt; /* page faults (hard page faults) */
  1066. uint64_t ru_nswap; /* swaps */
  1067. uint64_t ru_inblock; /* block input operations */
  1068. uint64_t ru_oublock; /* block output operations */
  1069. uint64_t ru_msgsnd; /* IPC messages sent */
  1070. uint64_t ru_msgrcv; /* IPC messages received */
  1071. uint64_t ru_nsignals; /* signals received */
  1072. uint64_t ru_nvcsw; /* voluntary context switches */
  1073. uint64_t ru_nivcsw; /* involuntary context switches */
  1074. } uv_rusage_t;
  1075. UV_EXTERN int uv_getrusage(uv_rusage_t* rusage);
  1076. UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
  1077. UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
  1078. UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
  1079. UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
  1080. UV_EXTERN uv_pid_t uv_os_getpid(void);
  1081. UV_EXTERN uv_pid_t uv_os_getppid(void);
  1082. #if defined(__PASE__)
  1083. /* On IBM i PASE, the highest process priority is -10 */
  1084. # define UV_PRIORITY_LOW 39 /* RUNPTY(99) */
  1085. # define UV_PRIORITY_BELOW_NORMAL 15 /* RUNPTY(50) */
  1086. # define UV_PRIORITY_NORMAL 0 /* RUNPTY(20) */
  1087. # define UV_PRIORITY_ABOVE_NORMAL -4 /* RUNTY(12) */
  1088. # define UV_PRIORITY_HIGH -7 /* RUNPTY(6) */
  1089. # define UV_PRIORITY_HIGHEST -10 /* RUNPTY(1) */
  1090. #else
  1091. # define UV_PRIORITY_LOW 19
  1092. # define UV_PRIORITY_BELOW_NORMAL 10
  1093. # define UV_PRIORITY_NORMAL 0
  1094. # define UV_PRIORITY_ABOVE_NORMAL -7
  1095. # define UV_PRIORITY_HIGH -14
  1096. # define UV_PRIORITY_HIGHEST -20
  1097. #endif
  1098. UV_EXTERN int uv_os_getpriority(uv_pid_t pid, int* priority);
  1099. UV_EXTERN int uv_os_setpriority(uv_pid_t pid, int priority);
  1100. UV_EXTERN unsigned int uv_available_parallelism(void);
  1101. UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
  1102. UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);
  1103. UV_EXTERN int uv_cpumask_size(void);
  1104. UV_EXTERN int uv_interface_addresses(uv_interface_address_t** addresses,
  1105. int* count);
  1106. UV_EXTERN void uv_free_interface_addresses(uv_interface_address_t* addresses,
  1107. int count);
  1108. struct uv_env_item_s {
  1109. char* name;
  1110. char* value;
  1111. };
  1112. UV_EXTERN int uv_os_environ(uv_env_item_t** envitems, int* count);
  1113. UV_EXTERN void uv_os_free_environ(uv_env_item_t* envitems, int count);
  1114. UV_EXTERN int uv_os_getenv(const char* name, char* buffer, size_t* size);
  1115. UV_EXTERN int uv_os_setenv(const char* name, const char* value);
  1116. UV_EXTERN int uv_os_unsetenv(const char* name);
  1117. #ifdef MAXHOSTNAMELEN
  1118. # define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
  1119. #else
  1120. /*
  1121. Fallback for the maximum hostname size, including the null terminator. The
  1122. Windows gethostname() documentation states that 256 bytes will always be
  1123. large enough to hold the null-terminated hostname.
  1124. */
  1125. # define UV_MAXHOSTNAMESIZE 256
  1126. #endif
  1127. UV_EXTERN int uv_os_gethostname(char* buffer, size_t* size);
  1128. UV_EXTERN int uv_os_uname(uv_utsname_t* buffer);
  1129. UV_EXTERN uint64_t uv_metrics_idle_time(uv_loop_t* loop);
  1130. typedef enum {
  1131. UV_FS_UNKNOWN = -1,
  1132. UV_FS_CUSTOM,
  1133. UV_FS_OPEN,
  1134. UV_FS_CLOSE,
  1135. UV_FS_READ,
  1136. UV_FS_WRITE,
  1137. UV_FS_SENDFILE,
  1138. UV_FS_STAT,
  1139. UV_FS_LSTAT,
  1140. UV_FS_FSTAT,
  1141. UV_FS_FTRUNCATE,
  1142. UV_FS_UTIME,
  1143. UV_FS_FUTIME,
  1144. UV_FS_ACCESS,
  1145. UV_FS_CHMOD,
  1146. UV_FS_FCHMOD,
  1147. UV_FS_FSYNC,
  1148. UV_FS_FDATASYNC,
  1149. UV_FS_UNLINK,
  1150. UV_FS_RMDIR,
  1151. UV_FS_MKDIR,
  1152. UV_FS_MKDTEMP,
  1153. UV_FS_RENAME,
  1154. UV_FS_SCANDIR,
  1155. UV_FS_LINK,
  1156. UV_FS_SYMLINK,
  1157. UV_FS_READLINK,
  1158. UV_FS_CHOWN,
  1159. UV_FS_FCHOWN,
  1160. UV_FS_REALPATH,
  1161. UV_FS_COPYFILE,
  1162. UV_FS_LCHOWN,
  1163. UV_FS_OPENDIR,
  1164. UV_FS_READDIR,
  1165. UV_FS_CLOSEDIR,
  1166. UV_FS_STATFS,
  1167. UV_FS_MKSTEMP,
  1168. UV_FS_LUTIME
  1169. } uv_fs_type;
  1170. struct uv_dir_s {
  1171. uv_dirent_t* dirents;
  1172. size_t nentries;
  1173. void* reserved[4];
  1174. UV_DIR_PRIVATE_FIELDS
  1175. };
  1176. /* uv_fs_t is a subclass of uv_req_t. */
  1177. struct uv_fs_s {
  1178. UV_REQ_FIELDS
  1179. uv_fs_type fs_type;
  1180. uv_loop_t* loop;
  1181. uv_fs_cb cb;
  1182. ssize_t result;
  1183. void* ptr;
  1184. const char* path;
  1185. uv_stat_t statbuf; /* Stores the result of uv_fs_stat() and uv_fs_fstat(). */
  1186. UV_FS_PRIVATE_FIELDS
  1187. };
  1188. UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
  1189. UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
  1190. UV_EXTERN int uv_fs_get_system_error(const uv_fs_t*);
  1191. UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
  1192. UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
  1193. UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
  1194. UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
  1195. UV_EXTERN int uv_fs_close(uv_loop_t* loop,
  1196. uv_fs_t* req,
  1197. uv_file file,
  1198. uv_fs_cb cb);
  1199. UV_EXTERN int uv_fs_open(uv_loop_t* loop,
  1200. uv_fs_t* req,
  1201. const char* path,
  1202. int flags,
  1203. int mode,
  1204. uv_fs_cb cb);
  1205. UV_EXTERN int uv_fs_read(uv_loop_t* loop,
  1206. uv_fs_t* req,
  1207. uv_file file,
  1208. const uv_buf_t bufs[],
  1209. unsigned int nbufs,
  1210. int64_t offset,
  1211. uv_fs_cb cb);
  1212. UV_EXTERN int uv_fs_unlink(uv_loop_t* loop,
  1213. uv_fs_t* req,
  1214. const char* path,
  1215. uv_fs_cb cb);
  1216. UV_EXTERN int uv_fs_write(uv_loop_t* loop,
  1217. uv_fs_t* req,
  1218. uv_file file,
  1219. const uv_buf_t bufs[],
  1220. unsigned int nbufs,
  1221. int64_t offset,
  1222. uv_fs_cb cb);
  1223. /*
  1224. * This flag can be used with uv_fs_copyfile() to return an error if the
  1225. * destination already exists.
  1226. */
  1227. #define UV_FS_COPYFILE_EXCL 0x0001
  1228. /*
  1229. * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
  1230. * If copy-on-write is not supported, a fallback copy mechanism is used.
  1231. */
  1232. #define UV_FS_COPYFILE_FICLONE 0x0002
  1233. /*
  1234. * This flag can be used with uv_fs_copyfile() to attempt to create a reflink.
  1235. * If copy-on-write is not supported, an error is returned.
  1236. */
  1237. #define UV_FS_COPYFILE_FICLONE_FORCE 0x0004
  1238. UV_EXTERN int uv_fs_copyfile(uv_loop_t* loop,
  1239. uv_fs_t* req,
  1240. const char* path,
  1241. const char* new_path,
  1242. int flags,
  1243. uv_fs_cb cb);
  1244. UV_EXTERN int uv_fs_mkdir(uv_loop_t* loop,
  1245. uv_fs_t* req,
  1246. const char* path,
  1247. int mode,
  1248. uv_fs_cb cb);
  1249. UV_EXTERN int uv_fs_mkdtemp(uv_loop_t* loop,
  1250. uv_fs_t* req,
  1251. const char* tpl,
  1252. uv_fs_cb cb);
  1253. UV_EXTERN int uv_fs_mkstemp(uv_loop_t* loop,
  1254. uv_fs_t* req,
  1255. const char* tpl,
  1256. uv_fs_cb cb);
  1257. UV_EXTERN int uv_fs_rmdir(uv_loop_t* loop,
  1258. uv_fs_t* req,
  1259. const char* path,
  1260. uv_fs_cb cb);
  1261. UV_EXTERN int uv_fs_scandir(uv_loop_t* loop,
  1262. uv_fs_t* req,
  1263. const char* path,
  1264. int flags,
  1265. uv_fs_cb cb);
  1266. UV_EXTERN int uv_fs_scandir_next(uv_fs_t* req,
  1267. uv_dirent_t* ent);
  1268. UV_EXTERN int uv_fs_opendir(uv_loop_t* loop,
  1269. uv_fs_t* req,
  1270. const char* path,
  1271. uv_fs_cb cb);
  1272. UV_EXTERN int uv_fs_readdir(uv_loop_t* loop,
  1273. uv_fs_t* req,
  1274. uv_dir_t* dir,
  1275. uv_fs_cb cb);
  1276. UV_EXTERN int uv_fs_closedir(uv_loop_t* loop,
  1277. uv_fs_t* req,
  1278. uv_dir_t* dir,
  1279. uv_fs_cb cb);
  1280. UV_EXTERN int uv_fs_stat(uv_loop_t* loop,
  1281. uv_fs_t* req,
  1282. const char* path,
  1283. uv_fs_cb cb);
  1284. UV_EXTERN int uv_fs_fstat(uv_loop_t* loop,
  1285. uv_fs_t* req,
  1286. uv_file file,
  1287. uv_fs_cb cb);
  1288. UV_EXTERN int uv_fs_rename(uv_loop_t* loop,
  1289. uv_fs_t* req,
  1290. const char* path,
  1291. const char* new_path,
  1292. uv_fs_cb cb);
  1293. UV_EXTERN int uv_fs_fsync(uv_loop_t* loop,
  1294. uv_fs_t* req,
  1295. uv_file file,
  1296. uv_fs_cb cb);
  1297. UV_EXTERN int uv_fs_fdatasync(uv_loop_t* loop,
  1298. uv_fs_t* req,
  1299. uv_file file,
  1300. uv_fs_cb cb);
  1301. UV_EXTERN int uv_fs_ftruncate(uv_loop_t* loop,
  1302. uv_fs_t* req,
  1303. uv_file file,
  1304. int64_t offset,
  1305. uv_fs_cb cb);
  1306. UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop,
  1307. uv_fs_t* req,
  1308. uv_file out_fd,
  1309. uv_file in_fd,
  1310. int64_t in_offset,
  1311. size_t length,
  1312. uv_fs_cb cb);
  1313. UV_EXTERN int uv_fs_access(uv_loop_t* loop,
  1314. uv_fs_t* req,
  1315. const char* path,
  1316. int mode,
  1317. uv_fs_cb cb);
  1318. UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
  1319. uv_fs_t* req,
  1320. const char* path,
  1321. int mode,
  1322. uv_fs_cb cb);
  1323. UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
  1324. uv_fs_t* req,
  1325. const char* path,
  1326. double atime,
  1327. double mtime,
  1328. uv_fs_cb cb);
  1329. UV_EXTERN int uv_fs_futime(uv_loop_t* loop,
  1330. uv_fs_t* req,
  1331. uv_file file,
  1332. double atime,
  1333. double mtime,
  1334. uv_fs_cb cb);
  1335. UV_EXTERN int uv_fs_lutime(uv_loop_t* loop,
  1336. uv_fs_t* req,
  1337. const char* path,
  1338. double atime,
  1339. double mtime,
  1340. uv_fs_cb cb);
  1341. UV_EXTERN int uv_fs_lstat(uv_loop_t* loop,
  1342. uv_fs_t* req,
  1343. const char* path,
  1344. uv_fs_cb cb);
  1345. UV_EXTERN int uv_fs_link(uv_loop_t* loop,
  1346. uv_fs_t* req,
  1347. const char* path,
  1348. const char* new_path,
  1349. uv_fs_cb cb);
  1350. /*
  1351. * This flag can be used with uv_fs_symlink() on Windows to specify whether
  1352. * path argument points to a directory.
  1353. */
  1354. #define UV_FS_SYMLINK_DIR 0x0001
  1355. /*
  1356. * This flag can be used with uv_fs_symlink() on Windows to specify whether
  1357. * the symlink is to be created using junction points.
  1358. */
  1359. #define UV_FS_SYMLINK_JUNCTION 0x0002
  1360. UV_EXTERN int uv_fs_symlink(uv_loop_t* loop,
  1361. uv_fs_t* req,
  1362. const char* path,
  1363. const char* new_path,
  1364. int flags,
  1365. uv_fs_cb cb);
  1366. UV_EXTERN int uv_fs_readlink(uv_loop_t* loop,
  1367. uv_fs_t* req,
  1368. const char* path,
  1369. uv_fs_cb cb);
  1370. UV_EXTERN int uv_fs_realpath(uv_loop_t* loop,
  1371. uv_fs_t* req,
  1372. const char* path,
  1373. uv_fs_cb cb);
  1374. UV_EXTERN int uv_fs_fchmod(uv_loop_t* loop,
  1375. uv_fs_t* req,
  1376. uv_file file,
  1377. int mode,
  1378. uv_fs_cb cb);
  1379. UV_EXTERN int uv_fs_chown(uv_loop_t* loop,
  1380. uv_fs_t* req,
  1381. const char* path,
  1382. uv_uid_t uid,
  1383. uv_gid_t gid,
  1384. uv_fs_cb cb);
  1385. UV_EXTERN int uv_fs_fchown(uv_loop_t* loop,
  1386. uv_fs_t* req,
  1387. uv_file file,
  1388. uv_uid_t uid,
  1389. uv_gid_t gid,
  1390. uv_fs_cb cb);
  1391. UV_EXTERN int uv_fs_lchown(uv_loop_t* loop,
  1392. uv_fs_t* req,
  1393. const char* path,
  1394. uv_uid_t uid,
  1395. uv_gid_t gid,
  1396. uv_fs_cb cb);
  1397. UV_EXTERN int uv_fs_statfs(uv_loop_t* loop,
  1398. uv_fs_t* req,
  1399. const char* path,
  1400. uv_fs_cb cb);
  1401. enum uv_fs_event {
  1402. UV_RENAME = 1,
  1403. UV_CHANGE = 2
  1404. };
  1405. struct uv_fs_event_s {
  1406. UV_HANDLE_FIELDS
  1407. /* private */
  1408. char* path;
  1409. UV_FS_EVENT_PRIVATE_FIELDS
  1410. };
  1411. /*
  1412. * uv_fs_stat() based polling file watcher.
  1413. */
  1414. struct uv_fs_poll_s {
  1415. UV_HANDLE_FIELDS
  1416. /* Private, don't touch. */
  1417. void* poll_ctx;
  1418. };
  1419. UV_EXTERN int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle);
  1420. UV_EXTERN int uv_fs_poll_start(uv_fs_poll_t* handle,
  1421. uv_fs_poll_cb poll_cb,
  1422. const char* path,
  1423. unsigned int interval);
  1424. UV_EXTERN int uv_fs_poll_stop(uv_fs_poll_t* handle);
  1425. UV_EXTERN int uv_fs_poll_getpath(uv_fs_poll_t* handle,
  1426. char* buffer,
  1427. size_t* size);
  1428. struct uv_signal_s {
  1429. UV_HANDLE_FIELDS
  1430. uv_signal_cb signal_cb;
  1431. int signum;
  1432. UV_SIGNAL_PRIVATE_FIELDS
  1433. };
  1434. UV_EXTERN int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle);
  1435. UV_EXTERN int uv_signal_start(uv_signal_t* handle,
  1436. uv_signal_cb signal_cb,
  1437. int signum);
  1438. UV_EXTERN int uv_signal_start_oneshot(uv_signal_t* handle,
  1439. uv_signal_cb signal_cb,
  1440. int signum);
  1441. UV_EXTERN int uv_signal_stop(uv_signal_t* handle);
  1442. UV_EXTERN void uv_loadavg(double avg[3]);
  1443. /*
  1444. * Flags to be passed to uv_fs_event_start().
  1445. */
  1446. enum uv_fs_event_flags {
  1447. /*
  1448. * By default, if the fs event watcher is given a directory name, we will
  1449. * watch for all events in that directory. This flags overrides this behavior
  1450. * and makes fs_event report only changes to the directory entry itself. This
  1451. * flag does not affect individual files watched.
  1452. * This flag is currently not implemented yet on any backend.
  1453. */
  1454. UV_FS_EVENT_WATCH_ENTRY = 1,
  1455. /*
  1456. * By default uv_fs_event will try to use a kernel interface such as inotify
  1457. * or kqueue to detect events. This may not work on remote filesystems such
  1458. * as NFS mounts. This flag makes fs_event fall back to calling stat() on a
  1459. * regular interval.
  1460. * This flag is currently not implemented yet on any backend.
  1461. */
  1462. UV_FS_EVENT_STAT = 2,
  1463. /*
  1464. * By default, event watcher, when watching directory, is not registering
  1465. * (is ignoring) changes in it's subdirectories.
  1466. * This flag will override this behaviour on platforms that support it.
  1467. */
  1468. UV_FS_EVENT_RECURSIVE = 4
  1469. };
  1470. UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle);
  1471. UV_EXTERN int uv_fs_event_start(uv_fs_event_t* handle,
  1472. uv_fs_event_cb cb,
  1473. const char* path,
  1474. unsigned int flags);
  1475. UV_EXTERN int uv_fs_event_stop(uv_fs_event_t* handle);
  1476. UV_EXTERN int uv_fs_event_getpath(uv_fs_event_t* handle,
  1477. char* buffer,
  1478. size_t* size);
  1479. UV_EXTERN int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr);
  1480. UV_EXTERN int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr);
  1481. UV_EXTERN int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size);
  1482. UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size);
  1483. UV_EXTERN int uv_ip_name(const struct sockaddr* src, char* dst, size_t size);
  1484. UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size);
  1485. UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst);
  1486. struct uv_random_s {
  1487. UV_REQ_FIELDS
  1488. /* read-only */
  1489. uv_loop_t* loop;
  1490. /* private */
  1491. int status;
  1492. void* buf;
  1493. size_t buflen;
  1494. uv_random_cb cb;
  1495. struct uv__work work_req;
  1496. };
  1497. UV_EXTERN int uv_random(uv_loop_t* loop,
  1498. uv_random_t* req,
  1499. void *buf,
  1500. size_t buflen,
  1501. unsigned flags, /* For future extension; must be 0. */
  1502. uv_random_cb cb);
  1503. #if defined(IF_NAMESIZE)
  1504. # define UV_IF_NAMESIZE (IF_NAMESIZE + 1)
  1505. #elif defined(IFNAMSIZ)
  1506. # define UV_IF_NAMESIZE (IFNAMSIZ + 1)
  1507. #else
  1508. # define UV_IF_NAMESIZE (16 + 1)
  1509. #endif
  1510. UV_EXTERN int uv_if_indextoname(unsigned int ifindex,
  1511. char* buffer,
  1512. size_t* size);
  1513. UV_EXTERN int uv_if_indextoiid(unsigned int ifindex,
  1514. char* buffer,
  1515. size_t* size);
  1516. UV_EXTERN int uv_exepath(char* buffer, size_t* size);
  1517. UV_EXTERN int uv_cwd(char* buffer, size_t* size);
  1518. UV_EXTERN int uv_chdir(const char* dir);
  1519. UV_EXTERN uint64_t uv_get_free_memory(void);
  1520. UV_EXTERN uint64_t uv_get_total_memory(void);
  1521. UV_EXTERN uint64_t uv_get_constrained_memory(void);
  1522. UV_EXTERN uint64_t uv_hrtime(void);
  1523. UV_EXTERN void uv_sleep(unsigned int msec);
  1524. UV_EXTERN void uv_disable_stdio_inheritance(void);
  1525. UV_EXTERN int uv_dlopen(const char* filename, uv_lib_t* lib);
  1526. UV_EXTERN void uv_dlclose(uv_lib_t* lib);
  1527. UV_EXTERN int uv_dlsym(uv_lib_t* lib, const char* name, void** ptr);
  1528. UV_EXTERN const char* uv_dlerror(const uv_lib_t* lib);
  1529. UV_EXTERN int uv_mutex_init(uv_mutex_t* handle);
  1530. UV_EXTERN int uv_mutex_init_recursive(uv_mutex_t* handle);
  1531. UV_EXTERN void uv_mutex_destroy(uv_mutex_t* handle);
  1532. UV_EXTERN void uv_mutex_lock(uv_mutex_t* handle);
  1533. UV_EXTERN int uv_mutex_trylock(uv_mutex_t* handle);
  1534. UV_EXTERN void uv_mutex_unlock(uv_mutex_t* handle);
  1535. UV_EXTERN int uv_rwlock_init(uv_rwlock_t* rwlock);
  1536. UV_EXTERN void uv_rwlock_destroy(uv_rwlock_t* rwlock);
  1537. UV_EXTERN void uv_rwlock_rdlock(uv_rwlock_t* rwlock);
  1538. UV_EXTERN int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock);
  1539. UV_EXTERN void uv_rwlock_rdunlock(uv_rwlock_t* rwlock);
  1540. UV_EXTERN void uv_rwlock_wrlock(uv_rwlock_t* rwlock);
  1541. UV_EXTERN int uv_rwlock_trywrlock(uv_rwlock_t* rwlock);
  1542. UV_EXTERN void uv_rwlock_wrunlock(uv_rwlock_t* rwlock);
  1543. UV_EXTERN int uv_sem_init(uv_sem_t* sem, unsigned int value);
  1544. UV_EXTERN void uv_sem_destroy(uv_sem_t* sem);
  1545. UV_EXTERN void uv_sem_post(uv_sem_t* sem);
  1546. UV_EXTERN void uv_sem_wait(uv_sem_t* sem);
  1547. UV_EXTERN int uv_sem_trywait(uv_sem_t* sem);
  1548. UV_EXTERN int uv_cond_init(uv_cond_t* cond);
  1549. UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
  1550. UV_EXTERN void uv_cond_signal(uv_cond_t* cond);
  1551. UV_EXTERN void uv_cond_broadcast(uv_cond_t* cond);
  1552. UV_EXTERN int uv_barrier_init(uv_barrier_t* barrier, unsigned int count);
  1553. UV_EXTERN void uv_barrier_destroy(uv_barrier_t* barrier);
  1554. UV_EXTERN int uv_barrier_wait(uv_barrier_t* barrier);
  1555. UV_EXTERN void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex);
  1556. UV_EXTERN int uv_cond_timedwait(uv_cond_t* cond,
  1557. uv_mutex_t* mutex,
  1558. uint64_t timeout);
  1559. UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
  1560. UV_EXTERN int uv_key_create(uv_key_t* key);
  1561. UV_EXTERN void uv_key_delete(uv_key_t* key);
  1562. UV_EXTERN void* uv_key_get(uv_key_t* key);
  1563. UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
  1564. UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv);
  1565. typedef void (*uv_thread_cb)(void* arg);
  1566. UV_EXTERN int uv_thread_create(uv_thread_t* tid, uv_thread_cb entry, void* arg);
  1567. typedef enum {
  1568. UV_THREAD_NO_FLAGS = 0x00,
  1569. UV_THREAD_HAS_STACK_SIZE = 0x01
  1570. } uv_thread_create_flags;
  1571. struct uv_thread_options_s {
  1572. unsigned int flags;
  1573. size_t stack_size;
  1574. /* More fields may be added at any time. */
  1575. };
  1576. typedef struct uv_thread_options_s uv_thread_options_t;
  1577. UV_EXTERN int uv_thread_create_ex(uv_thread_t* tid,
  1578. const uv_thread_options_t* params,
  1579. uv_thread_cb entry,
  1580. void* arg);
  1581. UV_EXTERN uv_thread_t uv_thread_self(void);
  1582. UV_EXTERN int uv_thread_join(uv_thread_t *tid);
  1583. UV_EXTERN int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2);
  1584. /* The presence of these unions force similar struct layout. */
  1585. #define XX(_, name) uv_ ## name ## _t name;
  1586. union uv_any_handle {
  1587. UV_HANDLE_TYPE_MAP(XX)
  1588. };
  1589. union uv_any_req {
  1590. UV_REQ_TYPE_MAP(XX)
  1591. };
  1592. #undef XX
  1593. struct uv_loop_s {
  1594. /* User data - use this for whatever. */
  1595. void* data;
  1596. /* Loop reference counting. */
  1597. unsigned int active_handles;
  1598. void* handle_queue[2];
  1599. union {
  1600. void* unused;
  1601. unsigned int count;
  1602. } active_reqs;
  1603. /* Internal storage for future extensions. */
  1604. void* internal_fields;
  1605. /* Internal flag to signal loop stop. */
  1606. unsigned int stop_flag;
  1607. UV_LOOP_PRIVATE_FIELDS
  1608. };
  1609. UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
  1610. UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
  1611. /* Don't export the private CPP symbols. */
  1612. #undef UV_HANDLE_TYPE_PRIVATE
  1613. #undef UV_REQ_TYPE_PRIVATE
  1614. #undef UV_REQ_PRIVATE_FIELDS
  1615. #undef UV_STREAM_PRIVATE_FIELDS
  1616. #undef UV_TCP_PRIVATE_FIELDS
  1617. #undef UV_PREPARE_PRIVATE_FIELDS
  1618. #undef UV_CHECK_PRIVATE_FIELDS
  1619. #undef UV_IDLE_PRIVATE_FIELDS
  1620. #undef UV_ASYNC_PRIVATE_FIELDS
  1621. #undef UV_TIMER_PRIVATE_FIELDS
  1622. #undef UV_GETADDRINFO_PRIVATE_FIELDS
  1623. #undef UV_GETNAMEINFO_PRIVATE_FIELDS
  1624. #undef UV_FS_REQ_PRIVATE_FIELDS
  1625. #undef UV_WORK_PRIVATE_FIELDS
  1626. #undef UV_FS_EVENT_PRIVATE_FIELDS
  1627. #undef UV_SIGNAL_PRIVATE_FIELDS
  1628. #undef UV_LOOP_PRIVATE_FIELDS
  1629. #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
  1630. #undef UV__ERR
  1631. #ifdef __cplusplus
  1632. }
  1633. #endif
  1634. #endif /* UV_H */