1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
22 #ifndef UV_WIN_INTERNAL_H_
23 #define UV_WIN_INTERNAL_H_
26 # pragma warning(push,1)
30 #include "../uv-common.h"
37 # define INLINE __inline
38 # define UV_THREAD_LOCAL __declspec( thread )
40 # define INLINE inline
41 # define UV_THREAD_LOCAL __thread
47 extern UV_THREAD_LOCAL int uv__crt_assert_enabled;
49 #define UV_BEGIN_DISABLE_CRT_ASSERT() \
51 int uv__saved_crt_assert_enabled = uv__crt_assert_enabled; \
52 uv__crt_assert_enabled = FALSE;
55 #define UV_END_DISABLE_CRT_ASSERT() \
56 uv__crt_assert_enabled = uv__saved_crt_assert_enabled; \
60 #define UV_BEGIN_DISABLE_CRT_ASSERT()
61 #define UV_END_DISABLE_CRT_ASSERT()
69 UV__IPC_SOCKET_XFER_NONE = 0,
70 UV__IPC_SOCKET_XFER_TCP_CONNECTION,
71 UV__IPC_SOCKET_XFER_TCP_SERVER
72 } uv__ipc_socket_xfer_type_t;
75 WSAPROTOCOL_INFOW socket_info;
76 uint32_t delayed_error;
77 } uv__ipc_socket_xfer_info_t;
79 int uv__tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb);
80 int uv__tcp_accept(uv_tcp_t* server, uv_tcp_t* client);
81 int uv__tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
83 int uv__tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle,
84 const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
85 int uv__tcp_try_write(uv_tcp_t* handle, const uv_buf_t bufs[],
88 void uv__process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req);
89 void uv__process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
91 void uv__process_tcp_accept_req(uv_loop_t* loop, uv_tcp_t* handle,
93 void uv__process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle,
95 void uv__process_tcp_shutdown_req(uv_loop_t* loop,
99 void uv__tcp_close(uv_loop_t* loop, uv_tcp_t* tcp);
100 void uv__tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);
102 int uv__tcp_xfer_export(uv_tcp_t* handle,
104 uv__ipc_socket_xfer_type_t* xfer_type,
105 uv__ipc_socket_xfer_info_t* xfer_info);
106 int uv__tcp_xfer_import(uv_tcp_t* tcp,
107 uv__ipc_socket_xfer_type_t xfer_type,
108 uv__ipc_socket_xfer_info_t* xfer_info);
114 void uv__process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, uv_req_t* req);
115 void uv__process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
118 void uv__udp_close(uv_loop_t* loop, uv_udp_t* handle);
119 void uv__udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
125 int uv__create_stdio_pipe_pair(uv_loop_t* loop,
126 uv_pipe_t* parent_pipe, HANDLE* child_pipe_ptr, unsigned int flags);
128 int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
129 int uv__pipe_accept(uv_pipe_t* server, uv_stream_t* client);
130 int uv__pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
132 void uv__pipe_read_stop(uv_pipe_t* handle);
133 int uv__pipe_write(uv_loop_t* loop,
136 const uv_buf_t bufs[],
138 uv_stream_t* send_handle,
140 void uv__pipe_shutdown(uv_loop_t* loop, uv_pipe_t* handle, uv_shutdown_t* req);
142 void uv__process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
144 void uv__process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
146 void uv__process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle,
148 void uv__process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
150 void uv__process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
153 void uv__pipe_close(uv_loop_t* loop, uv_pipe_t* handle);
154 void uv__pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle);
160 void uv__console_init(void);
162 int uv__tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
164 int uv__tty_read_stop(uv_tty_t* handle);
165 int uv__tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
166 const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
167 int uv__tty_try_write(uv_tty_t* handle, const uv_buf_t bufs[],
169 void uv__tty_close(uv_tty_t* handle);
171 void uv__process_tty_read_req(uv_loop_t* loop, uv_tty_t* handle,
173 void uv__process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
176 * uv__process_tty_accept_req() is a stub to keep DELEGATE_STREAM_REQ working
177 * TODO: find a way to remove it
179 void uv__process_tty_accept_req(uv_loop_t* loop, uv_tty_t* handle,
182 * uv__process_tty_connect_req() is a stub to keep DELEGATE_STREAM_REQ working
183 * TODO: find a way to remove it
185 void uv__process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle,
187 void uv__process_tty_shutdown_req(uv_loop_t* loop,
190 void uv__tty_endgame(uv_loop_t* loop, uv_tty_t* handle);
196 void uv__process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
199 int uv__poll_close(uv_loop_t* loop, uv_poll_t* handle);
200 void uv__poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
206 void uv__loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle);
208 void uv__prepare_invoke(uv_loop_t* loop);
209 void uv__check_invoke(uv_loop_t* loop);
210 void uv__idle_invoke(uv_loop_t* loop);
212 void uv__once_init(void);
218 void uv__async_close(uv_loop_t* loop, uv_async_t* handle);
219 void uv__async_endgame(uv_loop_t* loop, uv_async_t* handle);
221 void uv__process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
228 void uv__signals_init(void);
229 int uv__signal_dispatch(int signum);
231 void uv__signal_close(uv_loop_t* loop, uv_signal_t* handle);
232 void uv__signal_endgame(uv_loop_t* loop, uv_signal_t* handle);
234 void uv__process_signal_req(uv_loop_t* loop, uv_signal_t* handle,
241 void uv__process_proc_exit(uv_loop_t* loop, uv_process_t* handle);
242 void uv__process_close(uv_loop_t* loop, uv_process_t* handle);
243 void uv__process_endgame(uv_loop_t* loop, uv_process_t* handle);
249 void uv__fs_init(void);
255 void uv__process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
256 uv_fs_event_t* handle);
257 void uv__fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle);
258 void uv__fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);
264 void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
270 void uv__util_init(void);
272 uint64_t uv__hrtime(unsigned int scale);
273 __declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
274 int uv__getpwuid_r(uv_passwd_t* pwd);
275 int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8);
276 int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16);
278 typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*);
280 int uv__getsockpeername(const uv_handle_t* handle,
281 uv__peersockfunc func,
282 struct sockaddr* name,
286 int uv__random_rtlgenrandom(void* buf, size_t buflen);
290 * Process stdio handles.
292 int uv__stdio_create(uv_loop_t* loop,
293 const uv_process_options_t* options,
295 void uv__stdio_destroy(BYTE* buffer);
296 void uv__stdio_noinherit(BYTE* buffer);
297 int uv__stdio_verify(BYTE* buffer, WORD size);
298 WORD uv__stdio_size(BYTE* buffer);
299 HANDLE uv__stdio_handle(BYTE* buffer, int fd);
303 * Winapi and ntapi utility functions
305 void uv__winapi_init(void);
309 * Winsock utility functions
311 void uv__winsock_init(void);
313 int uv__ntstatus_to_winsock_error(NTSTATUS status);
315 BOOL uv__get_acceptex_function(SOCKET socket, LPFN_ACCEPTEX* target);
316 BOOL uv__get_connectex_function(SOCKET socket, LPFN_CONNECTEX* target);
318 int WSAAPI uv__wsarecv_workaround(SOCKET socket, WSABUF* buffers,
319 DWORD buffer_count, DWORD* bytes, DWORD* flags, WSAOVERLAPPED *overlapped,
320 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
321 int WSAAPI uv__wsarecvfrom_workaround(SOCKET socket, WSABUF* buffers,
322 DWORD buffer_count, DWORD* bytes, DWORD* flags, struct sockaddr* addr,
323 int* addr_len, WSAOVERLAPPED *overlapped,
324 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
326 int WSAAPI uv__msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in,
327 AFD_POLL_INFO* info_out, OVERLAPPED* overlapped);
329 /* Whether there are any non-IFS LSPs stacked on TCP */
330 extern int uv_tcp_non_ifs_lsp_ipv4;
331 extern int uv_tcp_non_ifs_lsp_ipv6;
333 /* Ip address used to bind to any port at any interface */
334 extern struct sockaddr_in uv_addr_ip4_any_;
335 extern struct sockaddr_in6 uv_addr_ip6_any_;
338 * Wake all loops with fake message
340 void uv__wake_all_loops(void);
343 * Init system wake-up detection
345 void uv__init_detect_system_wakeup(void);
347 #endif /* UV_WIN_INTERNAL_H_ */