uv.h 66 KB

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