Reap curls that are unused for over a minute. This allows connections to be closed, thereby allowing the number of curl handles to always be the minimum necessary to not delay networking.
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
diff --git a/cgminer.c b/cgminer.c
index 1cfa90f..f92f98e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1951,7 +1951,8 @@ static void sighandler(int __maybe_unused sig)
kill_work();
}
-/* Called with pool_lock held */
+/* Called with pool_lock held. Recruit an extra curl if none are available for
+ * this pool. */
static void recruit_curl(struct pool *pool)
{
struct curl_ent *ce = calloc(sizeof(struct curl_ent), 1);
@@ -1981,7 +1982,8 @@ static struct curl_ent *pop_curl_entry(struct pool *pool)
static void push_curl_entry(struct curl_ent *ce, struct pool *pool)
{
mutex_lock(&pool->pool_lock);
- list_add(&ce->node, &pool->curlring);
+ list_add_tail(&ce->node, &pool->curlring);
+ gettimeofday(&ce->tv, NULL);
mutex_unlock(&pool->pool_lock);
}
@@ -3980,6 +3982,25 @@ void reinit_device(struct cgpu_info *cgpu)
static struct timeval rotate_tv;
+/* We reap curls if they are unused for over a minute */
+static void reap_curl(struct pool *pool)
+{
+ struct curl_ent *ent, *iter;
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ mutex_lock(&pool->pool_lock);
+ list_for_each_entry_safe(ent, iter, &pool->curlring, node) {
+ if (now.tv_sec - ent->tv.tv_sec > 60) {
+ applog(LOG_DEBUG, "Reaped curl from pool %d", pool->pool_no);
+ list_del(&ent->node);
+ curl_easy_cleanup(ent->curl);
+ free(ent);
+ }
+ }
+ mutex_unlock(&pool->pool_lock);
+}
+
static void *watchpool_thread(void __maybe_unused *userdata)
{
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
@@ -3993,6 +4014,7 @@ static void *watchpool_thread(void __maybe_unused *userdata)
for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i];
+ reap_curl(pool);
if (!pool->enabled)
continue;
diff --git a/miner.h b/miner.h
index 3f6f9ba..3e114c4 100644
--- a/miner.h
+++ b/miner.h
@@ -601,6 +601,7 @@ typedef struct {
struct curl_ent {
CURL *curl;
struct list_head node;
+ struct timeval tv;
};
struct pool {