Permalink
Browse files

bug 1719 - moxi should not run when passed a bad REST/URL

With this change, if libconflate cannot contact the REST/HTTP server
at the given URL the first time, it exits the process.

A better change would be to callback the caller/libconflate-API-client
so that the program (such as moxi) can cleanup more effectively.
Since all API users (like moxi) are currently stateless, this isn't
completely horrible at the moment.

Change-Id: I06ec533e6c72dd5a2c1412df8254f48afa186412
Reviewed-on: http://review.northscale.com/1099
Reviewed-by: Dustin Sallings <dustin@spy.net>
Tested-by: Dustin Sallings <dustin@spy.net>
  • Loading branch information...
1 parent fb3bffc commit 420faf47fa6c1ee3564f21dc8cde57056670aa06 @steveyen steveyen committed with dustin Jul 12, 2010
Showing with 15 additions and 2 deletions.
  1. +15 −2 rest.c
View
17 rest.c
@@ -1,7 +1,7 @@
-
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
+#include <unistd.h>
#include <string.h>
#include <curl/curl.h>
@@ -177,9 +177,22 @@ void* run_rest_conflate(void *arg) {
setup_handle(curl_handle, handle->conf->jid, handle->conf->pass,
handle->conf->host, "", handle, handle_response);
+ bool first = true;
+
/* get initial config and notify call back */
while (true) {
- curl_easy_perform(curl_handle);
+ if (curl_easy_perform(curl_handle) == 0) {
+ first = false;
+ } else {
+ if (first) {
+ /* the first time, exit rather than retry */
+ printf("ERROR: could not contact REST server: %s\n", handle->conf->host);
+ exit(1);
+ }
+
+ /* otherwise, don't kill the server with tons of retries */
+ sleep(1);
+ }
}
free_response(response_buffer_head);

0 comments on commit 420faf4

Please sign in to comment.