[libsoup/http2] Add SoupSocketProperties to transfer props from session to socket
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/http2] Add SoupSocketProperties to transfer props from session to socket
- Date: Mon, 9 Dec 2013 12:32:43 +0000 (UTC)
commit 67ae809a555226a1e48db9c4c8eace9f6d91514d
Author: Dan Winship <danw gnome org>
Date: Mon Dec 9 13:24:27 2013 +0100
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 (and now the SoupSessionHost) to
the SoupSocket. Wrap them all up into a single struct for ease of
carrying.
libsoup/Makefile.am | 2 +
libsoup/soup-connection.c | 183 +++++--------------------------------
libsoup/soup-connection.h | 17 +---
libsoup/soup-misc-private.h | 2 +-
libsoup/soup-session-host.c | 37 ++-------
libsoup/soup-session-private.h | 2 +
libsoup/soup-session.c | 22 +++++
libsoup/soup-socket-properties.c | 74 +++++++++++++++
libsoup/soup-socket-properties.h | 50 ++++++++++
libsoup/soup-socket.c | 56 ++++++++----
10 files changed, 226 insertions(+), 219 deletions(-)
---
diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am
index fdbda5b..73b4fb5 100644
--- a/libsoup/Makefile.am
+++ b/libsoup/Makefile.am
@@ -188,6 +188,8 @@ libsoup_2_4_la_SOURCES = \
soup-socket.c \
soup-socket-io-stream.h \
soup-socket-io-stream.c \
+ soup-socket-properties.h \
+ soup-socket-properties.c \
soup-status.c \
soup-tld.c \
soup-tld-private.h \
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 2b5dc49..f59a9f8 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -13,23 +13,18 @@
#include "soup.h"
#include "soup-message-queue.h"
#include "soup-misc-private.h"
+#include "soup-socket-properties.h"
typedef struct {
SoupSocket *socket;
+ SoupSocketProperties *socket_props;
- SoupAddress *local_addr;
SoupURI *remote_uri, *proxy_uri;
- GProxyResolver *proxy_resolver;
- GTlsDatabase *tlsdb;
- gboolean ssl, ssl_strict, ssl_fallback;
-
- GMainContext *async_context;
- gboolean use_thread_context;
+ gboolean ssl, ssl_fallback;
SoupMessage *current_msg;
SoupConnectionState state;
time_t unused_timeout;
- guint io_timeout, idle_timeout;
GSource *idle_timeout_src;
gboolean reusable;
} SoupConnectionPrivate;
@@ -48,17 +43,9 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
- PROP_LOCAL_ADDRESS,
PROP_REMOTE_URI,
- PROP_PROXY_RESOLVER,
- PROP_SSL,
- PROP_SSL_CREDS,
- PROP_SSL_STRICT,
PROP_SSL_FALLBACK,
- PROP_ASYNC_CONTEXT,
- PROP_USE_THREAD_CONTEXT,
- PROP_TIMEOUT,
- PROP_IDLE_TIMEOUT,
+ PROP_SOCKET_PROPERTIES,
PROP_STATE,
LAST_PROP
@@ -83,10 +70,7 @@ soup_connection_finalize (GObject *object)
g_clear_pointer (&priv->remote_uri, soup_uri_free);
g_clear_pointer (&priv->proxy_uri, soup_uri_free);
- g_clear_object (&priv->tlsdb);
- g_clear_object (&priv->proxy_resolver);
- g_clear_object (&priv->local_addr);
- g_clear_pointer (&priv->async_context, g_main_context_unref);
+ g_clear_pointer (&priv->socket_props, soup_socket_properties_unref);
G_OBJECT_CLASS (soup_connection_parent_class)->finalize (object);
}
@@ -114,42 +98,15 @@ soup_connection_set_property (GObject *object, guint prop_id,
SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_LOCAL_ADDRESS:
- priv->local_addr = g_value_dup_object (value);
- break;
case PROP_REMOTE_URI:
priv->remote_uri = g_value_dup_boxed (value);
- break;
- case PROP_PROXY_RESOLVER:
- priv->proxy_resolver = g_value_dup_object (value);
- break;
- case PROP_SSL:
- priv->ssl = g_value_get_boolean (value);
- break;
- case PROP_SSL_CREDS:
- if (priv->tlsdb)
- g_object_unref (priv->tlsdb);
- priv->tlsdb = g_value_dup_object (value);
- break;
- case PROP_SSL_STRICT:
- priv->ssl_strict = g_value_get_boolean (value);
+ priv->ssl = (priv->remote_uri->scheme == SOUP_URI_SCHEME_HTTPS);
break;
case PROP_SSL_FALLBACK:
priv->ssl_fallback = g_value_get_boolean (value);
break;
- case PROP_ASYNC_CONTEXT:
- priv->async_context = g_value_get_pointer (value);
- if (priv->async_context)
- g_main_context_ref (priv->async_context);
- break;
- case PROP_USE_THREAD_CONTEXT:
- priv->use_thread_context = g_value_get_boolean (value);
- break;
- case PROP_TIMEOUT:
- priv->io_timeout = g_value_get_uint (value);
- break;
- case PROP_IDLE_TIMEOUT:
- priv->idle_timeout = g_value_get_uint (value);
+ case PROP_SOCKET_PROPERTIES:
+ priv->socket_props = g_value_dup_boxed (value);
break;
case PROP_STATE:
soup_connection_set_state (SOUP_CONNECTION (object), g_value_get_uint (value));
@@ -167,35 +124,14 @@ soup_connection_get_property (GObject *object, guint prop_id,
SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (object);
switch (prop_id) {
- case PROP_LOCAL_ADDRESS:
- g_value_set_object (value, priv->local_addr);
- break;
case PROP_REMOTE_URI:
g_value_set_boxed (value, priv->remote_uri);
break;
- case PROP_SSL:
- g_value_set_boolean (value, priv->ssl);
- break;
- case PROP_SSL_CREDS:
- g_value_set_object (value, priv->tlsdb);
- break;
- case PROP_SSL_STRICT:
- g_value_set_boolean (value, priv->ssl_strict);
- break;
case PROP_SSL_FALLBACK:
g_value_set_boolean (value, priv->ssl_fallback);
break;
- case PROP_ASYNC_CONTEXT:
- g_value_set_pointer (value, priv->async_context ? g_main_context_ref (priv->async_context) :
NULL);
- break;
- case PROP_USE_THREAD_CONTEXT:
- g_value_set_boolean (value, priv->use_thread_context);
- break;
- case PROP_TIMEOUT:
- g_value_set_uint (value, priv->io_timeout);
- break;
- case PROP_IDLE_TIMEOUT:
- g_value_set_uint (value, priv->idle_timeout);
+ case PROP_SOCKET_PROPERTIES:
+ g_value_set_boxed (value, priv->socket_props);
break;
case PROP_STATE:
g_value_set_enum (value, priv->state);
@@ -241,13 +177,6 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
/* properties */
g_object_class_install_property (
- object_class, PROP_LOCAL_ADDRESS,
- g_param_spec_object (SOUP_CONNECTION_LOCAL_ADDRESS,
- "Local address",
- "Address of local end of socket",
- SOUP_TYPE_ADDRESS,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
object_class, PROP_REMOTE_URI,
g_param_spec_boxed (SOUP_CONNECTION_REMOTE_URI,
"Remote URI",
@@ -255,34 +184,6 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
SOUP_TYPE_URI,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
- object_class, PROP_PROXY_RESOLVER,
- g_param_spec_object (SOUP_CONNECTION_PROXY_RESOLVER,
- "Proxy resolver",
- "GProxyResolver to use",
- G_TYPE_PROXY_RESOLVER,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class, PROP_SSL,
- g_param_spec_boolean (SOUP_CONNECTION_SSL,
- "SSL",
- "Whether this is an SSL connection",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class, PROP_SSL_CREDS,
- g_param_spec_object (SOUP_CONNECTION_SSL_CREDENTIALS,
- "SSL credentials",
- "SSL credentials for this connection",
- G_TYPE_TLS_DATABASE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class, PROP_SSL_STRICT,
- g_param_spec_boolean (SOUP_CONNECTION_SSL_STRICT,
- "Strictly validate SSL certificates",
- "Whether certificate errors should be considered a connection error",
- TRUE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
object_class, PROP_SSL_FALLBACK,
g_param_spec_boolean (SOUP_CONNECTION_SSL_FALLBACK,
"SSLv3 fallback",
@@ -290,32 +191,12 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
- object_class, PROP_ASYNC_CONTEXT,
- g_param_spec_pointer (SOUP_CONNECTION_ASYNC_CONTEXT,
- "Async GMainContext",
- "GMainContext to dispatch this connection's async I/O in",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class, PROP_USE_THREAD_CONTEXT,
- g_param_spec_boolean (SOUP_CONNECTION_USE_THREAD_CONTEXT,
- "Use thread context",
- "Use g_main_context_get_thread_default",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class, PROP_TIMEOUT,
- g_param_spec_uint (SOUP_CONNECTION_TIMEOUT,
- "Timeout value",
- "Value in seconds to timeout a blocking I/O",
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (
- object_class, PROP_IDLE_TIMEOUT,
- g_param_spec_uint (SOUP_CONNECTION_IDLE_TIMEOUT,
- "Idle Timeout",
- "Connection lifetime when idle",
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ object_class, PROP_SOCKET_PROPERTIES,
+ g_param_spec_boxed (SOUP_CONNECTION_SOCKET_PROPERTIES,
+ "Socket properties",
+ "Socket properties",
+ SOUP_TYPE_SOCKET_PROPERTIES,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
object_class, PROP_STATE,
g_param_spec_enum (SOUP_CONNECTION_STATE,
@@ -351,10 +232,10 @@ start_idle_timer (SoupConnection *conn)
{
SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
- if (priv->idle_timeout > 0 && !priv->idle_timeout_src) {
+ if (priv->socket_props->idle_timeout > 0 && !priv->idle_timeout_src) {
priv->idle_timeout_src =
- soup_add_timeout (priv->async_context,
- priv->idle_timeout * 1000,
+ soup_add_timeout (priv->socket_props->async_context,
+ priv->socket_props->idle_timeout * 1000,
idle_timeout, conn);
}
}
@@ -448,8 +329,7 @@ socket_connect_finished (GTask *task, SoupSocket *sock, GError *error)
SoupConnection *conn = g_task_get_source_object (task);
SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
- if (priv->async_context && !priv->use_thread_context)
- g_main_context_pop_thread_default (priv->async_context);
+ soup_socket_properties_pop_async_context (priv->socket_props);
g_signal_handlers_disconnect_by_func (sock, G_CALLBACK (re_emit_socket_event), conn);
@@ -536,23 +416,16 @@ soup_connection_connect_async (SoupConnection *conn,
priv->remote_uri->port);
priv->socket =
soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS, remote_addr,
- SOUP_SOCKET_SSL_CREDENTIALS, priv->tlsdb,
- SOUP_SOCKET_SSL_STRICT, priv->ssl_strict,
SOUP_SOCKET_SSL_FALLBACK, priv->ssl_fallback,
- SOUP_SOCKET_ASYNC_CONTEXT, priv->async_context,
- SOUP_SOCKET_USE_THREAD_CONTEXT, priv->use_thread_context,
- SOUP_SOCKET_PROXY_RESOLVER, priv->proxy_resolver,
- SOUP_SOCKET_TIMEOUT, priv->io_timeout,
+ SOUP_SOCKET_SOCKET_PROPERTIES, priv->socket_props,
SOUP_SOCKET_CLEAN_DISPOSE, TRUE,
- SOUP_SOCKET_LOCAL_ADDRESS, priv->local_addr,
NULL);
g_object_unref (remote_addr);
g_signal_connect (priv->socket, "event",
G_CALLBACK (re_emit_socket_event), conn);
- if (priv->async_context && !priv->use_thread_context)
- g_main_context_push_thread_default (priv->async_context);
+ soup_socket_properties_push_async_context (priv->socket_props);
task = g_task_new (conn, cancellable, callback, user_data);
soup_socket_connect_async_internal (priv->socket, cancellable,
@@ -586,14 +459,10 @@ soup_connection_connect_sync (SoupConnection *conn,
remote_addr = soup_address_new (priv->remote_uri->host, priv->remote_uri->port);
priv->socket =
soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS, remote_addr,
- SOUP_SOCKET_PROXY_RESOLVER, priv->proxy_resolver,
- SOUP_SOCKET_SSL_CREDENTIALS, priv->tlsdb,
- SOUP_SOCKET_SSL_STRICT, priv->ssl_strict,
SOUP_SOCKET_SSL_FALLBACK, priv->ssl_fallback,
+ SOUP_SOCKET_SOCKET_PROPERTIES, priv->socket_props,
SOUP_SOCKET_FLAG_NONBLOCKING, FALSE,
- SOUP_SOCKET_TIMEOUT, priv->io_timeout,
SOUP_SOCKET_CLEAN_DISPOSE, TRUE,
- SOUP_SOCKET_LOCAL_ADDRESS, priv->local_addr,
NULL);
g_object_unref (remote_addr);
@@ -676,8 +545,7 @@ start_ssl_completed (GObject *object, GAsyncResult *result, gpointer user_data)
SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
GError *error = NULL;
- if (priv->async_context && !priv->use_thread_context)
- g_main_context_pop_thread_default (priv->async_context);
+ soup_socket_properties_pop_async_context (priv->socket_props);
if (soup_socket_handshake_finish (priv->socket, result, &error)) {
soup_connection_event (conn, G_SOCKET_CLIENT_TLS_HANDSHAKED, NULL);
@@ -702,8 +570,7 @@ soup_connection_start_ssl_async (SoupConnection *conn,
soup_connection_event (conn, G_SOCKET_CLIENT_TLS_HANDSHAKING, NULL);
- if (priv->async_context && !priv->use_thread_context)
- g_main_context_push_thread_default (priv->async_context);
+ soup_socket_properties_push_async_context (priv->socket_props);
task = g_task_new (conn, cancellable, callback, user_data);
soup_socket_handshake_async (priv->socket, priv->remote_uri->host,
diff --git a/libsoup/soup-connection.h b/libsoup/soup-connection.h
index b70a8a3..8df6112 100644
--- a/libsoup/soup-connection.h
+++ b/libsoup/soup-connection.h
@@ -35,19 +35,10 @@ typedef struct {
GType soup_connection_get_type (void);
-#define SOUP_CONNECTION_LOCAL_ADDRESS "local-address"
-#define SOUP_CONNECTION_REMOTE_URI "remote-uri"
-#define SOUP_CONNECTION_PROXY_RESOLVER "proxy-resolver"
-#define SOUP_CONNECTION_SSL "ssl"
-#define SOUP_CONNECTION_SSL_CREDENTIALS "ssl-creds"
-#define SOUP_CONNECTION_SSL_STRICT "ssl-strict"
-#define SOUP_CONNECTION_SSL_FALLBACK "ssl-fallback"
-#define SOUP_CONNECTION_ASYNC_CONTEXT "async-context"
-#define SOUP_CONNECTION_USE_THREAD_CONTEXT "use-thread-context"
-#define SOUP_CONNECTION_TIMEOUT "timeout"
-#define SOUP_CONNECTION_IDLE_TIMEOUT "idle-timeout"
-#define SOUP_CONNECTION_STATE "state"
-#define SOUP_CONNECTION_MESSAGE "message"
+#define SOUP_CONNECTION_REMOTE_URI "remote-uri"
+#define SOUP_CONNECTION_SSL_FALLBACK "ssl-fallback"
+#define SOUP_CONNECTION_SOCKET_PROPERTIES "socket-properties"
+#define SOUP_CONNECTION_STATE "state"
void soup_connection_connect_async (SoupConnection *conn,
GCancellable *cancellable,
diff --git a/libsoup/soup-misc-private.h b/libsoup/soup-misc-private.h
index ee5c24c..01253c7 100644
--- a/libsoup/soup-misc-private.h
+++ b/libsoup/soup-misc-private.h
@@ -45,7 +45,7 @@ GIOStream *soup_socket_get_connection (SoupSocket *sock);
GIOStream *soup_socket_get_iostream (SoupSocket *sock);
#define SOUP_SOCKET_CLEAN_DISPOSE "clean-dispose"
-#define SOUP_SOCKET_PROXY_RESOLVER "proxy-resolver"
+#define SOUP_SOCKET_SOCKET_PROPERTIES "socket-properties"
SoupURI *soup_socket_get_http_proxy_uri (SoupSocket *sock);
/* At some point it might be possible to mark additional methods
diff --git a/libsoup/soup-session-host.c b/libsoup/soup-session-host.c
index 85af3fa..ba3e7f6 100644
--- a/libsoup/soup-session-host.c
+++ b/libsoup/soup-session-host.c
@@ -13,6 +13,8 @@
#include "soup.h"
#include "soup-connection.h"
#include "soup-misc-private.h"
+#include "soup-session-private.h"
+#include "soup-socket-properties.h"
G_DEFINE_TYPE (SoupSessionHost, soup_session_host, G_TYPE_OBJECT)
@@ -41,7 +43,6 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
#define HOST_KEEP_ALIVE 5 * 60 * 1000 /* 5 min in msecs */
-#define SOUP_IS_PLAIN_SESSION(o) (G_TYPE_FROM_INSTANCE (o) == SOUP_TYPE_SESSION)
static void
soup_session_host_init (SoupSessionHost *host)
@@ -155,12 +156,7 @@ soup_session_host_get_connection (SoupSessionHost *host,
SoupConnection *conn;
GSList *conns;
int num_pending = 0;
- GProxyResolver *proxy_resolver;
- GTlsDatabase *tlsdb;
- SoupAddress *local_addr;
- GMainContext *async_context;
- gboolean ssl_strict, use_thread_context;
- guint io_timeout, idle_timeout;
+ SoupSocketProperties *socket_props;
for (conns = priv->connections; conns; conns = conns->next) {
conn = conns->data;
@@ -190,35 +186,14 @@ soup_session_host_get_connection (SoupSessionHost *host,
}
g_object_get (G_OBJECT (priv->session),
- SOUP_SESSION_PROXY_RESOLVER, &proxy_resolver,
- SOUP_SESSION_TLS_DATABASE, &tlsdb,
- SOUP_SESSION_SSL_STRICT, &ssl_strict,
- SOUP_SESSION_ASYNC_CONTEXT, &async_context,
- SOUP_SESSION_USE_THREAD_CONTEXT, &use_thread_context,
- SOUP_SESSION_TIMEOUT, &io_timeout,
- SOUP_SESSION_IDLE_TIMEOUT, &idle_timeout,
- SOUP_SESSION_LOCAL_ADDRESS, &local_addr,
+ SOUP_SESSION_SOCKET_PROPERTIES, &socket_props,
NULL);
-
conn = g_object_new (SOUP_TYPE_CONNECTION,
SOUP_CONNECTION_REMOTE_URI, priv->uri,
- SOUP_CONNECTION_PROXY_RESOLVER, proxy_resolver,
- SOUP_CONNECTION_SSL, priv->uri->scheme == SOUP_URI_SCHEME_HTTPS,
- SOUP_CONNECTION_SSL_CREDENTIALS, tlsdb,
- SOUP_CONNECTION_SSL_STRICT, ssl_strict && (tlsdb != NULL ||
SOUP_IS_PLAIN_SESSION (priv->session)),
SOUP_CONNECTION_SSL_FALLBACK, priv->ssl_fallback,
- SOUP_CONNECTION_ASYNC_CONTEXT, async_context,
- SOUP_CONNECTION_USE_THREAD_CONTEXT, use_thread_context,
- SOUP_CONNECTION_TIMEOUT, io_timeout,
- SOUP_CONNECTION_IDLE_TIMEOUT, idle_timeout,
- SOUP_CONNECTION_LOCAL_ADDRESS, local_addr,
+ SOUP_CONNECTION_SOCKET_PROPERTIES, socket_props,
NULL);
-
-
- g_clear_object (&proxy_resolver);
- g_clear_object (&tlsdb);
- g_clear_object (&local_addr);
- g_clear_pointer (&async_context, g_main_context_unref);
+ soup_socket_properties_unref (socket_props);
priv->num_conns++;
priv->connections = g_slist_prepend (priv->connections, conn);
diff --git a/libsoup/soup-session-private.h b/libsoup/soup-session-private.h
index dc4d300..b769e9d 100644
--- a/libsoup/soup-session-private.h
+++ b/libsoup/soup-session-private.h
@@ -12,6 +12,8 @@
G_BEGIN_DECLS
+#define SOUP_SESSION_SOCKET_PROPERTIES "socket-properties"
+
/* "protected" methods for subclasses */
SoupMessageQueue *soup_session_get_queue (SoupSession *session);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index d80086c..03af7cd 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -22,6 +22,7 @@
#include "soup-proxy-resolver-wrapper.h"
#include "soup-session-host.h"
#include "soup-session-private.h"
+#include "soup-socket-properties.h"
/**
* SECTION:soup-session
@@ -160,6 +161,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
+ PROP_SOCKET_PROPERTIES,
PROP_PROXY_URI,
PROP_PROXY_RESOLVER,
PROP_MAX_CONNS,
@@ -738,8 +740,21 @@ soup_session_get_property (GObject *object, guint prop_id,
SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
SoupSessionFeature *feature;
GTlsDatabase *tlsdb;
+ SoupSocketProperties *props;
switch (prop_id) {
+ case PROP_SOCKET_PROPERTIES:
+ tlsdb = get_tls_database (session);
+ props = soup_socket_properties_new (priv->async_context,
+ priv->use_thread_context,
+ get_proxy_resolver (session),
+ priv->local_addr,
+ tlsdb,
+ priv->ssl_strict && (tlsdb != NULL ||
SOUP_IS_PLAIN_SESSION (priv->session)),
+ priv->io_timeout,
+ priv->idle_timeout);
+ g_value_take_boxed (value, props);
+ break;
case PROP_LOCAL_ADDRESS:
g_value_set_object (value, priv->local_addr);
break;
@@ -2977,6 +2992,13 @@ soup_session_class_init (SoupSessionClass *session_class)
/* properties */
+ g_object_class_install_property (
+ object_class, PROP_SOCKET_PROPERTIES,
+ g_param_spec_boxed (SOUP_SESSION_SOCKET_PROPERTIES,
+ "Socket properties",
+ "Socket properties",
+ SOUP_TYPE_SOCKET_PROPERTIES,
+ G_PARAM_READABLE));
/**
* SoupSession:proxy-uri:
*
diff --git a/libsoup/soup-socket-properties.c b/libsoup/soup-socket-properties.c
new file mode 100644
index 0000000..f99ff3b
--- /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-properties.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)
diff --git a/libsoup/soup-socket-properties.h b/libsoup/soup-socket-properties.h
new file mode 100644
index 0000000..dd87ec6
--- /dev/null
+++ b/libsoup/soup-socket-properties.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright 2013 Red Hat, Inc.
+ */
+
+#ifndef SOUP_SOCKET_PROPERTIES_H
+#define SOUP_SOCKET_PROPERTIES_H 1
+
+#include "soup-types.h"
+
+G_BEGIN_DECLS
+
+typedef struct {
+ GMainContext *async_context;
+ gboolean use_thread_context;
+
+ GProxyResolver *proxy_resolver;
+ SoupAddress *local_addr;
+
+ GTlsDatabase *tlsdb;
+ gboolean ssl_strict;
+
+ guint io_timeout;
+ guint idle_timeout;
+
+ /*< private >*/
+ guint ref_count;
+} SoupSocketProperties;
+
+GType soup_socket_properties_get_type (void);
+#define SOUP_TYPE_SOCKET_PROPERTIES (soup_socket_properties_get_type ())
+
+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 *soup_socket_properties_ref (SoupSocketProperties *props);
+void soup_socket_properties_unref (SoupSocketProperties *props);
+
+void soup_socket_properties_push_async_context (SoupSocketProperties *props);
+void soup_socket_properties_pop_async_context (SoupSocketProperties *props);
+
+G_END_DECLS
+
+#endif /* SOUP_SOCKET_PROPERTIES_H */
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index 0a9ed9a..fcb4fe2 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -16,8 +16,9 @@
#include "soup-socket.h"
#include "soup.h"
#include "soup-filter-input-stream.h"
-#include "soup-socket-io-stream.h"
#include "soup-misc-private.h"
+#include "soup-socket-io-stream.h"
+#include "soup-socket-properties.h"
/**
* SECTION:soup-socket
@@ -59,7 +60,7 @@ enum {
PROP_CLEAN_DISPOSE,
PROP_TLS_CERTIFICATE,
PROP_TLS_ERRORS,
- PROP_PROXY_RESOLVER,
+ PROP_SOCKET_PROPERTIES,
LAST_PROP
};
@@ -149,6 +150,7 @@ soup_socket_finalize (GObject *object)
g_clear_object (&priv->remote_addr);
g_clear_object (&priv->proxy_resolver);
+ g_clear_object (&priv->ssl_creds);
if (priv->watch_src) {
if (priv->clean_dispose && !priv->is_server)
@@ -185,19 +187,22 @@ soup_socket_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec)
{
SoupSocketPrivate *priv = SOUP_SOCKET_GET_PRIVATE (object);
+ SoupSocketProperties *props;
switch (prop_id) {
case PROP_LOCAL_ADDRESS:
- priv->local_addr = (SoupAddress *)g_value_dup_object (value);
+ priv->local_addr = g_value_dup_object (value);
break;
case PROP_REMOTE_ADDRESS:
- priv->remote_addr = (SoupAddress *)g_value_dup_object (value);
+ priv->remote_addr = g_value_dup_object (value);
break;
case PROP_NON_BLOCKING:
priv->non_blocking = g_value_get_boolean (value);
break;
case PROP_SSL_CREDENTIALS:
priv->ssl_creds = g_value_get_pointer (value);
+ if (priv->ssl_creds)
+ g_object_ref (priv->ssl_creds);
break;
case PROP_SSL_STRICT:
priv->ssl_strict = g_value_get_boolean (value);
@@ -218,8 +223,30 @@ soup_socket_set_property (GObject *object, guint prop_id,
if (priv->conn)
g_socket_set_timeout (priv->gsock, priv->timeout);
break;
- case PROP_PROXY_RESOLVER:
- priv->proxy_resolver = g_value_dup_object (value);
+ case PROP_SOCKET_PROPERTIES:
+ props = g_value_get_boxed (value);
+ if (props) {
+ g_clear_pointer (&priv->async_context, g_main_context_unref);
+ if (props->async_context)
+ priv->async_context = g_main_context_ref (props->async_context);
+ priv->use_thread_context = props->use_thread_context;
+
+ g_clear_object (&priv->proxy_resolver);
+ if (props->proxy_resolver)
+ priv->proxy_resolver = g_object_ref (props->proxy_resolver);
+ g_clear_object (&priv->local_addr);
+ if (props->local_addr)
+ priv->local_addr = g_object_ref (props->local_addr);
+
+ g_clear_object (&priv->ssl_creds);
+ if (props->tlsdb)
+ priv->ssl_creds = g_object_ref (props->tlsdb);
+ priv->ssl_strict = props->ssl_strict;
+
+ priv->timeout = props->io_timeout;
+ if (priv->conn)
+ g_socket_set_timeout (priv->gsock, priv->timeout);
+ }
break;
case PROP_CLEAN_DISPOSE:
priv->clean_dispose = g_value_get_boolean (value);
@@ -279,9 +306,6 @@ soup_socket_get_property (GObject *object, guint prop_id,
case PROP_TLS_ERRORS:
g_value_set_flags (value, priv->tls_errors);
break;
- case PROP_PROXY_RESOLVER:
- g_value_set_object (value, priv->proxy_resolver);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -617,12 +641,12 @@ soup_socket_class_init (SoupSocketClass *socket_class)
G_PARAM_READABLE));
g_object_class_install_property (
- object_class, PROP_PROXY_RESOLVER,
- g_param_spec_object (SOUP_SOCKET_PROXY_RESOLVER,
- "Proxy resolver",
- "GProxyResolver to use",
- G_TYPE_PROXY_RESOLVER,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ object_class, PROP_SOCKET_PROPERTIES,
+ g_param_spec_boxed (SOUP_SOCKET_SOCKET_PROPERTIES,
+ "Socket properties",
+ "Socket properties",
+ SOUP_TYPE_SOCKET_PROPERTIES,
+ G_PARAM_WRITABLE));
}
@@ -994,7 +1018,7 @@ listen_watch (GObject *pollable, gpointer data)
new_priv->is_server = TRUE;
new_priv->ssl = priv->ssl;
if (priv->ssl_creds)
- new_priv->ssl_creds = priv->ssl_creds;
+ new_priv->ssl_creds = g_object_ref (priv->ssl_creds);
finish_socket_setup (new_priv);
if (new_priv->ssl_creds) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]