Commit 39906718d2067f854c22c31b22b1f02c41eedf9b

Con Kolivas 2012-02-19T22:07:31

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.

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;