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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/cgminer.c b/cgminer.c
index f01ee15..3824a50 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 467b863..0afd6fb 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)