From aa97e87a13d8b61ff479fe39f493ba791ec07d48 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 28 Oct 2012 09:15:45 +1100 Subject: [PATCH] Use keepalive with stratum sockets to improve its ability to detect broken connections. --- util.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/util.c b/util.c index cd75c8f3..115dfe02 100644 --- a/util.c +++ b/util.c @@ -196,11 +196,10 @@ out: return ptrlen; } -int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd, - curlsocktype __maybe_unused purpose) +static int keep_sockalive(SOCKETTYPE fd) { - int tcp_keepidle = 120; - int tcp_keepintvl = 120; + int tcp_keepidle = 60; + int tcp_keepintvl = 60; #ifndef WIN32 int keepalive = 1; @@ -244,6 +243,12 @@ int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd, return 0; } +int json_rpc_call_sockopt_cb(void __maybe_unused *userdata, curl_socket_t fd, + curlsocktype __maybe_unused purpose) +{ + return keep_sockalive(fd); +} + static void last_nettime(struct timeval *last) { rd_lock(&netacc_lock); @@ -1347,6 +1352,7 @@ bool initiate_stratum(struct pool *pool) goto out; } curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock); + keep_sockalive(pool->sock); sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);