Browse Source

Ensure we connect at least once successfully before continuing to try to connect.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
c36cc61f64
  1. 32
      main.c
  2. 2
      miner.h
  3. 7
      util.c

32
main.c

@ -756,12 +756,25 @@ static void workio_cmd_free(struct workio_cmd *wc)
free(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 workio_cmd *wc;
struct thr_info *thr; struct thr_info *thr;
unsigned int i; unsigned int i;
disable_curses();
applog(LOG_INFO, "Received kill message"); applog(LOG_INFO, "Received kill message");
/* Kill the watchdog thread */ /* Kill the watchdog thread */
@ -796,19 +809,6 @@ static void kill_work(void)
applog(LOG_ERR, "Failed to tq_push work in kill_work"); applog(LOG_ERR, "Failed to tq_push work in kill_work");
exit (1); 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) static void sighandler(int sig)
@ -2004,11 +2004,13 @@ static void print_summary(void)
printf("\nSummary of runtime statistics:\n\n"); printf("\nSummary of runtime statistics:\n\n");
printf("Started at %s\n", datestamp); printf("Started at %s\n", datestamp);
printf("Runtime: %d hrs : %d mins : %d secs\n", hours, mins, secs); printf("Runtime: %d hrs : %d mins : %d secs\n", hours, mins, secs);
if (total_secs)
printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs); printf("Average hashrate: %.1f Megahash/s\n", total_mhashes_done / total_secs);
printf("Queued work requests: %d\n", getwork_requested); printf("Queued work requests: %d\n", getwork_requested);
printf("Share submissions: %d\n", accepted + rejected); printf("Share submissions: %d\n", accepted + rejected);
printf("Accepted shares: %d\n", accepted); printf("Accepted shares: %d\n", accepted);
printf("Rejected shares: %d\n", rejected); printf("Rejected shares: %d\n", rejected);
if (accepted || rejected)
printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected)); printf("Reject ratio: %.1f\n", (double)(rejected * 100) / (double)(accepted + rejected));
printf("Hardware errors: %d\n", hw_errors); printf("Hardware errors: %d\n", hw_errors);
printf("Efficiency (accepted / queued): %.0f%%\n", efficiency); printf("Efficiency (accepted / queued): %.0f%%\n", efficiency);
@ -2332,7 +2334,7 @@ int main (int argc, char *argv[])
gettimeofday(&total_tv_end, NULL); gettimeofday(&total_tv_end, NULL);
curl_global_cleanup(); curl_global_cleanup();
disable_curses(); disable_curses();
if (!opt_quiet) if (!opt_quiet && successful_connect)
print_summary(); print_summary();
if (gpu_threads) if (gpu_threads)

2
miner.h

@ -269,6 +269,7 @@ struct work {
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce); 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 log_curses(const char *f, va_list ap);
extern void vapplog(int prio, const char *fmt, va_list ap); extern void vapplog(int prio, const char *fmt, va_list ap);
extern void applog(int prio, const char *fmt, ...); 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_pop(struct thread_q *tq, const struct timespec *abstime);
extern void tq_freeze(struct thread_q *tq); extern void tq_freeze(struct thread_q *tq);
extern void tq_thaw(struct thread_q *tq); extern void tq_thaw(struct thread_q *tq);
extern bool successful_connect;
#endif /* __MINER_H__ */ #endif /* __MINER_H__ */

7
util.c

@ -32,6 +32,8 @@
#define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr)) #define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
#endif #endif
bool successful_connect = false;
struct data_buffer { struct data_buffer {
void *buf; void *buf;
size_t len; size_t len;
@ -340,6 +342,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out; goto err_out;
} }
successful_connect = true;
comms_error = false; comms_error = false;
databuf_free(&all_data); databuf_free(&all_data);
curl_slist_free_all(headers); curl_slist_free_all(headers);
@ -350,6 +353,10 @@ err_out:
databuf_free(&all_data); databuf_free(&all_data);
curl_slist_free_all(headers); curl_slist_free_all(headers);
curl_easy_reset(curl); curl_easy_reset(curl);
if (!successful_connect) {
kill_work();
applog(LOG_ERR, "Failed to connect - wrong URL or login details?");
}
return NULL; return NULL;
} }

Loading…
Cancel
Save