uv.h 56 KB

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