Keep track of when a longpoll has been sent for a pool and if the current pool is requesting work but has not sent a longpoll request, convert one of the work items to a longpoll as we may have switched pools but still be using the longpoll from the previous pool.
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 68 69 70 71 72 73 74
diff --git a/cgminer.c b/cgminer.c
index 1ac0ee9..e5b1e67 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1572,9 +1572,9 @@ static inline struct pool *select_pool(bool lagging)
static bool get_upstream_work(struct work *work, bool lagging)
{
+ bool rc = false, req_longpoll = false;
struct pool *pool;
json_t *val = NULL;
- bool rc = false;
int retries = 0;
CURL *curl;
@@ -1587,13 +1587,18 @@ static bool get_upstream_work(struct work *work, bool lagging)
pool = select_pool(lagging);
applog(LOG_DEBUG, "DBG: sending %s get RPC call: %s", pool->rpc_url, rpc_req);
+ /* If this is the current pool and supports longpoll but has not sent
+ * a longpoll, send one now */
+ if (unlikely(pool == current_pool() && pool->hdr_path && !pool->lp_sent))
+ req_longpoll = true;
+
retry:
/* A single failure response here might be reported as a dead pool and
* there may be temporary denied messages etc. falsely reporting
* failure so retry a few times before giving up */
while (!val && retries++ < 3) {
val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
- false, false, &work->rolltime, pool, false);
+ false, req_longpoll, &work->rolltime, pool, false);
}
if (unlikely(!val)) {
applog(LOG_DEBUG, "Failed json_rpc_call in get_upstream_work");
diff --git a/miner.h b/miner.h
index 8a41000..0fce0bb 100644
--- a/miner.h
+++ b/miner.h
@@ -537,6 +537,7 @@ struct pool {
char *hdr_path;
char *lp_url;
+ bool lp_sent;
unsigned int getwork_requested;
unsigned int stale_shares;
diff --git a/util.c b/util.c
index a6cd37a..a28c0e1 100644
--- a/util.c
+++ b/util.c
@@ -301,10 +301,12 @@ json_t *json_rpc_call(CURL *curl, const char *url,
curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
+ if (longpoll) {
+ pool->lp_sent = true;
#ifdef CURL_HAS_SOCKOPT
- if (longpoll)
curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, json_rpc_call_sockopt_cb);
#endif
+ }
curl_easy_setopt(curl, CURLOPT_POST, 1);
if (opt_protocol)
@@ -350,6 +352,8 @@ json_t *json_rpc_call(CURL *curl, const char *url,
}
rc = curl_easy_perform(curl);
+ if (longpoll)
+ pool->lp_sent = false;
if (rc) {
applog(LOG_INFO, "HTTP request failed: %s", curl_err_str);
goto err_out;