[gvfs] http: Use a global SoupSession rather than per-backend
- From: Ross Lagerwall <rossl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs] http: Use a global SoupSession rather than per-backend
- Date: Fri, 25 Jul 2014 16:20:50 +0000 (UTC)
commit 449a4b878695de6e545fadaa7fe846d7deb64acc
Author: Ross Lagerwall <rosslagerwall gmail com>
Date: Tue Jul 1 22:59:13 2014 +0100
http: Use a global SoupSession rather than per-backend
Use a global SoupSession rather than a per-backend so that idle
connections are reused appropriately. This prevents a process running
out of file descriptors due to connections stuck in a CLOSE_WAIT state.
It also has the side-effect of limiting the maximum number of concurrent
connections because libsoup's max-conns property is respected, fixing
bug 576460.
(Reapplying now that #732783 and #732925 have been fixed.)
https://bugzilla.gnome.org/show_bug.cgi?id=732090
daemon/gvfsbackendhttp.c | 85 ++++++++++++++++++++++++----------------------
1 files changed, 44 insertions(+), 41 deletions(-)
---
diff --git a/daemon/gvfsbackendhttp.c b/daemon/gvfsbackendhttp.c
index 763b7db..2056a4a 100644
--- a/daemon/gvfsbackendhttp.c
+++ b/daemon/gvfsbackendhttp.c
@@ -51,6 +51,8 @@
#include "gvfsdaemonprotocol.h"
#include "gvfsdaemonutils.h"
+static SoupSession *the_session;
+
G_DEFINE_TYPE (GVfsBackendHttp, g_vfs_backend_http, G_VFS_TYPE_BACKEND)
static void
@@ -63,7 +65,6 @@ g_vfs_backend_http_finalize (GObject *object)
if (backend->mount_base)
soup_uri_free (backend->mount_base);
- soup_session_abort (backend->session);
g_object_unref (backend->session);
@@ -71,51 +72,12 @@ g_vfs_backend_http_finalize (GObject *object)
(*G_OBJECT_CLASS (g_vfs_backend_http_parent_class)->finalize) (object);
}
-#define DEBUG_MAX_BODY_SIZE (100 * 1024 * 1024)
-
static void
g_vfs_backend_http_init (GVfsBackendHttp *backend)
{
- const char *debug;
- SoupSessionFeature *cookie_jar;
-
g_vfs_backend_set_user_visible (G_VFS_BACKEND (backend), FALSE);
- backend->session = soup_session_new_with_options ("user-agent",
- "gvfs/" VERSION,
- NULL);
-
- g_object_set (backend->session, "ssl-strict", FALSE, NULL);
-
- /* Cookie handling - stored temporarlly in memory, mostly useful for
- * authentication in WebDAV. */
- cookie_jar = g_object_new (SOUP_TYPE_COOKIE_JAR, NULL);
- soup_session_add_feature (backend->session, cookie_jar);
- g_object_unref (cookie_jar);
-
- /* Send Accept-Language header (see bug 166795) */
- g_object_set (backend->session, "accept-language-auto", TRUE, NULL);
-
- /* Logging */
- debug = g_getenv ("GVFS_HTTP_DEBUG");
- if (debug)
- {
- SoupLogger *logger;
- SoupLoggerLogLevel level;
-
- if (g_ascii_strcasecmp (debug, "all") ||
- g_ascii_strcasecmp (debug, "body"))
- level = SOUP_LOGGER_LOG_BODY;
- else if (g_ascii_strcasecmp (debug, "header"))
- level = SOUP_LOGGER_LOG_HEADERS;
- else
- level = SOUP_LOGGER_LOG_MINIMAL;
-
- logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE);
- soup_session_add_feature (backend->session, SOUP_SESSION_FEATURE (logger));
- g_object_unref (logger);
- }
-
+ backend->session = g_object_ref (the_session);
}
/* ************************************************************************* */
@@ -697,9 +659,14 @@ try_query_info_on_read (GVfsBackend *backend,
}
+#define DEBUG_MAX_BODY_SIZE (100 * 1024 * 1024)
+
static void
g_vfs_backend_http_class_init (GVfsBackendHttpClass *klass)
{
+ const char *debug;
+ SoupSessionFeature *cookie_jar;
+
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GVfsBackendClass *backend_class;
@@ -714,4 +681,40 @@ g_vfs_backend_http_class_init (GVfsBackendHttpClass *klass)
backend_class->try_close_read = try_close_read;
backend_class->try_query_info = try_query_info;
backend_class->try_query_info_on_read = try_query_info_on_read;
+
+ /* Initialize the SoupSession, common to all backend instances */
+ the_session = soup_session_new_with_options ("user-agent",
+ "gvfs/" VERSION,
+ NULL);
+
+ g_object_set (the_session, "ssl-strict", FALSE, NULL);
+
+ /* Cookie handling - stored temporarlly in memory, mostly useful for
+ * authentication in WebDAV. */
+ cookie_jar = g_object_new (SOUP_TYPE_COOKIE_JAR, NULL);
+ soup_session_add_feature (the_session, cookie_jar);
+ g_object_unref (cookie_jar);
+
+ /* Send Accept-Language header (see bug 166795) */
+ g_object_set (the_session, "accept-language-auto", TRUE, NULL);
+
+ /* Logging */
+ debug = g_getenv ("GVFS_HTTP_DEBUG");
+ if (debug)
+ {
+ SoupLogger *logger;
+ SoupLoggerLogLevel level;
+
+ if (g_ascii_strcasecmp (debug, "all") ||
+ g_ascii_strcasecmp (debug, "body"))
+ level = SOUP_LOGGER_LOG_BODY;
+ else if (g_ascii_strcasecmp (debug, "header"))
+ level = SOUP_LOGGER_LOG_HEADERS;
+ else
+ level = SOUP_LOGGER_LOG_MINIMAL;
+
+ logger = soup_logger_new (level, DEBUG_MAX_BODY_SIZE);
+ soup_session_add_feature (the_session, SOUP_SESSION_FEATURE (logger));
+ g_object_unref (logger);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]