uv.h 60 KB

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