From e0d3a7df60177ef8933a89f53afce410b90aabed Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 7 May 2017 11:20:50 +1000 Subject: [PATCH] Remove unnecessary use of gbt as private data in socket instance. --- src/ckpool.h | 2 -- src/generator.c | 18 +++++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/ckpool.h b/src/ckpool.h index c5f48158..dc8716d0 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -122,8 +122,6 @@ struct server_instance { bool notify; bool alive; connsock_t cs; - - void *data; // Private data }; typedef struct server_instance server_instance_t; diff --git a/src/generator.c b/src/generator.c index 7c910686..f90e4adc 100644 --- a/src/generator.c +++ b/src/generator.c @@ -194,7 +194,7 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging) char *userpass = NULL; bool ret = false; connsock_t *cs; - gbtbase_t *gbt; + gbtbase_t gbt; int fd; if (si->alive) @@ -222,16 +222,14 @@ static bool server_alive(ckpool_t *ckp, server_instance_t *si, bool pinging) } /* Test we can connect, authorise and get a block template */ - gbt = ckzalloc(sizeof(gbtbase_t)); - si->data = gbt; - if (!gen_gbtbase(cs, gbt)) { + if (!gen_gbtbase(cs, &gbt)) { if (!pinging) { LOGINFO("Failed to get test block template from %s:%s!", cs->url, cs->port); } goto out; } - clear_gbtbase(gbt); + clear_gbtbase(&gbt); if (!ckp->node && !validate_address(cs, ckp->btcaddress)) { LOGWARNING("Invalid btcaddress: %s !", ckp->btcaddress); goto out; @@ -299,7 +297,6 @@ static void kill_server(server_instance_t *si) dealloc(cs->url); dealloc(cs->port); dealloc(cs->auth); - dealloc(si->data); } static void clear_unix_msg(unix_msg_t **umsg) @@ -365,7 +362,7 @@ static void gen_loop(proc_instance_t *pi) ckpool_t *ckp = pi->ckp; char *buf = NULL; connsock_t *cs; - gbtbase_t *gbt; + gbtbase_t gbt; char hash[68]; reconnect: @@ -379,7 +376,6 @@ reconnect: LOGWARNING("%s generator ready", ckp->name); } - gbt = si->data; cs = &si->cs; if (!old_si) LOGWARNING("Connected to bitcoind: %s:%s", cs->url, cs->port); @@ -401,18 +397,18 @@ retry: buf = umsg->buf; LOGDEBUG("Generator received request: %s", buf); if (cmdmatch(buf, "getbase")) { - if (!gen_gbtbase(cs, gbt)) { + if (!gen_gbtbase(cs, &gbt)) { LOGWARNING("Failed to get block template from %s:%s", cs->url, cs->port); si->alive = cs->alive = false; send_unix_msg(umsg->sockd, "Failed"); goto reconnect; } else { - char *s = json_dumps(gbt->json, JSON_NO_UTF8); + char *s = json_dumps(gbt.json, JSON_NO_UTF8); send_unix_msg(umsg->sockd, s); free(s); - clear_gbtbase(gbt); + clear_gbtbase(&gbt); } } else if (cmdmatch(buf, "getbest")) { if (si->notify)