aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/unix/core.c12
-rw-r--r--src/unix/fs.c12
-rw-r--r--src/unix/internal.h11
-rw-r--r--src/unix/linux.c2
-rw-r--r--src/unix/qnx.c50
-rw-r--r--src/unix/stream.c2
-rw-r--r--src/unix/tcp.c50
-rw-r--r--src/unix/udp.c14
-rw-r--r--src/uv-common.c11
-rw-r--r--src/win/poll.c6
-rw-r--r--src/win/tcp.c126
-rw-r--r--src/win/thread.c2
-rw-r--r--src/win/util.c9
-rw-r--r--src/win/winapi.c10
-rw-r--r--src/win/winsock.h28
15 files changed, 248 insertions, 97 deletions
diff --git a/src/unix/core.c b/src/unix/core.c
index 1dde27bd..6e741628 100644
--- a/src/unix/core.c
+++ b/src/unix/core.c
@@ -275,7 +275,7 @@ void uv__make_close_pending(uv_handle_t* handle) {
int uv__getiovmax(void) {
#if defined(IOV_MAX)
return IOV_MAX;
-#elif defined(_SC_IOV_MAX)
+#elif defined(_SC_IOV_MAX) && !defined(__QNX__)
static _Atomic int iovmax_cached = -1;
int iovmax;
@@ -1611,6 +1611,10 @@ int uv_cpumask_size(void) {
}
int uv_os_getpriority(uv_pid_t pid, int* priority) {
+#if defined(__QNX__)
+ /* QNX priority is not process-based */
+ return UV_ENOSYS;
+#else
int r;
if (priority == NULL)
@@ -1624,10 +1628,15 @@ int uv_os_getpriority(uv_pid_t pid, int* priority) {
*priority = r;
return 0;
+#endif
}
int uv_os_setpriority(uv_pid_t pid, int priority) {
+#if defined(__QNX__)
+ /* QNX priority is not process-based */
+ return UV_ENOSYS;
+#else
if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
return UV_EINVAL;
@@ -1635,6 +1644,7 @@ int uv_os_setpriority(uv_pid_t pid, int priority) {
return UV__ERR(errno);
return 0;
+#endif
}
/**
diff --git a/src/unix/fs.c b/src/unix/fs.c
index 717f3fab..bd3f5962 100644
--- a/src/unix/fs.c
+++ b/src/unix/fs.c
@@ -211,7 +211,8 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
- || defined(__sun)
+ || defined(__sun) \
+ || defined(__QNX__)
static struct timespec uv__fs_to_timespec(double time) {
struct timespec ts;
@@ -248,7 +249,8 @@ static ssize_t uv__fs_futime(uv_fs_t* req) {
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
- || defined(__sun)
+ || defined(__sun) \
+ || defined(__QNX__)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
@@ -1147,7 +1149,8 @@ static ssize_t uv__fs_utime(uv_fs_t* req) {
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
- || defined(__sun)
+ || defined(__sun) \
+ || defined(__QNX__)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
@@ -1181,7 +1184,8 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) {
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
- || defined(__sun)
+ || defined(__sun) \
+ || defined(__QNX__)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
diff --git a/src/unix/internal.h b/src/unix/internal.h
index a1d7d436..d8c792f6 100644
--- a/src/unix/internal.h
+++ b/src/unix/internal.h
@@ -141,6 +141,11 @@ union uv__sockaddr {
/* Leans on the fact that, on Linux, POLLRDHUP == EPOLLRDHUP. */
#ifdef POLLRDHUP
# define UV__POLLRDHUP POLLRDHUP
+#elif defined(__QNX__)
+/* On QNX, POLLRDHUP is not available and the 0x2000 workaround
+ * leads to undefined bahavior.
+ */
+# define UV__POLLRDHUP 0
#else
# define UV__POLLRDHUP 0x2000
#endif
@@ -299,7 +304,11 @@ int uv__slurp(const char* filename, char* buf, size_t len);
/* tcp */
int uv__tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
int uv__tcp_nodelay(int fd, int on);
-int uv__tcp_keepalive(int fd, int on, unsigned int delay);
+int uv__tcp_keepalive(int fd,
+ int on,
+ unsigned int idle,
+ unsigned int intvl,
+ unsigned int cnt);
/* tty */
void uv__tty_close(uv_tty_t* handle);
diff --git a/src/unix/linux.c b/src/unix/linux.c
index ea3e2de0..77d079b7 100644
--- a/src/unix/linux.c
+++ b/src/unix/linux.c
@@ -2309,8 +2309,8 @@ static int uv__get_cgroupv2_constrained_cpu(const char* cgroup,
static const char cgroup_mount[] = "/sys/fs/cgroup";
const char* cgroup_trimmed;
char buf[1024];
- char full_path[256];
char path[256];
+ char full_path[sizeof(path) + sizeof("/cpu.max")];
char quota_buf[16];
char* last_slash;
int cgroup_size;
diff --git a/src/unix/qnx.c b/src/unix/qnx.c
index 57ea9dfd..d873165f 100644
--- a/src/unix/qnx.c
+++ b/src/unix/qnx.c
@@ -28,6 +28,14 @@
#include <sys/memmsg.h>
#include <sys/syspage.h>
#include <sys/procfs.h>
+#include <time.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#if __QNX__ >= 800
+#define cpuinfo_val cpuinfo
+#else
+#define cpuinfo_val new_cpuinfo
+#endif
static void
get_mem_info(uint64_t* totalmem, uint64_t* freemem) {
@@ -67,18 +75,44 @@ int uv_exepath(char* buffer, size_t* size) {
}
+static uint64_t uv__read_pidin_info(const char* what) {
+ uint64_t rc;
+ char* p;
+ char buf[2048];
+
+ FILE* fp = popen("pidin info", "r");
+ if (fp == NULL)
+ return 0;
+
+ size_t sz = fread(buf, 1, sizeof(buf) - 1, fp);
+ buf[sz] = '\0';
+
+ pclose(fp);
+
+ p = strstr(buf, what);
+ if (p == NULL)
+ return 0;
+
+ p += strlen(what);
+
+ rc = 0;
+ sscanf(p, "%" PRIu64 " MB", &rc);
+
+ return rc * 1024 * 1024;
+}
+
uint64_t uv_get_free_memory(void) {
- uint64_t totalmem;
uint64_t freemem;
- get_mem_info(&totalmem, &freemem);
+
+ freemem = uv__read_pidin_info("FreeMem:");
return freemem;
}
uint64_t uv_get_total_memory(void) {
uint64_t totalmem;
- uint64_t freemem;
- get_mem_info(&totalmem, &freemem);
+
+ totalmem = uv__read_pidin_info("MB/");
return totalmem;
}
@@ -113,15 +147,17 @@ int uv_resident_set_memory(size_t* rss) {
int uv_uptime(double* uptime) {
- struct qtime_entry* qtime = _SYSPAGE_ENTRY(_syspage_ptr, qtime);
- *uptime = (qtime->nsec / 1000000000.0);
+ struct timespec ts;
+ if(clock_gettime(CLOCK_MONOTONIC, &ts))
+ return UV__ERR(errno);
+ *uptime = (double)ts.tv_sec;
return 0;
}
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
struct cpuinfo_entry* cpuinfo =
- (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, new_cpuinfo);
+ (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, cpuinfo_val);
size_t cpuinfo_size = _SYSPAGE_ELEMENT_SIZE(_syspage_ptr, cpuinfo);
struct strings_entry* strings = _SYSPAGE_ENTRY(_syspage_ptr, strings);
int num_cpus = _syspage_ptr->num_cpu;
diff --git a/src/unix/stream.c b/src/unix/stream.c
index 18763b47..204f5a25 100644
--- a/src/unix/stream.c
+++ b/src/unix/stream.c
@@ -417,7 +417,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
/* TODO Use delay the user passed in. */
if ((stream->flags & UV_HANDLE_TCP_KEEPALIVE) &&
- uv__tcp_keepalive(fd, 1, 60)) {
+ uv__tcp_keepalive(fd, 1, 60, 1, 10)) {
return UV__ERR(errno);
}
}
diff --git a/src/unix/tcp.c b/src/unix/tcp.c
index 98970d75..1f59083e 100644
--- a/src/unix/tcp.c
+++ b/src/unix/tcp.c
@@ -445,9 +445,8 @@ int uv__tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
/* Start listening for connections. */
tcp->io_watcher.cb = uv__server_io;
- uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN);
- return 0;
+ return uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN);
}
@@ -466,22 +465,18 @@ int uv__tcp_nodelay(int fd, int on) {
#else
#define UV_KEEPALIVE_FACTOR(x)
#endif
-int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
- int idle;
- int intvl;
- int cnt;
-
- (void) &idle;
- (void) &intvl;
- (void) &cnt;
-
+int uv__tcp_keepalive(int fd,
+ int on,
+ unsigned int idle,
+ unsigned int intvl,
+ unsigned int cnt) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
return UV__ERR(errno);
if (!on)
return 0;
- if (delay < 1)
+ if (idle < 1 || intvl < 1 || cnt < 1)
return UV_EINVAL;
#ifdef __sun
@@ -507,13 +502,16 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
* The TCP connection will be aborted after certain amount of probes, which is set by TCP_KEEPCNT, without receiving response.
*/
- idle = delay;
- /* Kernel expects at least 10 seconds. */
+ /* Kernel expects at least 10 seconds for TCP_KEEPIDLE and TCP_KEEPINTVL. */
if (idle < 10)
idle = 10;
- /* Kernel expects at most 10 days. */
+ if (intvl < 10)
+ intvl = 10;
+ /* Kernel expects at most 10 days for TCP_KEEPIDLE and TCP_KEEPINTVL. */
if (idle > 10*24*60*60)
idle = 10*24*60*60;
+ if (intvl > 10*24*60*60)
+ intvl = 10*24*60*60;
UV_KEEPALIVE_FACTOR(idle);
@@ -523,12 +521,10 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)))
return UV__ERR(errno);
- intvl = 10; /* required at least 10 seconds */
UV_KEEPALIVE_FACTOR(intvl);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
return UV__ERR(errno);
- cnt = 1; /* 1 retry, ensure (TCP_KEEPINTVL * TCP_KEEPCNT) is 10 seconds */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno);
#else
@@ -540,7 +536,7 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
/* Note that the consequent probes will not be sent at equal intervals on Solaris,
* but will be sent using the exponential backoff algorithm. */
- int time_to_abort = 10; /* 10 seconds */
+ unsigned int time_to_abort = intvl * cnt;
UV_KEEPALIVE_FACTOR(time_to_abort);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, &time_to_abort, sizeof(time_to_abort)))
return UV__ERR(errno);
@@ -548,7 +544,6 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
#else /* !defined(__sun) */
- idle = delay;
UV_KEEPALIVE_FACTOR(idle);
#ifdef TCP_KEEPIDLE
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &idle, sizeof(idle)))
@@ -560,14 +555,12 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
#endif
#ifdef TCP_KEEPINTVL
- intvl = 1; /* 1 second; same as default on Win32 */
UV_KEEPALIVE_FACTOR(intvl);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
return UV__ERR(errno);
#endif
#ifdef TCP_KEEPCNT
- cnt = 10; /* 10 retries; same as hardcoded on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno);
#endif
@@ -595,11 +588,20 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int on) {
}
-int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
+int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int idle) {
+ return uv_tcp_keepalive_ex(handle, on, idle, 1, 10);
+}
+
+
+int uv_tcp_keepalive_ex(uv_tcp_t* handle,
+ int on,
+ unsigned int idle,
+ unsigned int intvl,
+ unsigned int cnt) {
int err;
if (uv__stream_fd(handle) != -1) {
- err =uv__tcp_keepalive(uv__stream_fd(handle), on, delay);
+ err = uv__tcp_keepalive(uv__stream_fd(handle), on, idle, intvl, cnt);
if (err)
return err;
}
@@ -609,7 +611,7 @@ int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int delay) {
else
handle->flags &= ~UV_HANDLE_TCP_KEEPALIVE;
- /* TODO Store delay if uv__stream_fd(handle) == -1 but don't want to enlarge
+ /* TODO Store idle if uv__stream_fd(handle) == -1 but don't want to enlarge
* uv_tcp_t with an int that's almost never used...
*/
diff --git a/src/unix/udp.c b/src/unix/udp.c
index c4a3559d..9f58edfe 100644
--- a/src/unix/udp.c
+++ b/src/unix/udp.c
@@ -560,7 +560,7 @@ int uv__udp_disconnect(uv_udp_t* handle) {
} while (r == -1 && errno == EINTR);
if (r == -1) {
-#if defined(BSD) /* The macro BSD is from sys/param.h */
+#if defined(BSD) || defined(__QNX__) /* The macro BSD is from sys/param.h */
if (errno != EAFNOSUPPORT && errno != EINVAL)
return UV__ERR(errno);
#else
@@ -766,8 +766,8 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
!defined(__NetBSD__) && \
!defined(__ANDROID__) && \
!defined(__DragonFly__) && \
- !defined(__QNX__) && \
- !defined(__GNU__)
+ !defined(__GNU__) && \
+ !defined(QNX_IOPKT)
static int uv__udp_set_source_membership4(uv_udp_t* handle,
const struct sockaddr_in* multicast_addr,
const char* interface_addr,
@@ -957,8 +957,8 @@ int uv_udp_set_source_membership(uv_udp_t* handle,
!defined(__NetBSD__) && \
!defined(__ANDROID__) && \
!defined(__DragonFly__) && \
- !defined(__QNX__) && \
- !defined(__GNU__)
+ !defined(__GNU__) && \
+ !defined(QNX_IOPKT)
int err;
union uv__sockaddr mcast_addr;
union uv__sockaddr src_addr;
@@ -1312,7 +1312,7 @@ static int uv__udp_sendmsgv(int fd,
nsent = 0;
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \
- (defined(__sun__) && defined(MSG_WAITFORONE))
+ (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__)
if (count > 1) {
for (i = 0; i < count; /*empty*/) {
struct mmsghdr m[20];
@@ -1340,7 +1340,7 @@ static int uv__udp_sendmsgv(int fd,
goto exit;
}
#endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) ||
- * (defined(__sun__) && defined(MSG_WAITFORONE))
+ * (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__)
*/
for (i = 0; i < count; i++, nsent++)
diff --git a/src/uv-common.c b/src/uv-common.c
index 60ff56b9..bff9d9ee 100644
--- a/src/uv-common.c
+++ b/src/uv-common.c
@@ -575,12 +575,17 @@ static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
struct uv__queue* q;
uv_handle_t* h;
- if (loop == NULL)
- loop = uv_default_loop();
-
if (stream == NULL)
stream = stderr;
+ if (loop == NULL) {
+ loop = uv_default_loop();
+ if (loop == NULL) {
+ fprintf(stream, "uv_default_loop() failed\n");
+ return;
+ }
+ }
+
uv__queue_foreach(q, &loop->handle_queue) {
h = uv__queue_data(q, uv_handle_t, handle_queue);
diff --git a/src/win/poll.c b/src/win/poll.c
index 7fec2b99..a20867a9 100644
--- a/src/win/poll.c
+++ b/src/win/poll.c
@@ -211,15 +211,11 @@ static SOCKET uv__fast_poll_create_peer_socket(HANDLE iocp,
protocol_info->iProtocol,
protocol_info,
0,
- WSA_FLAG_OVERLAPPED);
+ WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
if (sock == INVALID_SOCKET) {
return INVALID_SOCKET;
}
- if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
- goto error;
- };
-
if (CreateIoCompletionPort((HANDLE) sock,
iocp,
(ULONG_PTR) sock,
diff --git a/src/win/tcp.c b/src/win/tcp.c
index c452c12e..5b7604a9 100644
--- a/src/win/tcp.c
+++ b/src/win/tcp.c
@@ -49,29 +49,99 @@ static int uv__tcp_nodelay(uv_tcp_t* handle, SOCKET socket, int enable) {
}
-static int uv__tcp_keepalive(uv_tcp_t* handle, SOCKET socket, int enable, unsigned int delay) {
+/*
+ * Check if Windows version is 10.0.16299 (Windows 10, version 1709) or later.
+ */
+static int minimal_windows10_version1709(void) {
+ OSVERSIONINFOW os_info;
+ if (!pRtlGetVersion)
+ return 0;
+ pRtlGetVersion(&os_info);
+ if (os_info.dwMajorVersion < 10)
+ return 0;
+ if (os_info.dwMajorVersion > 10)
+ return 1;
+ if (os_info.dwMinorVersion > 0)
+ return 1;
+ return os_info.dwBuildNumber >= 16299;
+}
+
+
+static int uv__tcp_keepalive(uv_tcp_t* handle,
+ SOCKET socket,
+ int on,
+ unsigned int idle,
+ unsigned int intvl,
+ unsigned int cnt) {
if (setsockopt(socket,
SOL_SOCKET,
SO_KEEPALIVE,
- (const char*)&enable,
- sizeof enable) == -1) {
+ (const char*)&on,
+ sizeof on) == -1) {
return WSAGetLastError();
}
- if (!enable)
+ if (!on)
return 0;
- if (delay < 1)
+ if (idle < 1 || intvl < 1 || cnt < 1)
return UV_EINVAL;
- if (setsockopt(socket,
- IPPROTO_TCP,
- TCP_KEEPALIVE,
- (const char*)&delay,
- sizeof delay) == -1) {
- return WSAGetLastError();
+ /* Windows 10, version 1709 (build 10.0.16299) and later require second units
+ * for TCP keepalive options. */
+ if (minimal_windows10_version1709()) {
+ if (setsockopt(socket,
+ IPPROTO_TCP,
+ TCP_KEEPIDLE,
+ (const char*)&idle,
+ sizeof idle) == -1) {
+ return WSAGetLastError();
+ }
+
+ if (setsockopt(socket,
+ IPPROTO_TCP,
+ TCP_KEEPINTVL,
+ (const char*)&intvl,
+ sizeof intvl) == -1) {
+ return WSAGetLastError();
+ }
+
+ if (setsockopt(socket,
+ IPPROTO_TCP,
+ TCP_KEEPCNT,
+ (const char*)&cnt,
+ sizeof cnt) == -1) {
+ return WSAGetLastError();
+ }
+
+ return 0;
}
+ /* For those versions prior to Windows 10 version 1709,
+ * we fall back to SIO_KEEPALIVE_VALS that expects millisecond units.
+ * The SIO_KEEPALIVE_VALS IOCTL is supported on Windows 2000
+ * and later versions of the operating system. */
+ struct tcp_keepalive keepalive;
+ keepalive.onoff = on;
+ keepalive.keepalivetime = idle * 1000;
+ keepalive.keepaliveinterval = intvl * 1000;
+ /* On Windows Vista and later, the number of keep-alive probes
+ * (data retransmissions) is set to 10 and cannot be changed.
+ * On Windows Server 2003, Windows XP, and Windows 2000, the default setting
+ * for number of keep-alive probes is 5 and cannot be changed programmatically.
+ */
+ DWORD dummy;
+ if (WSAIoctl(socket,
+ SIO_KEEPALIVE_VALS,
+ (LPVOID) &keepalive,
+ sizeof keepalive,
+ NULL,
+ 0,
+ &dummy,
+ NULL,
+ NULL) == -1)
+ return WSAGetLastError();
+
return 0;
}
@@ -132,7 +202,7 @@ static int uv__tcp_set_socket(uv_loop_t* loop,
/* TODO: Use stored delay. */
if (handle->flags & UV_HANDLE_TCP_KEEPALIVE) {
- err = uv__tcp_keepalive(handle, socket, 1, 60);
+ err = uv__tcp_keepalive(handle, socket, 1, 60, 1, 10);
if (err)
return err;
}
@@ -749,20 +819,6 @@ static int uv__is_loopback(const struct sockaddr_storage* storage) {
return 0;
}
-// Check if Windows version is 10.0.16299 or later
-static int uv__is_fast_loopback_fail_supported(void) {
- OSVERSIONINFOW os_info;
- if (!pRtlGetVersion)
- return 0;
- pRtlGetVersion(&os_info);
- if (os_info.dwMajorVersion < 10)
- return 0;
- if (os_info.dwMajorVersion > 10)
- return 1;
- if (os_info.dwMinorVersion > 0)
- return 1;
- return os_info.dwBuildNumber >= 16299;
-}
static int uv__tcp_try_connect(uv_connect_t* req,
uv_tcp_t* handle,
@@ -809,7 +865,7 @@ static int uv__tcp_try_connect(uv_connect_t* req,
* is not reachable, instead of waiting for 2s. We do not care if this fails.
* This only works on Windows version 10.0.16299 and later.
*/
- if (uv__is_fast_loopback_fail_supported() && uv__is_loopback(&converted)) {
+ if (minimal_windows10_version1709() && uv__is_loopback(&converted)) {
memset(&retransmit_ioctl, 0, sizeof(retransmit_ioctl));
retransmit_ioctl.Rtt = TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS;
retransmit_ioctl.MaxSynRetransmissions = TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS;
@@ -1335,22 +1391,30 @@ int uv_tcp_nodelay(uv_tcp_t* handle, int enable) {
}
-int uv_tcp_keepalive(uv_tcp_t* handle, int enable, unsigned int delay) {
+int uv_tcp_keepalive(uv_tcp_t* handle, int on, unsigned int idle) {
+ return uv_tcp_keepalive_ex(handle, on, idle, 1, 10);
+}
+
+int uv_tcp_keepalive_ex(uv_tcp_t* handle,
+ int on,
+ unsigned int idle,
+ unsigned int intvl,
+ unsigned int cnt) {
int err;
if (handle->socket != INVALID_SOCKET) {
- err = uv__tcp_keepalive(handle, handle->socket, enable, delay);
+ err = uv__tcp_keepalive(handle, handle->socket, on, idle, intvl, cnt);
if (err)
return uv_translate_sys_error(err);
}
- if (enable) {
+ if (on) {
handle->flags |= UV_HANDLE_TCP_KEEPALIVE;
} else {
handle->flags &= ~UV_HANDLE_TCP_KEEPALIVE;
}
- /* TODO: Store delay if handle->socket isn't created yet. */
+ /* TODO: Store idle if handle->socket isn't created yet. */
return 0;
}
diff --git a/src/win/thread.c b/src/win/thread.c
index 753cb6a3..9c38e3d8 100644
--- a/src/win/thread.c
+++ b/src/win/thread.c
@@ -284,7 +284,7 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) {
static void uv__thread_name_init_once(void) {
HMODULE m;
- m = GetModuleHandleA("api-ms-win-core-processthreads-l1-1-3.dll");
+ m = GetModuleHandleW(L"api-ms-win-core-processthreads-l1-1-3.dll");
if (m != NULL) {
pGetThreadDescription = (void*) GetProcAddress(m, "GetThreadDescription");
pSetThreadDescription = (void*) GetProcAddress(m, "SetThreadDescription");
diff --git a/src/win/util.c b/src/win/util.c
index da1238d3..cebc2b3e 100644
--- a/src/win/util.c
+++ b/src/win/util.c
@@ -378,10 +378,15 @@ done:
static int uv__get_process_title(void) {
WCHAR title_w[MAX_TITLE_LENGTH];
DWORD wlen;
+ DWORD err;
+ SetLastError(ERROR_SUCCESS);
wlen = GetConsoleTitleW(title_w, sizeof(title_w) / sizeof(WCHAR));
- if (wlen == 0)
- return uv_translate_sys_error(GetLastError());
+ if (wlen == 0) {
+ err = GetLastError();
+ if (err != 0)
+ return uv_translate_sys_error(err);
+ }
return uv__convert_utf16_to_utf8(title_w, wlen, &process_title);
}
diff --git a/src/win/winapi.c b/src/win/winapi.c
index 315a0d49..786a9daa 100644
--- a/src/win/winapi.c
+++ b/src/win/winapi.c
@@ -55,9 +55,9 @@ void uv__winapi_init(void) {
HMODULE ws2_32_module;
HMODULE api_win_core_file_module;
- ntdll_module = GetModuleHandleA("ntdll.dll");
+ ntdll_module = GetModuleHandleW(L"ntdll.dll");
if (ntdll_module == NULL) {
- uv_fatal_error(GetLastError(), "GetModuleHandleA");
+ uv_fatal_error(GetLastError(), "GetModuleHandleW");
}
pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
@@ -123,20 +123,20 @@ void uv__winapi_init(void) {
GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
}
- user32_module = GetModuleHandleA("user32.dll");
+ user32_module = GetModuleHandleW(L"user32.dll");
if (user32_module != NULL) {
pSetWinEventHook = (sSetWinEventHook)
GetProcAddress(user32_module, "SetWinEventHook");
}
- ws2_32_module = GetModuleHandleA("ws2_32.dll");
+ ws2_32_module = GetModuleHandleW(L"ws2_32.dll");
if (ws2_32_module != NULL) {
pGetHostNameW = (uv_sGetHostNameW) GetProcAddress(
ws2_32_module,
"GetHostNameW");
}
- api_win_core_file_module = GetModuleHandleA("api-ms-win-core-file-l2-1-4.dll");
+ api_win_core_file_module = GetModuleHandleW(L"api-ms-win-core-file-l2-1-4.dll");
if (api_win_core_file_module != NULL) {
pGetFileInformationByName = (sGetFileInformationByName)GetProcAddress(
api_win_core_file_module, "GetFileInformationByName");
diff --git a/src/win/winsock.h b/src/win/winsock.h
index bb3808a3..e14b8b51 100644
--- a/src/win/winsock.h
+++ b/src/win/winsock.h
@@ -38,10 +38,6 @@
# define SO_UPDATE_CONNECT_CONTEXT 0x7010
#endif
-#ifndef TCP_KEEPALIVE
-# define TCP_KEEPALIVE 3
-#endif
-
#ifndef IPV6_V6ONLY
# define IPV6_V6ONLY 27
#endif
@@ -62,6 +58,30 @@
# define MCAST_LEAVE_SOURCE_GROUP 46
#endif
+#ifndef SIO_KEEPALIVE_VALS
+#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
+struct tcp_keepalive {
+ u_long onoff;
+ u_long keepalivetime;
+ u_long keepaliveinterval;
+};
+#endif
+
+/*
+ * TCP keepalive definitions on MinGW are located in <netinet/tcp.h>.
+ */
+#ifndef TCP_KEEPIDLE
+#define TCP_KEEPIDLE 0x03 /* start keepalives after this period */
+#endif
+
+#ifndef TCP_KEEPINTVL
+#define TCP_KEEPINTVL 0x11 /* interval between keepalives */
+#endif
+
+#ifndef TCP_KEEPCNT
+#define TCP_KEEPCNT 0x10 /* number of keepalives before death */
+#endif
+
/*
* TDI defines that are only in the DDK.
* We only need receive flags so far.