Browse Source

Clean up the longpoll management to ensure the right paths go to the right pool and display whether we're connected to LP or not in the status line.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
1e77f04481
  1. 33
      main.c
  2. 5
      miner.h
  3. 18
      util.c

33
main.c

@ -172,8 +172,8 @@ static const sha256_func sha256_funcs[] = { @@ -172,8 +172,8 @@ static const sha256_func sha256_funcs[] = {
bool opt_debug = false;
bool opt_protocol = false;
bool want_longpoll = true;
bool have_longpoll = false;
static bool want_longpoll = true;
static bool have_longpoll = false;
bool use_syslog = false;
static bool opt_quiet = false;
static bool opt_realquiet = false;
@ -1328,9 +1328,11 @@ static void curses_print_status(int thr_id) @@ -1328,9 +1328,11 @@ static void curses_print_status(int thr_id)
wclrtoeol(statuswin);
wmove(statuswin, 4, 0);
if (pool_strategy == POOL_LOADBALANCE && total_pools > 1)
wprintw(statuswin, " Connected to multiple pools");
wprintw(statuswin, " Connected to multiple pools with%s LP",
have_longpoll ? "": "out");
else
wprintw(statuswin, " Connected to %s as user %s", pool->rpc_url, pool->rpc_user);
wprintw(statuswin, " Connected to %s with%s LP as user %s",
pool->rpc_url, have_longpoll ? "": "out", pool->rpc_user);
wclrtoeol(statuswin);
wmove(statuswin, 5, 0);
wprintw(statuswin, " Block: %s... Started: %s", current_hash, blocktime);
@ -1603,7 +1605,7 @@ static bool get_upstream_work(struct work *work, bool lagging) @@ -1603,7 +1605,7 @@ static bool get_upstream_work(struct work *work, bool lagging)
applog(LOG_DEBUG, "DBG: sending %s get RPC call: %s", pool->rpc_url, rpc_req);
val = json_rpc_call(curl, pool->rpc_url, pool->rpc_userpass, rpc_req,
want_longpoll, false, &work->rolltime, pool);
false, false, &work->rolltime, pool);
if (unlikely(!val)) {
applog(LOG_DEBUG, "Failed json_rpc_call in get_upstream_work");
goto out;
@ -2127,6 +2129,7 @@ static void display_pool_summary(struct pool *pool) @@ -2127,6 +2129,7 @@ static void display_pool_summary(struct pool *pool)
mutex_lock(&curses_lock);
wlog("Pool: %s\n", pool->rpc_url);
wlog("%s long-poll support\n", pool->hdr_path ? "Has" : "Does not have");
wlog(" Queued work requests: %d\n", pool->getwork_requested);
wlog(" Share submissions: %d\n", pool->accepted + pool->rejected);
wlog(" Accepted shares: %d\n", pool->accepted);
@ -3726,14 +3729,12 @@ static void *longpoll_thread(void *userdata) @@ -3726,14 +3729,12 @@ static void *longpoll_thread(void *userdata)
goto out;
}
if (opt_debug)
applog(LOG_DEBUG, "Popping hdr path in longpoll thread");
hdr_path = tq_pop(mythr->q, NULL);
if (!hdr_path) {
tq_pop(mythr->q, NULL);
if (!pool->hdr_path) {
applog(LOG_WARNING, "No long-poll found on this server");
goto out;
}
hdr_path = pool->hdr_path;
/* full URL */
if (strstr(hdr_path, "://")) {
@ -3753,8 +3754,8 @@ static void *longpoll_thread(void *userdata) @@ -3753,8 +3754,8 @@ static void *longpoll_thread(void *userdata)
sprintf(lp_url, "%s%s%s", pool->rpc_url, need_slash ? "/" : "", copy_start);
}
free(hdr_path);
have_longpoll = true;
applog(LOG_WARNING, "Long-polling activated for %s", lp_url);
while (1) {
@ -3802,6 +3803,7 @@ static void *longpoll_thread(void *userdata) @@ -3802,6 +3803,7 @@ static void *longpoll_thread(void *userdata)
}
out:
have_longpoll = false;
free(lp_url);
tq_freeze(mythr->q);
if (curl)
@ -3827,6 +3829,9 @@ static void start_longpoll(void) @@ -3827,6 +3829,9 @@ static void start_longpoll(void)
if (unlikely(thr_info_create(thr, NULL, longpoll_thread, thr)))
quit(1, "longpoll thread create failed");
pthread_detach(*thr->pth);
if (opt_debug)
applog(LOG_DEBUG, "Pushing ping to longpoll thread");
tq_push(thr_info[longpoll_thr_id].q, &ping);
}
static void restart_longpoll(void)
@ -4598,9 +4603,6 @@ int main (int argc, char *argv[]) @@ -4598,9 +4603,6 @@ int main (int argc, char *argv[])
if (!thr->q)
quit(1, "Failed to tq_new");
if (want_longpoll)
start_longpoll();
if (opt_n_threads ) {
cpus = calloc(num_processors, sizeof(struct cgpu_info));
if (unlikely(!cpus))
@ -4649,6 +4651,9 @@ int main (int argc, char *argv[]) @@ -4649,6 +4651,9 @@ int main (int argc, char *argv[])
if (!pools_active)
quit(0, "No pools active! Exiting.");
if (want_longpoll)
start_longpoll();
#ifdef HAVE_OPENCL
/* start GPU mining threads */
for (i = 0; i < nDevs * opt_g_threads; i++) {

5
miner.h

@ -261,8 +261,6 @@ timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y); @@ -261,8 +261,6 @@ timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
extern bool fulltest(const unsigned char *hash, const unsigned char *target);
extern int opt_scantime;
extern bool want_longpoll;
extern bool have_longpoll;
struct thread_q;
struct work_restart {
@ -305,6 +303,9 @@ struct pool { @@ -305,6 +303,9 @@ struct pool {
bool idle;
bool probed;
bool enabled;
char *hdr_path;
unsigned int getwork_requested;
unsigned int stale_shares;
unsigned int discarded_work;

18
util.c

@ -318,7 +318,7 @@ json_t *json_rpc_call(CURL *curl, const char *url, @@ -318,7 +318,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
/* it is assumed that 'curl' is freshly [re]initialized at this pt */
if (probe) {
probing = ((want_longpoll && !have_longpoll) || !pool->probed);
probing = !pool->probed;
/* Probe for only 15 seconds */
timeout = 15;
}
@ -378,21 +378,17 @@ json_t *json_rpc_call(CURL *curl, const char *url, @@ -378,21 +378,17 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out;
}
if (!have_longpoll && want_longpoll) {
if (probing) {
pool->probed = true;
/* If X-Long-Polling was found, activate long polling */
if (hi.lp_path) {
have_longpoll = true;
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
} else
free(hi.lp_path);
if (hi.lp_path)
pool->hdr_path = hi.lp_path;
else
pool->hdr_path = NULL;
}
if (probing)
pool->probed = true;
*rolltime = hi.has_rolltime;
hi.lp_path = NULL;
val = JSON_LOADS(all_data.buf, &err);
if (!val) {
applog(LOG_INFO, "JSON decode failed(%d): %s", err.line, err.text);

Loading…
Cancel
Save