Make longpoll switch servers should it not match the current pool.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/main.c b/main.c
index 7f76ade..e846acd 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 f017cde..c412433 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);