53 sizeof enable) == -1) {
54 return WSAGetLastError();
65 sizeof enable) == -1) {
66 return WSAGetLastError();
69 if (enable && setsockopt(
socket,
73 sizeof delay) == -1) {
74 return WSAGetLastError();
90 if (
handle->socket != INVALID_SOCKET)
95 return WSAGetLastError();
99 if (!SetHandleInformation((
HANDLE)
socket, HANDLE_FLAG_INHERIT, 0))
100 return GetLastError();
111 return GetLastError();
124 if (!SetFileCompletionNotificationModes((
HANDLE)
socket, sfcnm_flags))
125 return GetLastError();
168 handle->socket = INVALID_SOCKET;
172 handle->tcp.serv.processed_accepts = 0;
173 handle->delayed_error = 0;
184 if (sock == INVALID_SOCKET) {
185 err = WSAGetLastError();
211 uv_tcp_accept_t*
req;
215 handle->stream.conn.write_reqs_pending == 0) {
221 err = ERROR_OPERATION_ABORTED;
222 }
else if (shutdown(
handle->socket,
SD_SEND) == SOCKET_ERROR) {
223 err = WSAGetLastError();
226 if (
handle->stream.conn.shutdown_req->cb) {
227 handle->stream.conn.shutdown_req->cb(
handle->stream.conn.shutdown_req,
237 handle->reqs_pending == 0) {
241 closesocket(
handle->socket);
242 handle->socket = INVALID_SOCKET;
251 UnregisterWait(
req->wait_handle);
254 if (
req->event_handle !=
NULL) {
255 CloseHandle(
req->event_handle);
268 UnregisterWait(
handle->read_req.wait_handle);
272 CloseHandle(
handle->read_req.event_handle);
278 loop->active_tcp_streams--;
297 unsigned int flags) {
301 if (
handle->socket == INVALID_SOCKET) {
306 return ERROR_INVALID_PARAMETER;
309 if (sock == INVALID_SOCKET) {
310 return WSAGetLastError();
329 setsockopt(
handle->socket,
339 if (
r == SOCKET_ERROR) {
340 err = WSAGetLastError();
341 if (
err == WSAEADDRINUSE) {
365 if (!PostQueuedCompletionStatus(
handle->loop->iocp,
366 req->u.io.overlapped.InternalHigh,
368 &
req->u.io.overlapped)) {
384 if (!PostQueuedCompletionStatus(
handle->loop->iocp,
385 req->u.io.overlapped.InternalHigh,
387 &
req->u.io.overlapped)) {
397 SOCKET accept_socket;
401 assert(
req->accept_socket == INVALID_SOCKET);
412 if (accept_socket == INVALID_SOCKET) {
420 if (!SetHandleInformation((
HANDLE) accept_socket, HANDLE_FLAG_INHERIT, 0)) {
424 closesocket(accept_socket);
429 memset(&(
req->u.io.overlapped), 0,
sizeof(
req->u.io.overlapped));
432 req->u.io.overlapped.hEvent = (
HANDLE) ((ULONG_PTR)
req->event_handle | 1);
435 success =
handle->tcp.serv.func_acceptex(
handle->socket,
437 (
void*)
req->accept_buffer,
439 sizeof(
struct sockaddr_storage),
440 sizeof(struct sockaddr_storage),
442 &
req->u.io.overlapped);
446 req->accept_socket = accept_socket;
451 req->accept_socket = accept_socket;
455 !RegisterWaitForSingleObject(&
req->wait_handle,
457 INFINITE, WT_EXECUTEINWAITTHREAD)) {
467 closesocket(accept_socket);
470 CloseHandle(
req->event_handle);
487 memset(&
req->u.io.overlapped, 0,
sizeof(
req->u.io.overlapped));
497 if (
handle->tcp.conn.read_buffer.base ==
NULL ||
498 handle->tcp.conn.read_buffer.len == 0) {
511 memset(&(
req->u.io.overlapped), 0,
sizeof(
req->u.io.overlapped));
514 req->u.io.overlapped.hEvent = (
HANDLE) ((ULONG_PTR)
req->event_handle | 1);
518 result = WSARecv(
handle->socket,
523 &
req->u.io.overlapped,
531 req->u.io.overlapped.InternalHigh =
bytes;
537 !RegisterWaitForSingleObject(&
req->wait_handle,
539 INFINITE, WT_EXECUTEINWAITTHREAD)) {
552 struct linger l = { 1, 0 };
567 unsigned int i, simultaneous_accepts;
568 uv_tcp_accept_t*
req;
574 handle->stream.serv.connection_cb =
cb;
581 if (
handle->delayed_error) {
582 return handle->delayed_error;
592 if (
handle->delayed_error)
593 return handle->delayed_error;
596 if (!
handle->tcp.serv.func_acceptex) {
598 return WSAEAFNOSUPPORT;
604 return WSAGetLastError();
608 handle->stream.serv.connection_cb =
cb;
615 handle->tcp.serv.accept_reqs =
617 if (!
handle->tcp.serv.accept_reqs) {
621 for (
i = 0;
i < simultaneous_accepts;
i++) {
624 req->accept_socket = INVALID_SOCKET;
630 if (
req->event_handle ==
NULL) {
646 req->accept_socket = INVALID_SOCKET;
662 uv_tcp_accept_t*
req = server->tcp.serv.pending_accepts;
666 return WSAEWOULDBLOCK;
669 if (
req->accept_socket == INVALID_SOCKET) {
685 closesocket(
req->accept_socket);
693 server->tcp.serv.pending_accepts =
req->next_pending;
695 req->accept_socket = INVALID_SOCKET;
705 server->tcp.serv.processed_accepts++;
708 server->tcp.serv.processed_accepts = 0;
720 loop->active_tcp_streams++;
731 handle->read_cb = read_cb;
732 handle->alloc_cb = alloc_cb;
756 if (storage->ss_family ==
AF_INET) {
758 return in4->
sin_addr.S_un.S_un_b.s_b1 == 127;
760 if (storage->ss_family ==
AF_INET6) {
762 for (
i = 0;
i < 7; ++
i) {
773 OSVERSIONINFOW os_info;
777 if (os_info.dwMajorVersion < 10)
779 if (os_info.dwMajorVersion > 10)
781 if (os_info.dwMinorVersion > 0)
783 return os_info.dwBuildNumber >= 16299;
794 struct sockaddr_storage converted;
803 if (
handle->delayed_error) {
804 return handle->delayed_error;
818 if (
handle->delayed_error)
819 return handle->delayed_error;
822 if (!
handle->tcp.conn.func_connectex) {
824 return WSAEAFNOSUPPORT;
833 memset(&retransmit_ioctl, 0,
sizeof(retransmit_ioctl));
839 sizeof(retransmit_ioctl),
850 memset(&
req->u.io.overlapped, 0,
sizeof(
req->u.io.overlapped));
852 success =
handle->tcp.conn.func_connectex(
handle->socket,
853 (
const struct sockaddr*) &converted,
858 &
req->u.io.overlapped);
870 return WSAGetLastError();
915 memset(&(
req->u.io.overlapped), 0,
sizeof(
req->u.io.overlapped));
918 if (
req->event_handle ==
NULL) {
921 req->u.io.overlapped.hEvent = (
HANDLE) ((ULONG_PTR)
req->event_handle | 1);
925 result = WSASend(
handle->socket,
930 &
req->u.io.overlapped,
935 req->u.io.queued_bytes = 0;
937 handle->stream.conn.write_reqs_pending++;
944 handle->stream.conn.write_reqs_pending++;
946 handle->write_queue_size +=
req->u.io.queued_bytes;
948 !RegisterWaitForSingleObject(&
req->wait_handle,
950 INFINITE, WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE)) {
956 req->u.io.queued_bytes = 0;
958 handle->stream.conn.write_reqs_pending++;
970 unsigned int nbufs) {
974 if (
handle->stream.conn.write_reqs_pending > 0)
977 result = WSASend(
handle->socket,
985 if (result == SOCKET_ERROR)
1013 if (
err == WSAECONNABORTED) {
1016 err = WSAECONNRESET;
1026 if (
req->u.io.overlapped.InternalHigh > 0) {
1029 req->u.io.overlapped.InternalHigh,
1030 &
handle->tcp.conn.read_buffer);
1032 if (
req->u.io.overlapped.InternalHigh <
handle->tcp.conn.read_buffer.len) {
1062 if (WSARecv(
handle->socket,
1068 NULL) != SOCKET_ERROR) {
1085 err = WSAGetLastError();
1086 if (
err == WSAEWOULDBLOCK) {
1094 if (
err == WSAECONNABORTED) {
1097 err = WSAECONNRESET;
1127 handle->write_queue_size -=
req->u.io.queued_bytes;
1133 UnregisterWait(
req->wait_handle);
1136 if (
req->event_handle !=
NULL) {
1137 CloseHandle(
req->event_handle);
1144 if (
err == UV_ECONNABORTED) {
1151 handle->stream.conn.write_reqs_pending--;
1152 if (
handle->stream.conn.shutdown_req !=
NULL &&
1153 handle->stream.conn.write_reqs_pending == 0) {
1163 uv_tcp_accept_t*
req = (uv_tcp_accept_t*) raw_req;
1171 if (
req->accept_socket == INVALID_SOCKET) {
1175 if (
handle->stream.serv.connection_cb) {
1182 setsockopt(
req->accept_socket,
1184 SO_UPDATE_ACCEPT_CONTEXT,
1186 sizeof(
handle->socket)) == 0) {
1187 req->next_pending =
handle->tcp.serv.pending_accepts;
1191 if (
handle->stream.serv.connection_cb) {
1198 closesocket(
req->accept_socket);
1199 req->accept_socket = INVALID_SOCKET;
1221 err = ERROR_OPERATION_ABORTED;
1222 }
else if (setsockopt(
handle->socket,
1229 loop->active_tcp_streams++;
1231 err = WSAGetLastError();
1256 return ERROR_NOT_SUPPORTED;
1258 if (
handle->delayed_error == 0 &&
1260 handle->delayed_error = WSAGetLastError();
1266 return WSAGetLastError();
1286 socket = WSASocketW(FROM_PROTOCOL_INFO,
1291 WSA_FLAG_OVERLAPPED);
1293 if (
socket == INVALID_SOCKET) {
1294 return WSAGetLastError();
1312 tcp->loop->active_tcp_streams++;
1320 if (
handle->socket != INVALID_SOCKET) {
1339 if (
handle->socket != INVALID_SOCKET) {
1390 SOCKET
socket = tcp->socket;
1418 return GetLastError();
1427 int close_socket = 1;
1434 shutdown(tcp->socket,
SD_SEND);
1450 tcp->tcp.serv.accept_reqs !=
NULL) {
1463 uv_tcp_accept_t*
req = &tcp->tcp.serv.accept_reqs[
i];
1464 if (
req->accept_socket != INVALID_SOCKET &&
1465 !HasOverlappedIoCompleted(&
req->u.io.overlapped)) {
1466 closesocket(
req->accept_socket);
1467 req->accept_socket = INVALID_SOCKET;
1484 closesocket(tcp->socket);
1485 tcp->socket = INVALID_SOCKET;
1492 if (tcp->reqs_pending == 0) {
1499 WSAPROTOCOL_INFOW protocol_info;
1502 struct sockaddr_storage saddr;
1506 opt_len = (
int)
sizeof protocol_info;
1507 if (getsockopt(sock,
1510 (
char*) &protocol_info,
1511 &opt_len) == SOCKET_ERROR) {
1518 protocol_info.iAddressFamily,
1525 saddr_len =
sizeof(saddr);
1529 saddr_len =
sizeof(saddr);
1547 unsigned int flags) {
static mcore_handle handle
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd domain
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
void uv_fatal_error(const int errorno, const char *syscall)
#define DECREASE_ACTIVE_COUNT(loop, handle)
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
#define INCREASE_ACTIVE_COUNT(loop, handle)
#define uv__handle_close(handle)
#define DECREASE_PENDING_REQ_COUNT(handle)
#define uv__handle_closing(handle)
#define INVALID_HANDLE_VALUE
return memset(p, 0, total)
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol struct sockaddr addrlen
assert(limit<=UINT32_MAX/2)
static INLINE void uv_insert_pending_req(uv_loop_t *loop, uv_req_t *req)
#define GET_REQ_SOCK_ERROR(req)
#define UNREGISTER_HANDLE_REQ(loop, handle, req)
#define UV_SUCCEEDED_WITH_IOCP(result)
#define REGISTER_HANDLE_REQ(loop, handle, req)
#define UV_SUCCEEDED_WITHOUT_IOCP(result)
#define SET_REQ_ERROR(req, error)
static struct sockaddr static addrlen listen
static struct sockaddr static addrlen static backlog const void static flags void flags
static INLINE void uv_stream_init(uv_loop_t *loop, uv_stream_t *handle, uv_handle_type type)
static INLINE void uv_connection_init(uv_stream_t *handle)
UCHAR MaxSynRetransmissions
struct in6_addr sin6_addr
WSAPROTOCOL_INFOW socket_info
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
struct sockaddr_in uv_addr_ip4_any_
uv__ipc_socket_xfer_type_t
@ UV__IPC_SOCKET_XFER_TCP_CONNECTION
@ UV__IPC_SOCKET_XFER_TCP_SERVER
BOOL uv_get_connectex_function(SOCKET socket, LPFN_CONNECTEX *target)
int uv_tcp_non_ifs_lsp_ipv4
int uv_tcp_non_ifs_lsp_ipv6
BOOL uv_get_acceptex_function(SOCKET socket, LPFN_ACCEPTEX *target)
struct sockaddr_in6 uv_addr_ip6_any_
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
int uv__tcp_keepalive(int fd, int on, unsigned int delay)
int uv__tcp_connect(uv_connect_t *req, uv_tcp_t *handle, const struct sockaddr *addr, unsigned int addrlen, uv_connect_cb cb)
int uv__tcp_bind(uv_tcp_t *tcp, const struct sockaddr *addr, unsigned int addrlen, unsigned int flags)
int uv_tcp_init(uv_loop_t *loop, uv_tcp_t *tcp)
int uv_tcp_close_reset(uv_tcp_t *handle, uv_close_cb close_cb)
int uv_tcp_listen(uv_tcp_t *tcp, int backlog, uv_connection_cb cb)
int uv_tcp_nodelay(uv_tcp_t *handle, int on)
int uv_tcp_open(uv_tcp_t *handle, uv_os_sock_t sock)
int uv_tcp_getpeername(const uv_tcp_t *handle, struct sockaddr *name, int *namelen)
int uv_tcp_simultaneous_accepts(uv_tcp_t *handle, int enable)
int uv_tcp_init_ex(uv_loop_t *loop, uv_tcp_t *tcp, unsigned int flags)
int uv_tcp_keepalive(uv_tcp_t *handle, int on, unsigned int delay)
int uv__tcp_nodelay(int fd, int on)
int uv_tcp_getsockname(const uv_tcp_t *handle, struct sockaddr *name, int *namelen)
size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs)
void * uv__malloc(size_t size)
@ UV_HANDLE_TCP_KEEPALIVE
@ UV_HANDLE_TCP_SOCKET_CLOSED
@ UV_HANDLE_TCP_SINGLE_ACCEPT
@ UV_HANDLE_SHARED_TCP_SOCKET
@ UV_HANDLE_TCP_ACCEPT_STATE_CHANGING
@ UV_HANDLE_SYNC_BYPASS_IOCP
#define UV_REQ_INIT(req, typ)
void(* uv_write_cb)(uv_write_t *req, int status)
void(* uv_connection_cb)(uv_stream_t *server, int status)
UV_EXTERN int uv_translate_sys_error(int sys_errno)
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
void(* uv_read_cb)(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
void(* uv_alloc_cb)(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
void(* uv_connect_cb)(uv_connect_t *req, int status)
void(* uv_close_cb)(uv_handle_t *handle)
void uv_tcp_endgame(uv_loop_t *loop, uv_tcp_t *handle)
int uv__tcp_xfer_import(uv_tcp_t *tcp, uv__ipc_socket_xfer_type_t xfer_type, uv__ipc_socket_xfer_info_t *xfer_info)
const unsigned int uv_simultaneous_server_accepts
static int uv_tcp_try_bind(uv_tcp_t *handle, const struct sockaddr *addr, unsigned int addrlen, unsigned int flags)
static int uv__is_fast_loopback_fail_supported()
int uv__tcp_try_write(uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
static void uv_tcp_queue_read(uv_loop_t *loop, uv_tcp_t *handle)
const unsigned int uv_active_tcp_streams_threshold
int uv__tcp_xfer_export(uv_tcp_t *handle, int target_pid, uv__ipc_socket_xfer_type_t *xfer_type, uv__ipc_socket_xfer_info_t *xfer_info)
static void CALLBACK post_completion(void *context, BOOLEAN timed_out)
static int uv_tcp_set_socket(uv_loop_t *loop, uv_tcp_t *handle, SOCKET socket, int family, int imported)
void uv_process_tcp_connect_req(uv_loop_t *loop, uv_tcp_t *handle, uv_connect_t *req)
void uv_tcp_close(uv_loop_t *loop, uv_tcp_t *tcp)
static int uv_tcp_try_cancel_io(uv_tcp_t *tcp)
int uv_tcp_read_start(uv_tcp_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
static int uv__is_loopback(const struct sockaddr_storage *storage)
void uv_process_tcp_write_req(uv_loop_t *loop, uv_tcp_t *handle, uv_write_t *req)
int uv_tcp_accept(uv_tcp_t *server, uv_tcp_t *client)
void uv_process_tcp_accept_req(uv_loop_t *loop, uv_tcp_t *handle, uv_req_t *raw_req)
static void uv_tcp_queue_accept(uv_tcp_t *handle, uv_tcp_accept_t *req)
int uv_tcp_write(uv_loop_t *loop, uv_write_t *req, uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
static void CALLBACK post_write_completion(void *context, BOOLEAN timed_out)
void uv_process_tcp_read_req(uv_loop_t *loop, uv_tcp_t *handle, uv_req_t *req)
static int uv_tcp_try_connect(uv_connect_t *req, uv_tcp_t *handle, const struct sockaddr *addr, unsigned int addrlen, uv_connect_cb cb)
sRtlGetVersion pRtlGetVersion
#define FILE_SKIP_SET_EVENT_ON_HANDLE
#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
#define TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS
#define SIO_TCP_INITIAL_RTO
int uv__convert_to_localhost_if_unspecified(const struct sockaddr *addr, struct sockaddr_storage *storage)
#define SO_UPDATE_CONNECT_CONTEXT