2011-04-18 18:10:18 +00:00
|
|
|
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-04-18 17:25:03 +00:00
|
|
|
#ifndef _WIN32_WINNT
|
2011-08-03 22:07:33 +00:00
|
|
|
# define _WIN32_WINNT 0x0502
|
2011-04-18 17:25:03 +00:00
|
|
|
#endif
|
|
|
|
|
|
2011-04-12 18:39:14 +00:00
|
|
|
#include <stdint.h>
|
2011-03-30 03:03:56 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
|
#include <mswsock.h>
|
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
2011-04-12 18:39:14 +00:00
|
|
|
#include "tree.h"
|
|
|
|
|
|
2011-07-02 00:54:17 +00:00
|
|
|
#define MAX_PIPENAME_LEN 256
|
|
|
|
|
|
2011-03-23 12:56:06 +00:00
|
|
|
/**
|
2011-05-13 14:15:02 +00:00
|
|
|
* It should be possible to cast uv_buf_t[] to WSABUF[]
|
2011-03-30 03:03:56 +00:00
|
|
|
* see http://msdn.microsoft.com/en-us/library/ms741542(v=vs.85).aspx
|
2011-03-23 12:56:06 +00:00
|
|
|
*/
|
2011-05-13 14:15:02 +00:00
|
|
|
typedef struct uv_buf_t {
|
2011-03-30 03:03:56 +00:00
|
|
|
ULONG len;
|
|
|
|
|
char* base;
|
2011-05-13 14:15:02 +00:00
|
|
|
} uv_buf_t;
|
2011-03-28 08:55:29 +00:00
|
|
|
|
2011-07-30 01:30:07 +00:00
|
|
|
#define UV_REQ_TYPE_PRIVATE \
|
|
|
|
|
/* TODO: remove the req suffix */ \
|
|
|
|
|
UV_ARES_EVENT_REQ, \
|
|
|
|
|
UV_ARES_CLEANUP_REQ, \
|
|
|
|
|
UV_GETADDRINFO_REQ, \
|
|
|
|
|
UV_PROCESS_EXIT, \
|
2011-08-24 02:31:36 +00:00
|
|
|
UV_PROCESS_CLOSE, \
|
|
|
|
|
UV_UDP_RECV
|
2011-07-30 01:30:07 +00:00
|
|
|
|
2011-06-02 01:19:47 +00:00
|
|
|
#define UV_REQ_PRIVATE_FIELDS \
|
2011-04-14 20:34:13 +00:00
|
|
|
union { \
|
|
|
|
|
/* Used by I/O operations */ \
|
2011-05-09 21:54:52 +00:00
|
|
|
struct { \
|
|
|
|
|
OVERLAPPED overlapped; \
|
|
|
|
|
size_t queued_bytes; \
|
|
|
|
|
}; \
|
2011-04-14 20:34:13 +00:00
|
|
|
}; \
|
2011-06-07 16:07:28 +00:00
|
|
|
struct uv_req_s* next_req;
|
2011-07-14 00:52:19 +00:00
|
|
|
|
2011-07-14 01:01:44 +00:00
|
|
|
#define UV_WRITE_PRIVATE_FIELDS \
|
|
|
|
|
/* empty */
|
|
|
|
|
|
|
|
|
|
#define UV_CONNECT_PRIVATE_FIELDS \
|
|
|
|
|
/* empty */
|
|
|
|
|
|
|
|
|
|
#define UV_SHUTDOWN_PRIVATE_FIELDS \
|
|
|
|
|
/* empty */
|
|
|
|
|
|
2011-08-24 02:31:36 +00:00
|
|
|
#define UV_UDP_SEND_PRIVATE_FIELDS \
|
|
|
|
|
/* empty */
|
|
|
|
|
|
2011-07-15 22:33:31 +00:00
|
|
|
#define UV_PRIVATE_REQ_TYPES \
|
|
|
|
|
typedef struct uv_pipe_accept_s { \
|
|
|
|
|
UV_REQ_FIELDS \
|
|
|
|
|
HANDLE pipeHandle; \
|
|
|
|
|
struct uv_pipe_accept_s* next_pending; \
|
2011-08-11 20:18:07 +00:00
|
|
|
} uv_pipe_accept_t; \
|
|
|
|
|
typedef struct uv_tcp_accept_s { \
|
|
|
|
|
UV_REQ_FIELDS \
|
|
|
|
|
SOCKET accept_socket; \
|
|
|
|
|
char accept_buffer[sizeof(struct sockaddr_storage) * 2 + 32]; \
|
|
|
|
|
struct uv_tcp_accept_s* next_pending; \
|
|
|
|
|
} uv_tcp_accept_t;
|
2011-07-15 22:33:31 +00:00
|
|
|
|
2011-07-02 00:54:17 +00:00
|
|
|
#define uv_stream_connection_fields \
|
|
|
|
|
unsigned int write_reqs_pending; \
|
2011-07-14 01:01:44 +00:00
|
|
|
uv_shutdown_t* shutdown_req;
|
2011-07-02 00:54:17 +00:00
|
|
|
|
|
|
|
|
#define uv_stream_server_fields \
|
|
|
|
|
uv_connection_cb connection_cb;
|
2011-03-30 03:03:56 +00:00
|
|
|
|
2011-07-01 00:39:27 +00:00
|
|
|
#define UV_STREAM_PRIVATE_FIELDS \
|
2011-07-02 00:54:17 +00:00
|
|
|
unsigned int reqs_pending; \
|
2011-06-02 04:04:01 +00:00
|
|
|
uv_alloc_cb alloc_cb; \
|
2011-06-08 19:59:05 +00:00
|
|
|
uv_read_cb read_cb; \
|
2011-07-14 01:01:44 +00:00
|
|
|
uv_req_t read_req; \
|
2011-07-02 00:54:17 +00:00
|
|
|
union { \
|
|
|
|
|
struct { uv_stream_connection_fields }; \
|
|
|
|
|
struct { uv_stream_server_fields }; \
|
|
|
|
|
};
|
2011-05-07 22:17:44 +00:00
|
|
|
|
2011-08-15 23:49:57 +00:00
|
|
|
#define uv_tcp_server_fields \
|
2011-08-11 20:18:07 +00:00
|
|
|
uv_tcp_accept_t* accept_reqs; \
|
|
|
|
|
uv_tcp_accept_t* pending_accepts;
|
2011-08-15 23:49:57 +00:00
|
|
|
|
|
|
|
|
#define uv_tcp_connection_fields \
|
|
|
|
|
uv_buf_t read_buffer;
|
|
|
|
|
|
|
|
|
|
#define UV_TCP_PRIVATE_FIELDS \
|
|
|
|
|
SOCKET socket; \
|
2011-08-23 18:33:26 +00:00
|
|
|
uv_err_t bind_error; \
|
2011-08-15 23:49:57 +00:00
|
|
|
union { \
|
|
|
|
|
struct { uv_tcp_server_fields }; \
|
|
|
|
|
struct { uv_tcp_connection_fields }; \
|
|
|
|
|
};
|
2011-07-02 00:54:17 +00:00
|
|
|
|
2011-08-24 02:31:36 +00:00
|
|
|
#define UV_UDP_PRIVATE_FIELDS \
|
|
|
|
|
SOCKET socket; \
|
|
|
|
|
unsigned int reqs_pending; \
|
|
|
|
|
uv_req_t recv_req; \
|
|
|
|
|
uv_buf_t recv_buffer; \
|
|
|
|
|
struct sockaddr_storage recv_from; \
|
|
|
|
|
int recv_from_len; \
|
|
|
|
|
uv_udp_recv_cb recv_cb; \
|
|
|
|
|
uv_alloc_cb alloc_cb;
|
2011-08-19 21:22:30 +00:00
|
|
|
|
2011-07-02 00:54:17 +00:00
|
|
|
#define uv_pipe_server_fields \
|
2011-07-15 22:33:31 +00:00
|
|
|
uv_pipe_accept_t accept_reqs[4]; \
|
|
|
|
|
uv_pipe_accept_t* pending_accepts;
|
2011-07-02 00:54:17 +00:00
|
|
|
|
|
|
|
|
#define uv_pipe_connection_fields \
|
2011-08-26 00:02:20 +00:00
|
|
|
uv_timer_t* eof_timer;
|
2011-07-02 00:54:17 +00:00
|
|
|
|
|
|
|
|
#define UV_PIPE_PRIVATE_FIELDS \
|
2011-08-26 00:02:20 +00:00
|
|
|
HANDLE handle; \
|
2011-07-20 06:45:00 +00:00
|
|
|
wchar_t* name; \
|
2011-05-03 03:21:15 +00:00
|
|
|
union { \
|
2011-07-02 00:54:17 +00:00
|
|
|
struct { uv_pipe_server_fields }; \
|
|
|
|
|
struct { uv_pipe_connection_fields }; \
|
2011-05-07 22:17:44 +00:00
|
|
|
};
|
|
|
|
|
|
2011-06-02 01:19:47 +00:00
|
|
|
#define UV_TIMER_PRIVATE_FIELDS \
|
|
|
|
|
RB_ENTRY(uv_timer_s) tree_entry; \
|
2011-05-17 00:24:58 +00:00
|
|
|
int64_t due; \
|
|
|
|
|
int64_t repeat; \
|
2011-06-17 16:39:18 +00:00
|
|
|
uv_timer_cb timer_cb;
|
2011-05-07 22:27:12 +00:00
|
|
|
|
2011-06-02 01:19:47 +00:00
|
|
|
#define UV_ASYNC_PRIVATE_FIELDS \
|
2011-05-16 19:38:20 +00:00
|
|
|
struct uv_req_s async_req; \
|
2011-07-14 01:01:44 +00:00
|
|
|
uv_async_cb async_cb; \
|
2011-05-09 02:25:34 +00:00
|
|
|
/* char to avoid alignment issues */ \
|
|
|
|
|
char volatile async_sent;
|
|
|
|
|
|
2011-06-17 16:39:18 +00:00
|
|
|
#define UV_PREPARE_PRIVATE_FIELDS \
|
|
|
|
|
uv_prepare_t* prepare_prev; \
|
|
|
|
|
uv_prepare_t* prepare_next; \
|
|
|
|
|
uv_prepare_cb prepare_cb;
|
2011-06-02 01:19:47 +00:00
|
|
|
|
2011-06-17 16:39:18 +00:00
|
|
|
#define UV_CHECK_PRIVATE_FIELDS \
|
|
|
|
|
uv_check_t* check_prev; \
|
|
|
|
|
uv_check_t* check_next; \
|
|
|
|
|
uv_check_cb check_cb;
|
|
|
|
|
|
|
|
|
|
#define UV_IDLE_PRIVATE_FIELDS \
|
|
|
|
|
uv_idle_t* idle_prev; \
|
|
|
|
|
uv_idle_t* idle_next; \
|
|
|
|
|
uv_idle_cb idle_cb;
|
2011-06-02 01:19:47 +00:00
|
|
|
|
|
|
|
|
#define UV_HANDLE_PRIVATE_FIELDS \
|
2011-05-16 19:38:20 +00:00
|
|
|
uv_handle_t* endgame_next; \
|
2011-08-23 18:36:52 +00:00
|
|
|
unsigned int flags;
|
2011-05-24 17:29:08 +00:00
|
|
|
|
2011-06-20 16:41:57 +00:00
|
|
|
#define UV_ARES_TASK_PRIVATE_FIELDS \
|
|
|
|
|
struct uv_req_s ares_req; \
|
|
|
|
|
SOCKET sock; \
|
|
|
|
|
HANDLE h_wait; \
|
|
|
|
|
WSAEVENT h_event; \
|
|
|
|
|
HANDLE h_close_event;
|
2011-05-24 17:29:08 +00:00
|
|
|
|
2011-06-22 23:29:50 +00:00
|
|
|
#define UV_GETADDRINFO_PRIVATE_FIELDS \
|
|
|
|
|
struct uv_req_s getadddrinfo_req; \
|
|
|
|
|
uv_getaddrinfo_cb getaddrinfo_cb; \
|
|
|
|
|
void* alloc; \
|
|
|
|
|
wchar_t* node; \
|
|
|
|
|
wchar_t* service; \
|
|
|
|
|
struct addrinfoW* hints; \
|
|
|
|
|
struct addrinfoW* res; \
|
|
|
|
|
int retcode;
|
|
|
|
|
|
2011-07-27 18:05:32 +00:00
|
|
|
#define UV_PROCESS_PRIVATE_FIELDS \
|
2011-07-30 01:30:07 +00:00
|
|
|
struct uv_process_exit_s { \
|
|
|
|
|
UV_REQ_FIELDS \
|
|
|
|
|
} exit_req; \
|
|
|
|
|
struct uv_process_close_s { \
|
|
|
|
|
UV_REQ_FIELDS \
|
|
|
|
|
} close_req; \
|
|
|
|
|
struct uv_process_stdio_s { \
|
|
|
|
|
uv_pipe_t* server_pipe; \
|
|
|
|
|
HANDLE child_pipe; \
|
|
|
|
|
} stdio_pipes[3]; \
|
|
|
|
|
int exit_signal; \
|
2011-08-02 02:58:43 +00:00
|
|
|
DWORD spawn_errno; \
|
2011-07-30 01:30:07 +00:00
|
|
|
HANDLE wait_handle; \
|
|
|
|
|
HANDLE process_handle; \
|
|
|
|
|
HANDLE close_handle;
|
|
|
|
|
|
|
|
|
|
int uv_utf16_to_utf8(const wchar_t* utf16Buffer, size_t utf16Size, char* utf8Buffer, size_t utf8Size);
|
2011-06-22 23:29:50 +00:00
|
|
|
int uv_utf8_to_utf16(const char* utf8Buffer, wchar_t* utf16Buffer, size_t utf16Size);
|