Browse Source

Abstract out the setting up of the stratum curl socket.

Con Kolivas 13 years ago
parent
commit
c29df9760f
1 changed files with 16 additions and 7 deletions
  1. 16 7
      util.c

+ 16 - 7
util.c

@@ -1365,15 +1365,12 @@ out:
 	return ret;
 	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 curl_err_str[CURL_ERROR_SIZE];
-	char s[RBUFSIZE], *sret = NULL;
 	CURL *curl = NULL;
 	CURL *curl = NULL;
 	double byte_count;
 	double byte_count;
-	json_error_t err;
-	bool ret = false;
+	char s[RBUFSIZE];
 
 
 	mutex_lock(&pool->stratum_lock);
 	mutex_lock(&pool->stratum_lock);
 	pool->stratum_active = false;
 	pool->stratum_active = false;
@@ -1393,7 +1390,6 @@ bool initiate_stratum(struct pool *pool)
 	}
 	}
 
 
 	/* Create a http url for use with curl */
 	/* Create a http url for use with curl */
-	memset(s, 0, RBUFSIZE);
 	sprintf(s, "http://%s:%s", pool->sockaddr_url, pool->stratum_port);
 	sprintf(s, "http://%s:%s", pool->sockaddr_url, pool->stratum_port);
 
 
 	curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
 	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);
 	curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1);
 	if (curl_easy_perform(curl)) {
 	if (curl_easy_perform(curl)) {
 		applog(LOG_INFO, "Stratum connect failed to pool %d: %s", pool->pool_no, curl_err_str);
 		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);
 	curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
 	keep_alive(curl, 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)
 	if (curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &byte_count) == CURLE_OK)
 		pool->cgminer_pool_stats.bytes_received += byte_count;
 		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++);
 	sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
 
 
 	if (!__stratum_send(pool, s, strlen(s))) {
 	if (!__stratum_send(pool, s, strlen(s))) {