Start longpoll only after we have tried to extract the longpoll URL.
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 63c645a..0e6be11 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -378,7 +378,6 @@ static void sharelog(const char*disposition, const struct work*work)
static void *submit_work_thread(void *userdata);
static void *get_work_thread(void *userdata);
-static void *longpoll_thread(void *userdata);
static void add_pool(void)
{
@@ -402,8 +401,6 @@ static void add_pool(void)
quit(1, "Failed to create pool submit thread");
if (unlikely(pthread_create(&pool->getwork_thread, NULL, get_work_thread, (void *)pool)))
quit(1, "Failed to create pool getwork thread");
- if (unlikely(pthread_create(&pool->longpoll_thread, NULL, longpoll_thread, (void *)pool)))
- quit(1, "Failed to create pool longpoll thread");
}
/* Pool variant of test and set */
@@ -3214,6 +3211,8 @@ out_unlock:
}
}
+static void *longpoll_thread(void *userdata);
+
static bool pool_active(struct pool *pool, bool pinging)
{
bool ret = false;
@@ -3256,9 +3255,8 @@ static bool pool_active(struct pool *pool, bool pinging)
}
json_decref(val);
- /* We may be updating the url after the pool has died */
if (pool->lp_url)
- free(pool->lp_url);
+ goto out;
/* Decipher the longpoll URL, if any, and store it in ->lp_url */
if (pool->hdr_path) {
@@ -3285,13 +3283,19 @@ static bool pool_active(struct pool *pool, bool pinging)
}
} else
pool->lp_url = NULL;
+
+ if (!pool->lp_started) {
+ pool->lp_started = true;
+ if (unlikely(pthread_create(&pool->longpoll_thread, NULL, longpoll_thread, (void *)pool)))
+ quit(1, "Failed to create pool longpoll thread");
+ }
} else {
applog(LOG_DEBUG, "FAILED to retrieve work from pool %u %s",
pool->pool_no, pool->rpc_url);
if (!pinging)
applog(LOG_WARNING, "Pool %u slow/down or URL or credentials invalid", pool->pool_no);
}
-
+out:
curl_easy_cleanup(curl);
return ret;
}
diff --git a/miner.h b/miner.h
index d08fbbe..2d23804 100644
--- a/miner.h
+++ b/miner.h
@@ -610,6 +610,7 @@ struct pool {
bool enabled;
bool submit_old;
bool removed;
+ bool lp_started;
char *hdr_path;
char *lp_url;