Remove dependency on mstcpip.h for windows build by making curl version >= 7.25.0 mandatory on windows builds, and use curl functions for keepalive whenever possible instead.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
diff --git a/configure.ac b/configure.ac
index e83f7fe..ad81803 100644
--- a/configure.ac
+++ b/configure.ac
@@ -358,7 +358,13 @@ fi
AC_SUBST(LIBUSB_LIBS)
AC_SUBST(LIBUSB_CFLAGS)
-PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.18.2], ,[AC_MSG_ERROR([Missing required libcurl dev >= 7.18.2])])
+if test "x$have_win32" != xtrue; then
+ PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.25.0], [AC_DEFINE([CURL_HAS_KEEPALIVE], [1], [Defined if version of curl supports keepalive.])],
+ [PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.18.2], ,[AC_MSG_ERROR([Missing required libcurl dev >= 7.18.2])])])
+else
+ PKG_CHECK_MODULES([LIBCURL], [libcurl >= 7.25.0], ,[AC_MSG_ERROR([Missing required libcurl dev >= 7.25.0])])
+ AC_DEFINE([CURL_HAS_KEEPALIVE], [1])
+fi
AC_SUBST(LIBCURL_LIBS)
dnl CCAN wants to know a lot of vars.
diff --git a/util.c b/util.c
index afc1685..33e83c6 100644
--- a/util.c
+++ b/util.c
@@ -29,7 +29,6 @@
# include <netdb.h>
#else
# include <winsock2.h>
-# include <mstcpip.h>
# include <ws2tcpip.h>
#endif
@@ -196,16 +195,30 @@ out:
return ptrlen;
}
-static int keep_sockalive(SOCKETTYPE fd)
+#if CURL_HAS_KEEPALIVE
+static void keep_curlalive(CURL *curl)
{
const int tcp_keepidle = 60;
const int tcp_keepintvl = 60;
- const int keepalive = 1;
- int ret = 0;
+ const long int keepalive = 1;
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, keepalive);
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, tcp_keepidle);
+ curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, tcp_keepintvl);
+}
-#ifndef WIN32
+static void keep_alive(CURL *curl, __maybe_unused SOCKETTYPE fd)
+{
+ keep_curlalive(curl);
+}
+#else
+static int keep_sockalive(SOCKETTYPE fd)
+{
+ const int tcp_keepidle = 60;
+ const int tcp_keepintvl = 60;
+ const int keepalive = 1;
const int tcp_keepcnt = 5;
+ int ret = 0;
if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive))))
ret = 1;
@@ -228,37 +241,22 @@ static int keep_sockalive(SOCKETTYPE fd)
# endif /* __APPLE_CC__ */
-#else /* WIN32 */
-
- const int zero = 0;
- struct tcp_keepalive vals;
- vals.onoff = 1;
- vals.keepalivetime = tcp_keepidle * 1000;
- vals.keepaliveinterval = tcp_keepintvl * 1000;
-
- DWORD outputBytes;
-
- if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char *)&keepalive, sizeof(keepalive))))
- ret = 1;
-
- if (unlikely(WSAIoctl(fd, SIO_KEEPALIVE_VALS, &vals, sizeof(vals), NULL, 0, &outputBytes, NULL, NULL)))
- ret = 1;
+ return ret;
+}
- /* Windows happily submits indefinitely to the send buffer blissfully
- * unaware nothing is getting there without gracefully failing unless
- * we disable the send buffer */
- if (unlikely(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (const char *)&zero, sizeof(zero))))
- ret = 1;
-#endif /* WIN32 */
+static void keep_curlalive(CURL *curl)
+{
+ SOCKETTYPE sock;
- return ret;
+ curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&sock);
+ keep_sockalive(sock);
}
-int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd,
- curlsocktype __maybe_unused purpose)
+static void keep_alive(CURL __maybe_unused *curl, SOCKETTYPE fd)
{
- return keep_sockalive(fd);
+ keep_sockalive(fd);
}
+#endif
static void last_nettime(struct timeval *last)
{
@@ -334,7 +332,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
if (longpoll)
- curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, json_rpc_call_sockopt_cb);
+ keep_curlalive(curl);
curl_easy_setopt(curl, CURLOPT_POST, 1);
if (opt_protocol)
@@ -1362,7 +1360,7 @@ bool initiate_stratum(struct pool *pool)
goto out;
}
curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
- keep_sockalive(pool->sock);
+ keep_alive(curl, pool->sock);
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
diff --git a/windows-build.txt b/windows-build.txt
index 7fcd0af..9de4280 100644
--- a/windows-build.txt
+++ b/windows-build.txt
@@ -44,29 +44,6 @@ I just selected all the check boxes (excluding "Fortran Compiler") so that every
was installed.
**************************************************************************************
-* Create mstcpip.h *
-**************************************************************************************
-Open notepad and copy the following into it. Save it as "\MinGW\include\mstcpip.h".
-Make sure it does not have the ".txt" extension (If it does then rename it).
-
-struct tcp_keepalive
-{
- u_long onoff;
- u_long keepalivetime;
- u_long keepaliveinterval;
-};
-
-#ifndef USE_WS_PREFIX
-
-#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR, 4)
-
-#else
-
-#define WS_SIO_KEEPALIVE_VALS _WSAIOW(WS_IOC_VENDOR, 4)
-
-#endif
-
-**************************************************************************************
* Run the MSYS shell for the first time to create your user directory *
**************************************************************************************
(Start Icon/keyboard key ==> All Programs ==> MinGW ==> MinGW Shell).