[grits] Add grits_http_abort function



commit fde5359a826dadb68cfe3f62f0f3c9e0c25f3438
Author: Andy Spencer <andy753421 gmail com>
Date:   Wed Jan 23 06:30:53 2013 +0000

    Add grits_http_abort function
    
    This is similar to soup_session_abort, except that it also prevents any
    additional requests from being queued. This prevents long waits if we
    cancel during a loop, as was done in the AWeather alerts plugin.

 src/data/grits-http.c |   18 +++++++++++++++++-
 src/data/grits-http.h |    3 +++
 src/plugins/elev.c    |    2 +-
 src/plugins/map.c     |    4 ++--
 src/plugins/sat.c     |    2 +-
 5 files changed, 24 insertions(+), 5 deletions(-)
---
diff --git a/src/data/grits-http.c b/src/data/grits-http.c
index 01bc705..45b30df 100644
--- a/src/data/grits-http.c
+++ b/src/data/grits-http.c
@@ -59,6 +59,19 @@ GritsHttp *grits_http_new(const gchar *prefix)
 }
 
 /**
+ * grits_http_abort:
+ * @http: the #GritsHttp to abort
+ *
+ * Cancels any pending requests and prevents new requests.
+ */
+void grits_http_abort(GritsHttp *http)
+{
+	g_debug("GritsHttp: abort - %s", http->prefix);
+	http->aborted = TRUE;
+	soup_session_abort(http->soup);
+}
+
+/**
  * grits_http_free:
  * @http: the #GritsHttp to free
  *
@@ -67,7 +80,6 @@ GritsHttp *grits_http_new(const gchar *prefix)
 void grits_http_free(GritsHttp *http)
 {
 	g_debug("GritsHttp: free - %s", http->prefix);
-	soup_session_abort(http->soup);
 	g_object_unref(http->soup);
 	g_free(http->prefix);
 	g_free(http);
@@ -148,6 +160,10 @@ gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const char *local,
 		GritsCacheType mode, GritsChunkCallback callback, gpointer user_data)
 {
 	g_debug("GritsHttp: fetch - %s mode=%d", local, mode);
+	if (http->aborted) {
+		g_debug("GritsPluginSat: _load_tile_thread - aborted");
+		return NULL;
+	}
 	gchar *path = _get_cache_path(http, local);
 
 	/* Unlink the file if we're refreshing it */
diff --git a/src/data/grits-http.h b/src/data/grits-http.h
index 04f9a63..55865bf 100644
--- a/src/data/grits-http.h
+++ b/src/data/grits-http.h
@@ -26,10 +26,13 @@
 typedef struct _GritsHttp {
 	SoupSession *soup;
 	gchar *prefix;
+	gboolean aborted;
 } GritsHttp;
 
 GritsHttp *grits_http_new(const gchar *prefix);
 
+void grits_http_abort(GritsHttp *http);
+
 void grits_http_free(GritsHttp *http);
 
 gchar *grits_http_fetch(GritsHttp *http, const gchar *uri, const gchar *local,
diff --git a/src/plugins/elev.c b/src/plugins/elev.c
index 3fbeb87..3634df6 100644
--- a/src/plugins/elev.c
+++ b/src/plugins/elev.c
@@ -266,7 +266,7 @@ static void grits_plugin_elev_dispose(GObject *gobject)
 	if (elev->viewer) {
 		GritsViewer *viewer = elev->viewer;
 		g_signal_handler_disconnect(viewer, elev->sigid);
-		soup_session_abort(elev->wms->http->soup);
+		grits_http_abort(elev->wms->http);
 		g_thread_pool_free(elev->threads, TRUE, TRUE);
 		elev->viewer = NULL;
 		if (LOAD_BIL)
diff --git a/src/plugins/map.c b/src/plugins/map.c
index 255f67c..23e8b24 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -190,8 +190,8 @@ static void grits_plugin_map_dispose(GObject *gobject)
 	if (map->viewer) {
 		GritsViewer *viewer = map->viewer;
 		g_signal_handler_disconnect(viewer, map->sigid);
-		soup_session_abort(map->tms->http->soup);
-		//soup_session_abort(map->wms->http->soup);
+		grits_http_abort(map->tms->http);
+		//grits_http_abort(map->wms->http);
 		g_thread_pool_free(map->threads, TRUE, TRUE);
 		map->viewer = NULL;
 		grits_viewer_remove(viewer, GRITS_OBJECT(map->tiles));
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index 5389ddb..bf3b598 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -170,7 +170,7 @@ static void grits_plugin_sat_dispose(GObject *gobject)
 	if (sat->viewer) {
 		GritsViewer *viewer = sat->viewer;
 		g_signal_handler_disconnect(viewer, sat->sigid);
-		soup_session_abort(sat->wms->http->soup);
+		grits_http_abort(sat->wms->http);
 		g_thread_pool_free(sat->threads, TRUE, TRUE);
 		sat->viewer = NULL;
 		grits_viewer_remove(viewer, GRITS_OBJECT(sat->tiles));



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