Browse Source

Make longpoll switch servers should it not match the current pool.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
321c4798d4
  1. 30
      main.c
  2. 14
      util.c

30
main.c

@ -1989,9 +1989,19 @@ static void *longpoll_thread(void *userdata)
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
hdr_path = tq_pop(mythr->q, NULL); curl = curl_easy_init();
if (!hdr_path) if (unlikely(!curl)) {
applog(LOG_ERR, "CURL initialisation failed");
goto out; goto out;
}
/* Longpoll sits waiting on next pushed url */
next_path:
hdr_path = tq_pop(mythr->q, NULL);
if (!hdr_path) {
applog(LOG_WARNING, "No long-poll found on this server");
goto next_path;
}
/* full URL */ /* full URL */
if (strstr(hdr_path, "://")) { if (strstr(hdr_path, "://")) {
@ -2011,14 +2021,9 @@ static void *longpoll_thread(void *userdata)
sprintf(lp_url, "%s%s%s", pool->rpc_url, need_slash ? "/" : "", copy_start); sprintf(lp_url, "%s%s%s", pool->rpc_url, need_slash ? "/" : "", copy_start);
} }
free(hdr_path);
applog(LOG_INFO, "Long-polling activated for %s", lp_url); applog(LOG_WARNING, "Long-polling activated for %s", lp_url);
curl = curl_easy_init();
if (unlikely(!curl)) {
applog(LOG_ERR, "CURL initialisation failed");
goto out;
}
while (1) { while (1) {
struct timeval start, end; struct timeval start, end;
@ -2060,10 +2065,15 @@ static void *longpoll_thread(void *userdata)
} }
} }
memcpy(longpoll_block, current_block, 36); memcpy(longpoll_block, current_block, 36);
if (pool != current_pool()) {
applog(LOG_WARNING, "Attempting to change longpoll servers");
pool = current_pool();
have_longpoll = false;
goto next_path;
}
} }
out: out:
free(hdr_path);
free(lp_url); free(lp_url);
tq_freeze(mythr->q); tq_freeze(mythr->q);
if (curl) if (curl)

14
util.c

@ -315,12 +315,14 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out; goto err_out;
} }
/* If X-Long-Polling was found, activate long polling */ if (!have_longpoll) {
if (hi.lp_path) { /* If X-Long-Polling was found, activate long polling */
have_longpoll = true; if (hi.lp_path) {
tq_push(thr_info[longpoll_thr_id].q, hi.lp_path); have_longpoll = true;
} else tq_push(thr_info[longpoll_thr_id].q, hi.lp_path);
free(hi.lp_path); } else
free(hi.lp_path);
}
hi.lp_path = NULL; hi.lp_path = NULL;
val = JSON_LOADS(all_data.buf, &err); val = JSON_LOADS(all_data.buf, &err);

Loading…
Cancel
Save