From 1b7aa48c8fdfac32e5370aaa03b41f39c3cdbfbd Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 2 Oct 2012 11:46:48 +1000 Subject: [PATCH] Initiate stratum the first time in pool_active only, allowing us to switch to it on getting a failed getwork and detecting the presence of stratum on the url at that time. --- cgminer.c | 18 ++++++++++-------- util.c | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cgminer.c b/cgminer.c index f01ee154..3824a509 100644 --- a/cgminer.c +++ b/cgminer.c @@ -562,17 +562,12 @@ static char *set_rr(enum pool_strategy *strategy) * stratum+tcp or by detecting a stratum server response */ bool detect_stratum(struct pool *pool, char *url) { - bool stratum; - if (!extract_sockaddr(pool, url)) return false; - stratum = initiate_stratum(pool); - - if (!strncasecmp(url, "stratum+tcp://", 14) || stratum) { + if (!strncasecmp(url, "stratum+tcp://", 14)) { pool->has_stratum = true; - if (!pool->stratum_url) - pool->stratum_url = pool->sockaddr_url; + pool->stratum_url = pool->sockaddr_url; return true; } @@ -4205,6 +4200,7 @@ static bool pool_active(struct pool *pool, bool pinging) applog(LOG_INFO, "Testing pool %s", pool->rpc_url); + /* This is the central point we activate stratum when we can */ retry_stratum: if (pool->has_stratum) { if ((!pool->stratum_active || pinging) && !initiate_stratum(pool)) @@ -4233,7 +4229,7 @@ retry_stratum: /* Detect if a http getwork pool has an X-Stratum header at startup, * and if so, switch to that in preference to getwork */ - if (unlikely(!pinging && pool->stratum_url)) { + if (unlikely(pool->stratum_url)) { applog(LOG_NOTICE, "Switching pool %d %s to %s", pool->pool_no, pool->rpc_url, pool->stratum_url); pool->has_stratum = true; pool->rpc_url = pool->stratum_url; @@ -4308,6 +4304,12 @@ retry_stratum: quit(1, "Failed to create pool longpoll thread"); } } else { + /* If we failed to parse a getwork, this could be a stratum + * url without the prefix stratum+tcp:// so let's check it */ + if (initiate_stratum(pool)) { + pool->has_stratum = true; + goto retry_stratum; + } applog(LOG_DEBUG, "FAILED to retrieve work from pool %u %s", pool->pool_no, pool->rpc_url); if (!pinging) diff --git a/util.c b/util.c index 467b863b..0afd6fb8 100644 --- a/util.c +++ b/util.c @@ -906,7 +906,7 @@ static bool sock_full(SOCKETTYPE sock, bool wait) FD_SET(sock, &rd); timeout.tv_usec = 0; if (wait) - timeout.tv_sec = 5; + timeout.tv_sec = 60; else timeout.tv_sec = 0; if (select(sock + 1, &rd, NULL, NULL, &timeout) > 0)