Move pool active test to own function.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/main.c b/main.c
index e2f87e7..ec069b7 100644
--- a/main.c
+++ b/main.c
@@ -1397,6 +1397,53 @@ static int requests_queued(void)
return ret;
}
+static bool pool_active(struct pool *pool)
+{
+ bool ret = false;
+ json_t *val;
+ CURL *curl;
+
+ curl = curl_easy_init();
+ if (unlikely(!curl)) {
+ applog(LOG_ERR, "CURL initialisation failed");
+ return false;
+ }
+
+ val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
+ true, false, pool);
+
+ if (val) {
+ struct work *work = malloc(sizeof(struct work));
+ bool rc;
+
+ if (!work) {
+ applog(LOG_ERR, "Unable to malloc work in pool_active");
+ goto out;
+ }
+ rc = work_decode(json_object_get(val, "result"), work);
+ if (rc) {
+ applog(LOG_DEBUG, "Successfully retreived and deciphered work from pool %u %s",
+ pool->pool_no, pool->rpc_url);
+ work->pool = pool;
+ tq_push(thr_info[stage_thr_id].q, work);
+ total_getworks++;
+ pool->getwork_requested++;
+ inc_queued();
+ ret = true;
+ } else {
+ applog(LOG_DEBUG, "Successfully retreived but FAILED to decipher work from pool %u %s",
+ pool->pool_no, pool->rpc_url);
+ free(work);
+ }
+ json_decref(val);
+ } else
+ applog(LOG_DEBUG, "FAILED to retrieve work from pool %u %s",
+ pool->pool_no, pool->rpc_url);
+out:
+ curl_easy_cleanup(curl);
+ return ret;
+}
+
static bool queue_request(void)
{
int maxq = opt_queue + mining_threads;
@@ -2639,41 +2686,14 @@ int main (int argc, char *argv[])
* it supports */
for (i = 0; i < total_pools; i++) {
struct pool *pool;
- json_t *val;
- CURL *curl;
-
- curl = curl_easy_init();
- if (unlikely(!curl)) {
- applog(LOG_ERR, "CURL initialisation failed");
- return 1;
- }
pool = &pools[i];
- val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
- true, false, pool);
-
- if (val) {
- struct work *work = malloc(sizeof(struct work));
- bool rc;
-
- if (!work)
- return 1;
- rc = work_decode(json_object_get(val, "result"), work);
- if (rc) {
- applog(LOG_INFO, "Successfully retreived and deciphered work from pool %u %s", i, pool->rpc_url);
- work->pool = pool;
- tq_push(thr_info[stage_thr_id].q, work);
- total_getworks++;
- pool->getwork_requested++;
- inc_queued();
- } else {
- applog(LOG_WARNING, "Successfully retreived but FAILED to decipher work from pool %u %s", i, pool->rpc_url);
- free(work);
- }
- json_decref(val);
- } else
- applog(LOG_WARNING, "FAILED to retrieve work from pool %u %s", i, pool->rpc_url);
- curl_easy_cleanup(curl);
+ if (pool_active(pool))
+ applog(LOG_INFO, "Pool %d %s active", pool->pool_no, pool->rpc_url);
+ else {
+ applog(LOG_WARNING, "Unable to get work from pool %d %s", pool->pool_no, pool->rpc_url);
+ pool->idle = true;
+ }
}
#ifdef HAVE_OPENCL