From 321c4798d4813d8835ee1c23fcd16cdc837bfc36 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 19 Jul 2011 10:53:04 +1000 Subject: [PATCH] Make longpoll switch servers should it not match the current pool. --- main.c | 30 ++++++++++++++++++++---------- util.c | 14 ++++++++------ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 7f76adec..e846acd5 100644 --- a/main.c +++ b/main.c @@ -1989,9 +1989,19 @@ static void *longpoll_thread(void *userdata) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - hdr_path = tq_pop(mythr->q, NULL); - if (!hdr_path) + curl = curl_easy_init(); + if (unlikely(!curl)) { + applog(LOG_ERR, "CURL initialisation failed"); 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 */ 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); } + free(hdr_path); - applog(LOG_INFO, "Long-polling activated for %s", lp_url); - - curl = curl_easy_init(); - if (unlikely(!curl)) { - applog(LOG_ERR, "CURL initialisation failed"); - goto out; - } + applog(LOG_WARNING, "Long-polling activated for %s", lp_url); while (1) { struct timeval start, end; @@ -2060,10 +2065,15 @@ static void *longpoll_thread(void *userdata) } } 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: - free(hdr_path); free(lp_url); tq_freeze(mythr->q); if (curl) diff --git a/util.c b/util.c index f017cdeb..c4124330 100644 --- a/util.c +++ b/util.c @@ -315,12 +315,14 @@ json_t *json_rpc_call(CURL *curl, const char *url, goto err_out; } - /* 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 (!have_longpoll) { + /* 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); + } hi.lp_path = NULL; val = JSON_LOADS(all_data.buf, &err);