diff options
author | Dan Winship <danw@gnome.org> | 2013-12-09 13:24:27 +0100 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-05-02 09:03:57 -0400 |
commit | ca47f77b3b672cf158863246702d3e4050f60481 (patch) | |
tree | bfb18e185b1d5f57cc5248e36af8d74139d6013b /libsoup/soup-socket-properties.c | |
parent | 24378ecafe7e62b1f45ebe38ae3aed73f1ac480e (diff) | |
download | libsoup-ca47f77b3b672cf158863246702d3e4050f60481.tar.gz |
soup-socket: Add SoupSocketProperties to transfer props from session to socket
There are a large number of SoupSession properties that need to be
propagated through the SoupConnection to the SoupSocket. Wrap them all
up into a single struct for ease of carrying.
Diffstat (limited to 'libsoup/soup-socket-properties.c')
-rw-r--r-- | libsoup/soup-socket-properties.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/libsoup/soup-socket-properties.c b/libsoup/soup-socket-properties.c new file mode 100644 index 00000000..a7ed5128 --- /dev/null +++ b/libsoup/soup-socket-properties.c @@ -0,0 +1,74 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright 2013 Red Hat, Inc. + */ + +#include "soup-socket-private.h" +#include "soup.h" + +SoupSocketProperties * +soup_socket_properties_new (GMainContext *async_context, + gboolean use_thread_context, + GProxyResolver *proxy_resolver, + SoupAddress *local_addr, + GTlsDatabase *tlsdb, + gboolean ssl_strict, + guint io_timeout, + guint idle_timeout) +{ + SoupSocketProperties *props; + + props = g_slice_new (SoupSocketProperties); + props->ref_count = 1; + + props->async_context = async_context ? g_main_context_ref (async_context) : NULL; + props->use_thread_context = use_thread_context; + + props->proxy_resolver = proxy_resolver ? g_object_ref (proxy_resolver) : NULL; + props->local_addr = local_addr ? g_object_ref (local_addr) : NULL; + + props->tlsdb = tlsdb ? g_object_ref (tlsdb) : NULL; + props->ssl_strict = ssl_strict; + + props->io_timeout = io_timeout; + props->idle_timeout = idle_timeout; + + return props; +} + +SoupSocketProperties * +soup_socket_properties_ref (SoupSocketProperties *props) +{ + props->ref_count++; + return props; +} + +void +soup_socket_properties_unref (SoupSocketProperties *props) +{ + if (--props->ref_count) + return; + + g_clear_pointer (&props->async_context, g_main_context_unref); + g_clear_object (&props->proxy_resolver); + g_clear_object (&props->local_addr); + g_clear_object (&props->tlsdb); + + g_slice_free (SoupSocketProperties, props); +} + +void +soup_socket_properties_push_async_context (SoupSocketProperties *props) +{ + if (props->async_context && !props->use_thread_context) + g_main_context_push_thread_default (props->async_context); +} + +void +soup_socket_properties_pop_async_context (SoupSocketProperties *props) +{ + if (props->async_context && !props->use_thread_context) + g_main_context_pop_thread_default (props->async_context); +} + +G_DEFINE_BOXED_TYPE (SoupSocketProperties, soup_socket_properties, soup_socket_properties_ref, soup_socket_properties_unref) |