Set all stratum sockets to nonblocking to avoid trying to use MSG_DONTWAIT on windows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/util.c b/util.c
index 993a80f..15d90ea 100644
--- a/util.c
+++ b/util.c
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <sys/types.h>
#ifndef WIN32
+#include <fcntl.h>
# ifdef __linux
# include <sys/prctl.h>
# endif
@@ -201,11 +202,18 @@ out:
static void keep_sockalive(SOCKETTYPE fd)
{
+ const int tcp_one = 1;
#ifndef WIN32
const int tcp_keepidle = 45;
const int tcp_keepintvl = 30;
+ int flags = fcntl(fd, F_GETFL, 0);
+
+ fcntl(fd, F_SETFL, O_NONBLOCK | flags);
+#else
+ u_long flags = 1;
+
+ ioctlsocket(fd, FIONBIO, &flags);
#endif
- const int tcp_one = 1;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const void *)&tcp_one, sizeof(tcp_one));
if (!opt_delaynet)
@@ -213,9 +221,6 @@ static void keep_sockalive(SOCKETTYPE fd)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one));
#else /* __linux */
setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one));
-#endif /* __linux */
-
-#ifdef __linux
setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &tcp_one, sizeof(tcp_one));
setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &tcp_keepidle, sizeof(tcp_keepidle));
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &tcp_keepintvl, sizeof(tcp_keepintvl));
@@ -224,6 +229,7 @@ static void keep_sockalive(SOCKETTYPE fd)
#ifdef __APPLE_CC__
setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &tcp_keepintvl, sizeof(tcp_keepintvl));
#endif /* __APPLE_CC__ */
+
}
#if CURL_HAS_KEEPALIVE
@@ -1048,7 +1054,7 @@ static void clear_sock(struct pool *pool)
mutex_lock(&pool->stratum_lock);
do {
- n = recv(pool->sock, pool->sockbuf, RECVSIZE, MSG_DONTWAIT);
+ n = recv(pool->sock, pool->sockbuf, RECVSIZE, 0);
} while (n > 0);
mutex_unlock(&pool->stratum_lock);
@@ -1106,7 +1112,7 @@ char *recv_line(struct pool *pool)
ssize_t n;
memset(s, 0, RBUFSIZE);
- n = recv(pool->sock, s, RECVSIZE, MSG_DONTWAIT);
+ n = recv(pool->sock, s, RECVSIZE, 0);
if (!n) {
ret = RECV_CLOSED;
break;