mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
tcpkeepalive: support TCP_KEEPIDLE/TCP_KEEPINTVL on win32
Patch by: Robert Wruck Bug: http://curl.haxx.se/bug/view.cgi?id=1209
This commit is contained in:
parent
e839e7c61b
commit
c4d7c1514f
@ -87,13 +87,23 @@
|
|||||||
|
|
||||||
static bool verifyconnect(curl_socket_t sockfd, int *error);
|
static bool verifyconnect(curl_socket_t sockfd, int *error);
|
||||||
|
|
||||||
#ifdef __DragonFly__
|
#if defined(__DragonFly__) || defined(HAVE_WINSOCK_H)
|
||||||
/* DragonFlyBSD uses millisecond as KEEPIDLE and KEEPINTVL units */
|
/* DragonFlyBSD and Windows use millisecond units */
|
||||||
#define KEEPALIVE_FACTOR(x) (x *= 1000)
|
#define KEEPALIVE_FACTOR(x) (x *= 1000)
|
||||||
#else
|
#else
|
||||||
#define KEEPALIVE_FACTOR(x)
|
#define KEEPALIVE_FACTOR(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_WINSOCK_H) && !defined(SIO_KEEPALIVE_VALS)
|
||||||
|
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
|
||||||
|
|
||||||
|
struct tcp_keepalive {
|
||||||
|
u_long onoff;
|
||||||
|
u_long keepalivetime;
|
||||||
|
u_long keepaliveinterval;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
tcpkeepalive(struct SessionHandle *data,
|
tcpkeepalive(struct SessionHandle *data,
|
||||||
curl_socket_t sockfd)
|
curl_socket_t sockfd)
|
||||||
@ -106,6 +116,22 @@ tcpkeepalive(struct SessionHandle *data,
|
|||||||
infof(data, "Failed to set SO_KEEPALIVE on fd %d\n", sockfd);
|
infof(data, "Failed to set SO_KEEPALIVE on fd %d\n", sockfd);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
#if defined(SIO_KEEPALIVE_VALS)
|
||||||
|
struct tcp_keepalive vals;
|
||||||
|
DWORD dummy;
|
||||||
|
vals.onoff = 1;
|
||||||
|
optval = curlx_sltosi(data->set.tcp_keepidle);
|
||||||
|
KEEPALIVE_FACTOR(optval);
|
||||||
|
vals.keepalivetime = optval;
|
||||||
|
optval = curlx_sltosi(data->set.tcp_keepintvl);
|
||||||
|
KEEPALIVE_FACTOR(optval);
|
||||||
|
vals.keepaliveinterval = optval;
|
||||||
|
if (WSAIoctl(sockfd, SIO_KEEPALIVE_VALS, (LPVOID) &vals, sizeof(vals),
|
||||||
|
NULL, 0, &dummy, NULL, NULL) != 0) {
|
||||||
|
infof(data, "Failed to set SIO_KEEPALIVE_VALS on fd %d: %d\n",
|
||||||
|
(int)sockfd, WSAGetLastError());
|
||||||
|
}
|
||||||
|
#else
|
||||||
#ifdef TCP_KEEPIDLE
|
#ifdef TCP_KEEPIDLE
|
||||||
optval = curlx_sltosi(data->set.tcp_keepidle);
|
optval = curlx_sltosi(data->set.tcp_keepidle);
|
||||||
KEEPALIVE_FACTOR(optval);
|
KEEPALIVE_FACTOR(optval);
|
||||||
@ -121,6 +147,7 @@ tcpkeepalive(struct SessionHandle *data,
|
|||||||
(void *)&optval, sizeof(optval)) < 0) {
|
(void *)&optval, sizeof(optval)) < 0) {
|
||||||
infof(data, "Failed to set TCP_KEEPINTVL on fd %d\n", sockfd);
|
infof(data, "Failed to set TCP_KEEPINTVL on fd %d\n", sockfd);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user