[libsoup] Add soup_session_prepare_for_uri



commit f8ce30a570bdea4da87c69a080101846a0c21588
Author: Dan Winship <danw gnome org>
Date:   Sat Nov 7 14:15:08 2009 -0500

    Add soup_session_prepare_for_uri
    
    Lets the session prepare for a possible upcoming request. (Eg,
    WebKitGTK will call this when the user hovers over a link.) Currently
    just does DNS resolution. Will eventually do proxy resolution as well.
    
    Based on a patch from José Millán Soto
    https://bugzilla.gnome.org/show_bug.cgi?id=598948

 libsoup/soup-session.c |   50 ++++++++++++++++++++++++++++++++++++++++++-----
 libsoup/soup-session.h |    2 +
 2 files changed, 46 insertions(+), 6 deletions(-)
---
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index fc6f524..9c3efdb 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -809,16 +809,12 @@ soup_session_host_new (SoupSession *session, SoupURI *uri)
 	return host;
 }
 
-/* Note: get_host_for_message doesn't lock the host_lock. The caller
- * must do it itself if there's a chance the host doesn't already
- * exist.
- */
+/* Requires host_lock to be locked */
 static SoupSessionHost *
-get_host_for_message (SoupSession *session, SoupMessage *msg)
+get_host_for_uri (SoupSession *session, SoupURI *uri)
 {
 	SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
 	SoupSessionHost *host;
-	SoupURI *uri = soup_message_get_uri (msg);
 
 	host = g_hash_table_lookup (priv->hosts, uri);
 	if (host)
@@ -830,6 +826,16 @@ get_host_for_message (SoupSession *session, SoupMessage *msg)
 	return host;
 }
 
+/* Note: get_host_for_message doesn't lock the host_lock. The caller
+ * must do it itself if there's a chance the host doesn't already
+ * exist.
+ */
+static SoupSessionHost *
+get_host_for_message (SoupSession *session, SoupMessage *msg)
+{
+	return get_host_for_uri (session, soup_message_get_uri (msg));
+}
+
 static void
 free_host (SoupSessionHost *host)
 {
@@ -1522,6 +1528,38 @@ soup_session_abort (SoupSession *session)
 }
 
 /**
+* soup_session_prepare_for_uri:
+* @session: a #SoupSession
+* @uri: a #SoupURI which may be required
+*
+* Tells @session that @uri may be requested shortly, and so the
+* session can try to prepare (resolving the domain name, obtaining
+* proxy address, etc.) in order to work more quickly once the URI is
+* actually requested.
+*
+* This method acts asynchronously, in @session's %async_context.
+* If you are using #SoupSessionSync and do not have a main loop running,
+* then you can't use this method.
+*
+* Since: 2.30
+**/
+void
+soup_session_prepare_for_uri (SoupSession *session, SoupURI *uri)
+{
+	SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
+	SoupSessionHost *host;
+	SoupAddress *addr;
+
+	g_mutex_lock (priv->host_lock);
+	host = get_host_for_uri (session, uri);
+	addr = g_object_ref (host->addr);
+	g_mutex_unlock (priv->host_lock);
+
+	soup_address_resolve_async (addr, priv->async_context,
+				    NULL, NULL, NULL);
+}
+
+/**
  * soup_session_add_feature:
  * @session: a #SoupSession
  * @feature: an object that implements #SoupSessionFeature
diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h
index 598ee45..6080008 100644
--- a/libsoup/soup-session.h
+++ b/libsoup/soup-session.h
@@ -93,6 +93,8 @@ void            soup_session_cancel_message   (SoupSession           *session,
 					       guint                  status_code);
 void            soup_session_abort            (SoupSession           *session);
 
+void            soup_session_prepare_for_uri  (SoupSession           *session,
+					       SoupURI               *uri);
 
 void                soup_session_add_feature            (SoupSession        *session,
 							 SoupSessionFeature *feature);



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