[couchdb-glib] Set a shorter timeout (1 minute) for localhost polling



commit 328b984addfd0b856482422d9ff00d6334be3a47
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Fri Nov 6 11:23:25 2009 +0100

    Set a shorter timeout (1 minute) for localhost polling

 couchdb-glib/dbwatch.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/couchdb-glib/dbwatch.c b/couchdb-glib/dbwatch.c
index dc20f50..dade2d2 100644
--- a/couchdb-glib/dbwatch.c
+++ b/couchdb-glib/dbwatch.c
@@ -24,7 +24,8 @@
 #include "dbwatch.h"
 #include "utils.h"
 
-#define TIMEOUT_SECONDS 300
+#define LOCAL_TIMEOUT_SECONDS  60
+#define REMOTE_TIMEOUT_SECONDS 300
 
 static void
 process_change (DBWatch *watch, JsonNode *node)
@@ -115,6 +116,7 @@ DBWatch *
 dbwatch_new (CouchDB *couchdb, const gchar *dbname, gint update_seq)
 {
 	DBWatch *watch;
+	guint timeout;
 
 	watch = g_new0 (DBWatch, 1);
 	watch->couchdb = couchdb;
@@ -122,7 +124,12 @@ dbwatch_new (CouchDB *couchdb, const gchar *dbname, gint update_seq)
 	watch->last_update_seq = update_seq;
 
 	/* Set timeout to check for changes every 5 minutes*/
-	watch->timeout_id = g_timeout_add (TIMEOUT_SECONDS * 1000, (GSourceFunc) watch_timeout_cb, watch);
+	if (g_str_has_prefix (watch->couchdb->hostname, "http://127.0.0.1";))
+		timeout = LOCAL_TIMEOUT_SECONDS;
+	else
+		timeout = REMOTE_TIMEOUT_SECONDS;
+
+	watch->timeout_id = g_timeout_add (timeout * 1000, (GSourceFunc) watch_timeout_cb, watch);
 	
 	return watch;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]