diff --git a/cgminer.c b/cgminer.c index b97daf4e..38b646a2 100644 --- a/cgminer.c +++ b/cgminer.c @@ -135,6 +135,11 @@ bool opt_delaynet; bool opt_disable_pool; static bool no_work; bool opt_worktime; +#if defined(HAVE_LIBCURL) && defined(CURL_HAS_KEEPALIVE) +int opt_tcp_keepalive = 30; +#else +int opt_tcp_keepalive; +#endif char *opt_kernel_path; char *cgminer_path; @@ -1176,6 +1181,14 @@ static struct opt_table opt_config_table[] = { opt_set_bool, &use_syslog, "Use system log for output messages (default: standard error)"), #endif + OPT_WITH_ARG("--tcp-keepalive", + set_int_0_to_9999, opt_show_intval, &opt_tcp_keepalive, +#if defined(HAVE_LIBCURL) && defined(CURL_HAS_KEEPALIVE) + "TCP keepalive packet idle time" +#else + opt_hidden +#endif + ), #ifdef HAVE_ADL OPT_WITH_ARG("--temp-cutoff", set_temp_cutoff, opt_show_intval, &opt_cutofftemp, diff --git a/miner.h b/miner.h index 45837188..e2b3a8ff 100644 --- a/miner.h +++ b/miner.h @@ -971,6 +971,7 @@ extern bool opt_delaynet; extern bool opt_restart; extern bool opt_worktime; extern int swork_id; +extern int opt_tcp_keepalive; #if LOCK_TRACKING extern pthread_mutex_t lockstat_lock; diff --git a/util.c b/util.c index f5472c30..8097eb8d 100644 --- a/util.c +++ b/util.c @@ -255,13 +255,11 @@ static void set_nettime(void) #if CURL_HAS_KEEPALIVE static void keep_curlalive(CURL *curl) { - const int tcp_keepidle = 45; - const int tcp_keepintvl = 30; 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); + curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, opt_tcp_keepalive); + curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, opt_tcp_keepalive); } #else static void keep_curlalive(CURL *curl)