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,
96 void uv_tcp_close(uv_loop_t* loop, uv_tcp_t* tcp);
97 void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle);
99 int uv__tcp_xfer_export(uv_tcp_t* handle,
101 uv__ipc_socket_xfer_type_t* xfer_type,
102 uv__ipc_socket_xfer_info_t* xfer_info);
103 int uv__tcp_xfer_import(uv_tcp_t* tcp,
104 uv__ipc_socket_xfer_type_t xfer_type,
105 uv__ipc_socket_xfer_info_t* xfer_info);
111 void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, uv_req_t* req);
112 void uv_process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle,
115 void uv_udp_close(uv_loop_t* loop, uv_udp_t* handle);
116 void uv_udp_endgame(uv_loop_t* loop, uv_udp_t* handle);
122 int uv__create_stdio_pipe_pair(uv_loop_t* loop,
123 uv_pipe_t* parent_pipe, HANDLE* child_pipe_ptr, unsigned int flags);
125 int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
126 int uv_pipe_accept(uv_pipe_t* server, uv_stream_t* client);
127 int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb,
129 void uv__pipe_read_stop(uv_pipe_t* handle);
130 int uv__pipe_write(uv_loop_t* loop,
133 const uv_buf_t bufs[],
135 uv_stream_t* send_handle,
138 void uv_process_pipe_read_req(uv_loop_t* loop, uv_pipe_t* handle,
140 void uv_process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle,
142 void uv_process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle,
144 void uv_process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
146 void uv_process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle,
149 void uv_pipe_close(uv_loop_t* loop, uv_pipe_t* handle);
150 void uv_pipe_cleanup(uv_loop_t* loop, uv_pipe_t* handle);
151 void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle);
157 void uv_console_init(void);
159 int uv_tty_read_start(uv_tty_t* handle, uv_alloc_cb alloc_cb,
161 int uv_tty_read_stop(uv_tty_t* handle);
162 int uv_tty_write(uv_loop_t* loop, uv_write_t* req, uv_tty_t* handle,
163 const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb);
164 int uv__tty_try_write(uv_tty_t* handle, const uv_buf_t bufs[],
166 void uv_tty_close(uv_tty_t* handle);
168 void uv_process_tty_read_req(uv_loop_t* loop, uv_tty_t* handle,
170 void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
173 * uv_process_tty_accept_req() is a stub to keep DELEGATE_STREAM_REQ working
174 * TODO: find a way to remove it
176 void uv_process_tty_accept_req(uv_loop_t* loop, uv_tty_t* handle,
179 * uv_process_tty_connect_req() is a stub to keep DELEGATE_STREAM_REQ working
180 * TODO: find a way to remove it
182 void uv_process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle,
185 void uv_tty_endgame(uv_loop_t* loop, uv_tty_t* handle);
191 void uv_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
194 int uv_poll_close(uv_loop_t* loop, uv_poll_t* handle);
195 void uv_poll_endgame(uv_loop_t* loop, uv_poll_t* handle);
201 void uv_loop_watcher_endgame(uv_loop_t* loop, uv_handle_t* handle);
203 void uv_prepare_invoke(uv_loop_t* loop);
204 void uv_check_invoke(uv_loop_t* loop);
205 void uv_idle_invoke(uv_loop_t* loop);
207 void uv__once_init(void);
213 void uv_async_close(uv_loop_t* loop, uv_async_t* handle);
214 void uv_async_endgame(uv_loop_t* loop, uv_async_t* handle);
216 void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
223 void uv_signals_init(void);
224 int uv__signal_dispatch(int signum);
226 void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle);
227 void uv_signal_endgame(uv_loop_t* loop, uv_signal_t* handle);
229 void uv_process_signal_req(uv_loop_t* loop, uv_signal_t* handle,
236 void uv_process_proc_exit(uv_loop_t* loop, uv_process_t* handle);
237 void uv_process_close(uv_loop_t* loop, uv_process_t* handle);
238 void uv_process_endgame(uv_loop_t* loop, uv_process_t* handle);
244 int uv_translate_sys_error(int sys_errno);
250 void uv_fs_init(void);
256 void uv_process_fs_event_req(uv_loop_t* loop, uv_req_t* req,
257 uv_fs_event_t* handle);
258 void uv_fs_event_close(uv_loop_t* loop, uv_fs_event_t* handle);
259 void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);
265 void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
271 void uv__util_init(void);
273 uint64_t uv__hrtime(unsigned int scale);
274 __declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
275 int uv__getpwuid_r(uv_passwd_t* pwd);
276 int uv__convert_utf16_to_utf8(const WCHAR* utf16, int utf16len, char** utf8);
277 int uv__convert_utf8_to_utf16(const char* utf8, int utf8len, WCHAR** utf16);
279 typedef int (WINAPI *uv__peersockfunc)(SOCKET, struct sockaddr*, int*);
281 int uv__getsockpeername(const uv_handle_t* handle,
282 uv__peersockfunc func,
283 struct sockaddr* name,
287 int uv__random_rtlgenrandom(void* buf, size_t buflen);
291 * Process stdio handles.
293 int uv__stdio_create(uv_loop_t* loop,
294 const uv_process_options_t* options,
296 void uv__stdio_destroy(BYTE* buffer);
297 void uv__stdio_noinherit(BYTE* buffer);
298 int uv__stdio_verify(BYTE* buffer, WORD size);
299 WORD uv__stdio_size(BYTE* buffer);
300 HANDLE uv__stdio_handle(BYTE* buffer, int fd);
304 * Winapi and ntapi utility functions
306 void uv_winapi_init(void);
310 * Winsock utility functions
312 void uv_winsock_init(void);
314 int uv_ntstatus_to_winsock_error(NTSTATUS status);
316 BOOL uv_get_acceptex_function(SOCKET socket, LPFN_ACCEPTEX* target);
317 BOOL uv_get_connectex_function(SOCKET socket, LPFN_CONNECTEX* target);
319 int WSAAPI uv_wsarecv_workaround(SOCKET socket, WSABUF* buffers,
320 DWORD buffer_count, DWORD* bytes, DWORD* flags, WSAOVERLAPPED *overlapped,
321 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
322 int WSAAPI uv_wsarecvfrom_workaround(SOCKET socket, WSABUF* buffers,
323 DWORD buffer_count, DWORD* bytes, DWORD* flags, struct sockaddr* addr,
324 int* addr_len, WSAOVERLAPPED *overlapped,
325 LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine);
327 int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO* info_in,
328 AFD_POLL_INFO* info_out, OVERLAPPED* overlapped);
330 /* Whether there are any non-IFS LSPs stacked on TCP */
331 extern int uv_tcp_non_ifs_lsp_ipv4;
332 extern int uv_tcp_non_ifs_lsp_ipv6;
334 /* Ip address used to bind to any port at any interface */
335 extern struct sockaddr_in uv_addr_ip4_any_;
336 extern struct sockaddr_in6 uv_addr_ip6_any_;
339 * Wake all loops with fake message
341 void uv__wake_all_loops(void);
344 * Init system wake-up detection
346 void uv__init_detect_system_wakeup(void);
348 #endif /* UV_WIN_INTERNAL_H_ */