aboutsummaryrefslogtreecommitdiff
path: root/cpu-miner.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2011-02-10 00:41:44 -0500
committerJeff Garzik <jgarzik@redhat.com>2011-02-10 00:41:44 -0500
commitc0935a94899bc7261bc98b17a52d7c11b005fde4 (patch)
treeb69fdac650a0c428e7f55babc9bc557f8feaa1ef /cpu-miner.c
parent82772022216c1d8b4dca2d0772d5810afc2e4ad8 (diff)
Re-use CURL object, thereby caching DNS and HTTP connections where possible.
Diffstat (limited to 'cpu-miner.c')
-rw-r--r--cpu-miner.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/cpu-miner.c b/cpu-miner.c
index f288471..e78c48f 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -23,6 +23,7 @@
#include <pthread.h>
#include <getopt.h>
#include <jansson.h>
+#include <curl/curl.h>
#include "compat.h"
#include "miner.h"
@@ -199,7 +200,7 @@ err_out:
return false;
}
-static void submit_work(struct work *work)
+static void submit_work(CURL *curl, struct work *work)
{
char *hexstr = NULL;
json_t *val, *res;
@@ -221,7 +222,7 @@ static void submit_work(struct work *work)
fprintf(stderr, "DBG: sending RPC call:\n%s", s);
/* issue JSON-RPC request */
- val = json_rpc_call(rpc_url, userpass, s);
+ val = json_rpc_call(curl, rpc_url, userpass, s);
if (!val) {
fprintf(stderr, "submit_work json_rpc_call failed\n");
goto out;
@@ -259,6 +260,13 @@ static void *miner_thread(void *thr_id_int)
static const char *rpc_req =
"{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n";
uint32_t max_nonce = 0xffffff;
+ CURL *curl;
+
+ curl = curl_easy_init();
+ if (!curl) {
+ fprintf(stderr, "CURL initialization failed\n");
+ return NULL;
+ }
while (1) {
struct work work __attribute__((aligned(128)));
@@ -268,7 +276,7 @@ static void *miner_thread(void *thr_id_int)
bool rc;
/* obtain new work from bitcoin */
- val = json_rpc_call(rpc_url, userpass, rpc_req);
+ val = json_rpc_call(curl, rpc_url, userpass, rpc_req);
if (!val) {
fprintf(stderr, "json_rpc_call failed, ");
@@ -369,11 +377,13 @@ static void *miner_thread(void *thr_id_int)
/* if nonce found, submit work */
if (rc)
- submit_work(&work);
+ submit_work(curl, &work);
failures = 0;
}
+ curl_easy_cleanup(curl);
+
return NULL;
}