Abstract out the setting up of the stratum curl socket.
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
diff --git a/util.c b/util.c
index 3ab1236..77f5b36 100644
--- a/util.c
+++ b/util.c
@@ -1365,15 +1365,12 @@ out:
return ret;
}
-bool initiate_stratum(struct pool *pool)
+static bool setup_stratum_curl(struct pool *pool)
{
- json_t *val = NULL, *res_val, *err_val;
char curl_err_str[CURL_ERROR_SIZE];
- char s[RBUFSIZE], *sret = NULL;
CURL *curl = NULL;
double byte_count;
- json_error_t err;
- bool ret = false;
+ char s[RBUFSIZE];
mutex_lock(&pool->stratum_lock);
pool->stratum_active = false;
@@ -1393,7 +1390,6 @@ bool initiate_stratum(struct pool *pool)
}
/* Create a http url for use with curl */
- memset(s, 0, RBUFSIZE);
sprintf(s, "http://%s:%s", pool->sockaddr_url, pool->stratum_port);
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
@@ -1413,7 +1409,7 @@ bool initiate_stratum(struct pool *pool)
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
if (curl_easy_perform(curl)) {
applog(LOG_INFO, "Stratum connect failed to pool %d: %s", pool->pool_no, curl_err_str);
- goto out;
+ return false;
}
curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
keep_alive(curl, pool->sock);
@@ -1425,6 +1421,19 @@ bool initiate_stratum(struct pool *pool)
if (curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &byte_count) == CURLE_OK)
pool->cgminer_pool_stats.bytes_received += byte_count;
+ return true;
+}
+
+bool initiate_stratum(struct pool *pool)
+{
+ json_t *val = NULL, *res_val, *err_val;
+ char s[RBUFSIZE], *sret = NULL;
+ json_error_t err;
+ bool ret = false;
+
+ if (!setup_stratum_curl(pool))
+ goto out;
+
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
if (!__stratum_send(pool, s, strlen(s))) {