diff --git a/cgminer.c b/cgminer.c index 2628b59e..beb8716c 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4676,6 +4676,28 @@ static void clear_stratum_shares(struct pool *pool) } } +/* We only need to maintain a secondary pool connection when we need the + * capacity to get work from the backup pools while still on the primary */ +static bool cnx_needed(struct pool *pool) +{ + struct pool *cp; + + if (pool_strategy == POOL_BALANCE) + return true; + if (pool_strategy == POOL_LOADBALANCE) + return true; + if (opt_fail_only) + return true; + cp = current_pool(); + if (cp == pool) + return true; + if (!cp->has_gbt && !cp->has_stratum) + return true; + return false; +} + +static void wait_lpcurrent(struct pool *pool); + /* One stratum thread per pool that has stratum waits on the socket checking * for new messages and for the integrity of the socket connection. We reset * the connection based on the integrity of the receive side only as the send @@ -4696,6 +4718,22 @@ static void *stratum_thread(void *userdata) if (unlikely(pool->removed)) break; + /* Check to see whether we need to maintain this connection + * indefinitely or just bring it up when we switch to this + * pool */ + if (!cnx_needed(pool)) { + suspend_stratum(pool); + wait_lpcurrent(pool); + if (!initiate_stratum(pool) || !auth_stratum(pool)) { + pool_died(pool); + while (!initiate_stratum(pool) || !auth_stratum(pool)) { + if (pool->removed) + goto out; + sleep(30); + } + } + } + FD_ZERO(&rd); FD_SET(pool->sock, &rd); timeout.tv_sec = 90; diff --git a/util.c b/util.c index c4b065f3..770f1ba1 100644 --- a/util.c +++ b/util.c @@ -1435,6 +1435,14 @@ out: return ret; } +void suspend_stratum(struct pool *pool) +{ + applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no); + mutex_lock(&pool->stratum_lock); + pool->stratum_active = false; + mutex_unlock(&pool->stratum_lock); + CLOSESOCKET(pool->sock); +} void dev_error(struct cgpu_info *dev, enum dev_reason reason) { diff --git a/util.h b/util.h index d0125ace..253b61d7 100644 --- a/util.h +++ b/util.h @@ -51,6 +51,7 @@ bool parse_method(struct pool *pool, char *s); bool extract_sockaddr(struct pool *pool, char *url); bool auth_stratum(struct pool *pool); bool initiate_stratum(struct pool *pool); +void suspend_stratum(struct pool *pool); void dev_error(struct cgpu_info *dev, enum dev_reason reason); void *realloc_strcat(char *ptr, char *s); void RenameThread(const char* name);