Turn audio into a shareable video. forked from nypublicradio/audiogram

win.h 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. #ifndef _WIN32_WINNT
  22. # define _WIN32_WINNT 0x0600
  23. #endif
  24. #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
  25. typedef intptr_t ssize_t;
  26. # define SSIZE_MAX INTPTR_MAX
  27. # define _SSIZE_T_
  28. # define _SSIZE_T_DEFINED
  29. #endif
  30. #include <winsock2.h>
  31. #if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
  32. typedef struct pollfd {
  33. SOCKET fd;
  34. short events;
  35. short revents;
  36. } WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;
  37. #endif
  38. #ifndef LOCALE_INVARIANT
  39. # define LOCALE_INVARIANT 0x007f
  40. #endif
  41. #include <mswsock.h>
  42. #include <ws2tcpip.h>
  43. #include <windows.h>
  44. #include <process.h>
  45. #include <signal.h>
  46. #include <fcntl.h>
  47. #include <sys/stat.h>
  48. #if defined(_MSC_VER) && _MSC_VER < 1600
  49. # include "uv/stdint-msvc2008.h"
  50. #else
  51. # include <stdint.h>
  52. #endif
  53. #include "uv/tree.h"
  54. #include "uv/threadpool.h"
  55. #define MAX_PIPENAME_LEN 256
  56. #ifndef S_IFLNK
  57. # define S_IFLNK 0xA000
  58. #endif
  59. /* Additional signals supported by uv_signal and or uv_kill. The CRT defines
  60. * the following signals already:
  61. *
  62. * #define SIGINT 2
  63. * #define SIGILL 4
  64. * #define SIGABRT_COMPAT 6
  65. * #define SIGFPE 8
  66. * #define SIGSEGV 11
  67. * #define SIGTERM 15
  68. * #define SIGBREAK 21
  69. * #define SIGABRT 22
  70. *
  71. * The additional signals have values that are common on other Unix
  72. * variants (Linux and Darwin)
  73. */
  74. #define SIGHUP 1
  75. #define SIGKILL 9
  76. #define SIGWINCH 28
  77. /* Redefine NSIG to take SIGWINCH into consideration */
  78. #if defined(NSIG) && NSIG <= SIGWINCH
  79. # undef NSIG
  80. #endif
  81. #ifndef NSIG
  82. # define NSIG SIGWINCH + 1
  83. #endif
  84. /* The CRT defines SIGABRT_COMPAT as 6, which equals SIGABRT on many unix-like
  85. * platforms. However MinGW doesn't define it, so we do. */
  86. #ifndef SIGABRT_COMPAT
  87. # define SIGABRT_COMPAT 6
  88. #endif
  89. /*
  90. * Guids and typedefs for winsock extension functions
  91. * Mingw32 doesn't have these :-(
  92. */
  93. #ifndef WSAID_ACCEPTEX
  94. # define WSAID_ACCEPTEX \
  95. {0xb5367df1, 0xcbac, 0x11cf, \
  96. {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
  97. # define WSAID_CONNECTEX \
  98. {0x25a207b9, 0xddf3, 0x4660, \
  99. {0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}}
  100. # define WSAID_GETACCEPTEXSOCKADDRS \
  101. {0xb5367df2, 0xcbac, 0x11cf, \
  102. {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
  103. # define WSAID_DISCONNECTEX \
  104. {0x7fda2e11, 0x8630, 0x436f, \
  105. {0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57}}
  106. # define WSAID_TRANSMITFILE \
  107. {0xb5367df0, 0xcbac, 0x11cf, \
  108. {0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}}
  109. typedef BOOL (PASCAL *LPFN_ACCEPTEX)
  110. (SOCKET sListenSocket,
  111. SOCKET sAcceptSocket,
  112. PVOID lpOutputBuffer,
  113. DWORD dwReceiveDataLength,
  114. DWORD dwLocalAddressLength,
  115. DWORD dwRemoteAddressLength,
  116. LPDWORD lpdwBytesReceived,
  117. LPOVERLAPPED lpOverlapped);
  118. typedef BOOL (PASCAL *LPFN_CONNECTEX)
  119. (SOCKET s,
  120. const struct sockaddr* name,
  121. int namelen,
  122. PVOID lpSendBuffer,
  123. DWORD dwSendDataLength,
  124. LPDWORD lpdwBytesSent,
  125. LPOVERLAPPED lpOverlapped);
  126. typedef void (PASCAL *LPFN_GETACCEPTEXSOCKADDRS)
  127. (PVOID lpOutputBuffer,
  128. DWORD dwReceiveDataLength,
  129. DWORD dwLocalAddressLength,
  130. DWORD dwRemoteAddressLength,
  131. LPSOCKADDR* LocalSockaddr,
  132. LPINT LocalSockaddrLength,
  133. LPSOCKADDR* RemoteSockaddr,
  134. LPINT RemoteSockaddrLength);
  135. typedef BOOL (PASCAL *LPFN_DISCONNECTEX)
  136. (SOCKET hSocket,
  137. LPOVERLAPPED lpOverlapped,
  138. DWORD dwFlags,
  139. DWORD reserved);
  140. typedef BOOL (PASCAL *LPFN_TRANSMITFILE)
  141. (SOCKET hSocket,
  142. HANDLE hFile,
  143. DWORD nNumberOfBytesToWrite,
  144. DWORD nNumberOfBytesPerSend,
  145. LPOVERLAPPED lpOverlapped,
  146. LPTRANSMIT_FILE_BUFFERS lpTransmitBuffers,
  147. DWORD dwFlags);
  148. typedef PVOID RTL_SRWLOCK;
  149. typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
  150. #endif
  151. typedef int (WSAAPI* LPFN_WSARECV)
  152. (SOCKET socket,
  153. LPWSABUF buffers,
  154. DWORD buffer_count,
  155. LPDWORD bytes,
  156. LPDWORD flags,
  157. LPWSAOVERLAPPED overlapped,
  158. LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
  159. typedef int (WSAAPI* LPFN_WSARECVFROM)
  160. (SOCKET socket,
  161. LPWSABUF buffers,
  162. DWORD buffer_count,
  163. LPDWORD bytes,
  164. LPDWORD flags,
  165. struct sockaddr* addr,
  166. LPINT addr_len,
  167. LPWSAOVERLAPPED overlapped,
  168. LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
  169. #ifndef _NTDEF_
  170. typedef LONG NTSTATUS;
  171. typedef NTSTATUS *PNTSTATUS;
  172. #endif
  173. #ifndef RTL_CONDITION_VARIABLE_INIT
  174. typedef PVOID CONDITION_VARIABLE, *PCONDITION_VARIABLE;
  175. #endif
  176. typedef struct _AFD_POLL_HANDLE_INFO {
  177. HANDLE Handle;
  178. ULONG Events;
  179. NTSTATUS Status;
  180. } AFD_POLL_HANDLE_INFO, *PAFD_POLL_HANDLE_INFO;
  181. typedef struct _AFD_POLL_INFO {
  182. LARGE_INTEGER Timeout;
  183. ULONG NumberOfHandles;
  184. ULONG Exclusive;
  185. AFD_POLL_HANDLE_INFO Handles[1];
  186. } AFD_POLL_INFO, *PAFD_POLL_INFO;
  187. #define UV_MSAFD_PROVIDER_COUNT 3
  188. /**
  189. * It should be possible to cast uv_buf_t[] to WSABUF[]
  190. * see http://msdn.microsoft.com/en-us/library/ms741542(v=vs.85).aspx
  191. */
  192. typedef struct uv_buf_t {
  193. ULONG len;
  194. char* base;
  195. } uv_buf_t;
  196. typedef int uv_file;
  197. typedef SOCKET uv_os_sock_t;
  198. typedef HANDLE uv_os_fd_t;
  199. typedef int uv_pid_t;
  200. typedef HANDLE uv_thread_t;
  201. typedef HANDLE uv_sem_t;
  202. typedef CRITICAL_SECTION uv_mutex_t;
  203. /* This condition variable implementation is based on the SetEvent solution
  204. * (section 3.2) at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
  205. * We could not use the SignalObjectAndWait solution (section 3.4) because
  206. * it want the 2nd argument (type uv_mutex_t) of uv_cond_wait() and
  207. * uv_cond_timedwait() to be HANDLEs, but we use CRITICAL_SECTIONs.
  208. */
  209. typedef union {
  210. CONDITION_VARIABLE cond_var;
  211. struct {
  212. unsigned int waiters_count;
  213. CRITICAL_SECTION waiters_count_lock;
  214. HANDLE signal_event;
  215. HANDLE broadcast_event;
  216. } unused_; /* TODO: retained for ABI compatibility; remove me in v2.x. */
  217. } uv_cond_t;
  218. typedef union {
  219. struct {
  220. unsigned int num_readers_;
  221. CRITICAL_SECTION num_readers_lock_;
  222. HANDLE write_semaphore_;
  223. } state_;
  224. /* TODO: remove me in v2.x. */
  225. struct {
  226. SRWLOCK unused_;
  227. } unused1_;
  228. /* TODO: remove me in v2.x. */
  229. struct {
  230. uv_mutex_t unused1_;
  231. uv_mutex_t unused2_;
  232. } unused2_;
  233. } uv_rwlock_t;
  234. typedef struct {
  235. unsigned int n;
  236. unsigned int count;
  237. uv_mutex_t mutex;
  238. uv_sem_t turnstile1;
  239. uv_sem_t turnstile2;
  240. } uv_barrier_t;
  241. typedef struct {
  242. DWORD tls_index;
  243. } uv_key_t;
  244. #define UV_ONCE_INIT { 0, NULL }
  245. typedef struct uv_once_s {
  246. unsigned char ran;
  247. HANDLE event;
  248. } uv_once_t;
  249. /* Platform-specific definitions for uv_spawn support. */
  250. typedef unsigned char uv_uid_t;
  251. typedef unsigned char uv_gid_t;
  252. typedef struct uv__dirent_s {
  253. int d_type;
  254. char d_name[1];
  255. } uv__dirent_t;
  256. #define UV_DIR_PRIVATE_FIELDS \
  257. HANDLE dir_handle; \
  258. WIN32_FIND_DATAW find_data; \
  259. BOOL need_find_call;
  260. #define HAVE_DIRENT_TYPES
  261. #define UV__DT_DIR UV_DIRENT_DIR
  262. #define UV__DT_FILE UV_DIRENT_FILE
  263. #define UV__DT_LINK UV_DIRENT_LINK
  264. #define UV__DT_FIFO UV_DIRENT_FIFO
  265. #define UV__DT_SOCKET UV_DIRENT_SOCKET
  266. #define UV__DT_CHAR UV_DIRENT_CHAR
  267. #define UV__DT_BLOCK UV_DIRENT_BLOCK
  268. /* Platform-specific definitions for uv_dlopen support. */
  269. #define UV_DYNAMIC FAR WINAPI
  270. typedef struct {
  271. HMODULE handle;
  272. char* errmsg;
  273. } uv_lib_t;
  274. #define UV_LOOP_PRIVATE_FIELDS \
  275. /* The loop's I/O completion port */ \
  276. HANDLE iocp; \
  277. /* The current time according to the event loop. in msecs. */ \
  278. uint64_t time; \
  279. /* Tail of a single-linked circular queue of pending reqs. If the queue */ \
  280. /* is empty, tail_ is NULL. If there is only one item, */ \
  281. /* tail_->next_req == tail_ */ \
  282. uv_req_t* pending_reqs_tail; \
  283. /* Head of a single-linked list of closed handles */ \
  284. uv_handle_t* endgame_handles; \
  285. /* TODO(bnoordhuis) Stop heap-allocating |timer_heap| in libuv v2.x. */ \
  286. void* timer_heap; \
  287. /* Lists of active loop (prepare / check / idle) watchers */ \
  288. uv_prepare_t* prepare_handles; \
  289. uv_check_t* check_handles; \
  290. uv_idle_t* idle_handles; \
  291. /* This pointer will refer to the prepare/check/idle handle whose */ \
  292. /* callback is scheduled to be called next. This is needed to allow */ \
  293. /* safe removal from one of the lists above while that list being */ \
  294. /* iterated over. */ \
  295. uv_prepare_t* next_prepare_handle; \
  296. uv_check_t* next_check_handle; \
  297. uv_idle_t* next_idle_handle; \
  298. /* This handle holds the peer sockets for the fast variant of uv_poll_t */ \
  299. SOCKET poll_peer_sockets[UV_MSAFD_PROVIDER_COUNT]; \
  300. /* Counter to keep track of active tcp streams */ \
  301. unsigned int active_tcp_streams; \
  302. /* Counter to keep track of active udp streams */ \
  303. unsigned int active_udp_streams; \
  304. /* Counter to started timer */ \
  305. uint64_t timer_counter; \
  306. /* Threadpool */ \
  307. void* wq[2]; \
  308. uv_mutex_t wq_mutex; \
  309. uv_async_t wq_async;
  310. #define UV_REQ_TYPE_PRIVATE \
  311. /* TODO: remove the req suffix */ \
  312. UV_ACCEPT, \
  313. UV_FS_EVENT_REQ, \
  314. UV_POLL_REQ, \
  315. UV_PROCESS_EXIT, \
  316. UV_READ, \
  317. UV_UDP_RECV, \
  318. UV_WAKEUP, \
  319. UV_SIGNAL_REQ,
  320. #define UV_REQ_PRIVATE_FIELDS \
  321. union { \
  322. /* Used by I/O operations */ \
  323. struct { \
  324. OVERLAPPED overlapped; \
  325. size_t queued_bytes; \
  326. } io; \
  327. } u; \
  328. struct uv_req_s* next_req;
  329. #define UV_WRITE_PRIVATE_FIELDS \
  330. int coalesced; \
  331. uv_buf_t write_buffer; \
  332. HANDLE event_handle; \
  333. HANDLE wait_handle;
  334. #define UV_CONNECT_PRIVATE_FIELDS \
  335. /* empty */
  336. #define UV_SHUTDOWN_PRIVATE_FIELDS \
  337. /* empty */
  338. #define UV_UDP_SEND_PRIVATE_FIELDS \
  339. /* empty */
  340. #define UV_PRIVATE_REQ_TYPES \
  341. typedef struct uv_pipe_accept_s { \
  342. UV_REQ_FIELDS \
  343. HANDLE pipeHandle; \
  344. struct uv_pipe_accept_s* next_pending; \
  345. } uv_pipe_accept_t; \
  346. \
  347. typedef struct uv_tcp_accept_s { \
  348. UV_REQ_FIELDS \
  349. SOCKET accept_socket; \
  350. char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \
  351. HANDLE event_handle; \
  352. HANDLE wait_handle; \
  353. struct uv_tcp_accept_s* next_pending; \
  354. } uv_tcp_accept_t; \
  355. \
  356. typedef struct uv_read_s { \
  357. UV_REQ_FIELDS \
  358. HANDLE event_handle; \
  359. HANDLE wait_handle; \
  360. } uv_read_t;
  361. #define uv_stream_connection_fields \
  362. unsigned int write_reqs_pending; \
  363. uv_shutdown_t* shutdown_req;
  364. #define uv_stream_server_fields \
  365. uv_connection_cb connection_cb;
  366. #define UV_STREAM_PRIVATE_FIELDS \
  367. unsigned int reqs_pending; \
  368. int activecnt; \
  369. uv_read_t read_req; \
  370. union { \
  371. struct { uv_stream_connection_fields } conn; \
  372. struct { uv_stream_server_fields } serv; \
  373. } stream;
  374. #define uv_tcp_server_fields \
  375. uv_tcp_accept_t* accept_reqs; \
  376. unsigned int processed_accepts; \
  377. uv_tcp_accept_t* pending_accepts; \
  378. LPFN_ACCEPTEX func_acceptex;
  379. #define uv_tcp_connection_fields \
  380. uv_buf_t read_buffer; \
  381. LPFN_CONNECTEX func_connectex;
  382. #define UV_TCP_PRIVATE_FIELDS \
  383. SOCKET socket; \
  384. int delayed_error; \
  385. union { \
  386. struct { uv_tcp_server_fields } serv; \
  387. struct { uv_tcp_connection_fields } conn; \
  388. } tcp;
  389. #define UV_UDP_PRIVATE_FIELDS \
  390. SOCKET socket; \
  391. unsigned int reqs_pending; \
  392. int activecnt; \
  393. uv_req_t recv_req; \
  394. uv_buf_t recv_buffer; \
  395. struct sockaddr_storage recv_from; \
  396. int recv_from_len; \
  397. uv_udp_recv_cb recv_cb; \
  398. uv_alloc_cb alloc_cb; \
  399. LPFN_WSARECV func_wsarecv; \
  400. LPFN_WSARECVFROM func_wsarecvfrom;
  401. #define uv_pipe_server_fields \
  402. int pending_instances; \
  403. uv_pipe_accept_t* accept_reqs; \
  404. uv_pipe_accept_t* pending_accepts;
  405. #define uv_pipe_connection_fields \
  406. uv_timer_t* eof_timer; \
  407. uv_write_t dummy; /* TODO: retained for ABI compat; remove this in v2.x. */ \
  408. DWORD ipc_remote_pid; \
  409. union { \
  410. uint32_t payload_remaining; \
  411. uint64_t dummy; /* TODO: retained for ABI compat; remove this in v2.x. */ \
  412. } ipc_data_frame; \
  413. void* ipc_xfer_queue[2]; \
  414. int ipc_xfer_queue_length; \
  415. uv_write_t* non_overlapped_writes_tail; \
  416. CRITICAL_SECTION readfile_thread_lock; \
  417. volatile HANDLE readfile_thread_handle;
  418. #define UV_PIPE_PRIVATE_FIELDS \
  419. HANDLE handle; \
  420. WCHAR* name; \
  421. union { \
  422. struct { uv_pipe_server_fields } serv; \
  423. struct { uv_pipe_connection_fields } conn; \
  424. } pipe;
  425. /* TODO: put the parser states in an union - TTY handles are always half-duplex
  426. * so read-state can safely overlap write-state. */
  427. #define UV_TTY_PRIVATE_FIELDS \
  428. HANDLE handle; \
  429. union { \
  430. struct { \
  431. /* Used for readable TTY handles */ \
  432. /* TODO: remove me in v2.x. */ \
  433. HANDLE unused_; \
  434. uv_buf_t read_line_buffer; \
  435. HANDLE read_raw_wait; \
  436. /* Fields used for translating win keystrokes into vt100 characters */ \
  437. char last_key[8]; \
  438. unsigned char last_key_offset; \
  439. unsigned char last_key_len; \
  440. WCHAR last_utf16_high_surrogate; \
  441. INPUT_RECORD last_input_record; \
  442. } rd; \
  443. struct { \
  444. /* Used for writable TTY handles */ \
  445. /* utf8-to-utf16 conversion state */ \
  446. unsigned int utf8_codepoint; \
  447. unsigned char utf8_bytes_left; \
  448. /* eol conversion state */ \
  449. unsigned char previous_eol; \
  450. /* ansi parser state */ \
  451. unsigned char ansi_parser_state; \
  452. unsigned char ansi_csi_argc; \
  453. unsigned short ansi_csi_argv[4]; \
  454. COORD saved_position; \
  455. WORD saved_attributes; \
  456. } wr; \
  457. } tty;
  458. #define UV_POLL_PRIVATE_FIELDS \
  459. SOCKET socket; \
  460. /* Used in fast mode */ \
  461. SOCKET peer_socket; \
  462. AFD_POLL_INFO afd_poll_info_1; \
  463. AFD_POLL_INFO afd_poll_info_2; \
  464. /* Used in fast and slow mode. */ \
  465. uv_req_t poll_req_1; \
  466. uv_req_t poll_req_2; \
  467. unsigned char submitted_events_1; \
  468. unsigned char submitted_events_2; \
  469. unsigned char mask_events_1; \
  470. unsigned char mask_events_2; \
  471. unsigned char events;
  472. #define UV_TIMER_PRIVATE_FIELDS \
  473. void* heap_node[3]; \
  474. int unused; \
  475. uint64_t timeout; \
  476. uint64_t repeat; \
  477. uint64_t start_id; \
  478. uv_timer_cb timer_cb;
  479. #define UV_ASYNC_PRIVATE_FIELDS \
  480. struct uv_req_s async_req; \
  481. uv_async_cb async_cb; \
  482. /* char to avoid alignment issues */ \
  483. char volatile async_sent;
  484. #define UV_PREPARE_PRIVATE_FIELDS \
  485. uv_prepare_t* prepare_prev; \
  486. uv_prepare_t* prepare_next; \
  487. uv_prepare_cb prepare_cb;
  488. #define UV_CHECK_PRIVATE_FIELDS \
  489. uv_check_t* check_prev; \
  490. uv_check_t* check_next; \
  491. uv_check_cb check_cb;
  492. #define UV_IDLE_PRIVATE_FIELDS \
  493. uv_idle_t* idle_prev; \
  494. uv_idle_t* idle_next; \
  495. uv_idle_cb idle_cb;
  496. #define UV_HANDLE_PRIVATE_FIELDS \
  497. uv_handle_t* endgame_next; \
  498. unsigned int flags;
  499. #define UV_GETADDRINFO_PRIVATE_FIELDS \
  500. struct uv__work work_req; \
  501. uv_getaddrinfo_cb getaddrinfo_cb; \
  502. void* alloc; \
  503. WCHAR* node; \
  504. WCHAR* service; \
  505. /* The addrinfoW field is used to store a pointer to the hints, and */ \
  506. /* later on to store the result of GetAddrInfoW. The final result will */ \
  507. /* be converted to struct addrinfo* and stored in the addrinfo field. */ \
  508. struct addrinfoW* addrinfow; \
  509. struct addrinfo* addrinfo; \
  510. int retcode;
  511. #define UV_GETNAMEINFO_PRIVATE_FIELDS \
  512. struct uv__work work_req; \
  513. uv_getnameinfo_cb getnameinfo_cb; \
  514. struct sockaddr_storage storage; \
  515. int flags; \
  516. char host[NI_MAXHOST]; \
  517. char service[NI_MAXSERV]; \
  518. int retcode;
  519. #define UV_PROCESS_PRIVATE_FIELDS \
  520. struct uv_process_exit_s { \
  521. UV_REQ_FIELDS \
  522. } exit_req; \
  523. BYTE* child_stdio_buffer; \
  524. int exit_signal; \
  525. HANDLE wait_handle; \
  526. HANDLE process_handle; \
  527. volatile char exit_cb_pending;
  528. #define UV_FS_PRIVATE_FIELDS \
  529. struct uv__work work_req; \
  530. int flags; \
  531. DWORD sys_errno_; \
  532. union { \
  533. /* TODO: remove me in 0.9. */ \
  534. WCHAR* pathw; \
  535. int fd; \
  536. } file; \
  537. union { \
  538. struct { \
  539. int mode; \
  540. WCHAR* new_pathw; \
  541. int file_flags; \
  542. int fd_out; \
  543. unsigned int nbufs; \
  544. uv_buf_t* bufs; \
  545. int64_t offset; \
  546. uv_buf_t bufsml[4]; \
  547. } info; \
  548. struct { \
  549. double atime; \
  550. double mtime; \
  551. } time; \
  552. } fs;
  553. #define UV_WORK_PRIVATE_FIELDS \
  554. struct uv__work work_req;
  555. #define UV_FS_EVENT_PRIVATE_FIELDS \
  556. struct uv_fs_event_req_s { \
  557. UV_REQ_FIELDS \
  558. } req; \
  559. HANDLE dir_handle; \
  560. int req_pending; \
  561. uv_fs_event_cb cb; \
  562. WCHAR* filew; \
  563. WCHAR* short_filew; \
  564. WCHAR* dirw; \
  565. char* buffer;
  566. #define UV_SIGNAL_PRIVATE_FIELDS \
  567. RB_ENTRY(uv_signal_s) tree_entry; \
  568. struct uv_req_s signal_req; \
  569. unsigned long pending_signum;
  570. #ifndef F_OK
  571. #define F_OK 0
  572. #endif
  573. #ifndef R_OK
  574. #define R_OK 4
  575. #endif
  576. #ifndef W_OK
  577. #define W_OK 2
  578. #endif
  579. #ifndef X_OK
  580. #define X_OK 1
  581. #endif
  582. /* fs open() flags supported on this platform: */
  583. #define UV_FS_O_APPEND _O_APPEND
  584. #define UV_FS_O_CREAT _O_CREAT
  585. #define UV_FS_O_EXCL _O_EXCL
  586. #define UV_FS_O_FILEMAP 0x20000000
  587. #define UV_FS_O_RANDOM _O_RANDOM
  588. #define UV_FS_O_RDONLY _O_RDONLY
  589. #define UV_FS_O_RDWR _O_RDWR
  590. #define UV_FS_O_SEQUENTIAL _O_SEQUENTIAL
  591. #define UV_FS_O_SHORT_LIVED _O_SHORT_LIVED
  592. #define UV_FS_O_TEMPORARY _O_TEMPORARY
  593. #define UV_FS_O_TRUNC _O_TRUNC
  594. #define UV_FS_O_WRONLY _O_WRONLY
  595. /* fs open() flags supported on other platforms (or mapped on this platform): */
  596. #define UV_FS_O_DIRECT 0x02000000 /* FILE_FLAG_NO_BUFFERING */
  597. #define UV_FS_O_DIRECTORY 0
  598. #define UV_FS_O_DSYNC 0x04000000 /* FILE_FLAG_WRITE_THROUGH */
  599. #define UV_FS_O_EXLOCK 0x10000000 /* EXCLUSIVE SHARING MODE */
  600. #define UV_FS_O_NOATIME 0
  601. #define UV_FS_O_NOCTTY 0
  602. #define UV_FS_O_NOFOLLOW 0
  603. #define UV_FS_O_NONBLOCK 0
  604. #define UV_FS_O_SYMLINK 0
  605. #define UV_FS_O_SYNC 0x08000000 /* FILE_FLAG_WRITE_THROUGH */