1
0

uv.h 53 KB

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