From c36cc61f648512531de6dc7944fb499c4bb056db Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 14 Jul 2011 22:16:06 +1000 Subject: [PATCH] Ensure we connect at least once successfully before continuing to try to connect. --- main.c | 36 +++++++++++++++++++----------------- miner.h | 2 ++ util.c | 7 +++++++ 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 81dadb1e..f5ba3c17 100644 --- a/main.c +++ b/main.c @@ -756,12 +756,25 @@ static void workio_cmd_free(struct workio_cmd *wc) free(wc); } -static void kill_work(void) +static void disable_curses(void) +{ + if (curses_active) { + curses_active = false; + delwin(logwin); + delwin(statuswin); + delwin(mainwin); + endwin(); + refresh(); + } +} + +void kill_work(void) { struct workio_cmd *wc; struct thr_info *thr; unsigned int i; + disable_curses(); applog(LOG_INFO, "Received kill message"); /* Kill the watchdog thread */ @@ -796,19 +809,6 @@ static void kill_work(void) applog(LOG_ERR, "Failed to tq_push work in kill_work"); exit (1); } - -} - -static void disable_curses(void) -{ - if (curses_active) { - curses_active = false; - delwin(logwin); - delwin(statuswin); - delwin(mainwin); - endwin(); - refresh(); - } } static void sighandler(int sig) @@ -2004,12 +2004,14 @@ static void print_summary(void) printf("\nSummary of runtime statistics:\n\n"); printf("Started at %s\n", datestamp); printf("Runtime: %d hrs : %d mins : %d secs\n", hours, mins, secs); - printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs); + if (total_secs) + printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs); printf("Queued work requests: %d\n", getwork_requested); printf("Share submissions: %d\n", accepted + rejected); printf("Accepted shares: %d\n", accepted); printf("Rejected shares: %d\n", rejected); - printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected)); + if (accepted || rejected) + printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected)); printf("Hardware errors: %d\n", hw_errors); printf("Efficiency (accepted / queued): %.0f%%\n", efficiency); printf("Utility (accepted shares / min): %.2f/min\n\n", utility); @@ -2332,7 +2334,7 @@ int main (int argc, char *argv[]) gettimeofday(&total_tv_end, NULL); curl_global_cleanup(); disable_curses(); - if (!opt_quiet) + if (!opt_quiet && successful_connect) print_summary(); if (gpu_threads) diff --git a/miner.h b/miner.h index 6ff9e1cd..53a537e1 100644 --- a/miner.h +++ b/miner.h @@ -269,6 +269,7 @@ struct work { bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce); +extern void kill_work(void); extern void log_curses(const char *f, va_list ap); extern void vapplog(int prio, const char *fmt, va_list ap); extern void applog(int prio, const char *fmt, ...); @@ -278,5 +279,6 @@ extern bool tq_push(struct thread_q *tq, void *data); extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime); extern void tq_freeze(struct thread_q *tq); extern void tq_thaw(struct thread_q *tq); +extern bool successful_connect; #endif /* __MINER_H__ */ diff --git a/util.c b/util.c index 0a72d635..ad4cd408 100644 --- a/util.c +++ b/util.c @@ -32,6 +32,8 @@ #define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr)) #endif +bool successful_connect = false; + struct data_buffer { void *buf; size_t len; @@ -340,6 +342,7 @@ json_t *json_rpc_call(CURL *curl, const char *url, goto err_out; } + successful_connect = true; comms_error = false; databuf_free(&all_data); curl_slist_free_all(headers); @@ -350,6 +353,10 @@ err_out: databuf_free(&all_data); curl_slist_free_all(headers); curl_easy_reset(curl); + if (!successful_connect) { + kill_work(); + applog(LOG_ERR, "Failed to connect - wrong URL or login details?"); + } return NULL; }