1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright (C) 2000-2003, Ximian, Inc.
12 #include "soup-session-sync.h"
14 #include "soup-session-private.h"
15 #include "soup-message-private.h"
16 #include "soup-message-queue.h"
19 * SECTION:soup-session-sync
20 * @short_description: (Deprecated) SoupSession for blocking I/O in
21 * multithreaded programs.
23 * #SoupSessionSync is an implementation of #SoupSession that uses
24 * synchronous I/O, intended for use in multi-threaded programs.
26 * As of libsoup 2.42, this is deprecated in favor of the plain
27 * #SoupSession class (which uses both asynchronous and synchronous
28 * I/O, depending on the API used). See the <link
29 * linkend="libsoup-session-porting">porting guide</link>.
32 G_DEFINE_TYPE (SoupSessionSync, soup_session_sync, SOUP_TYPE_SESSION)
35 soup_session_sync_init (SoupSessionSync *ss)
40 * soup_session_sync_new:
42 * Creates an synchronous #SoupSession with the default options.
44 * Return value: the new session.
46 * Deprecated: #SoupSessionSync is deprecated; use a plain
47 * #SoupSession, created with soup_session_new(). See the <link
48 * linkend="libsoup-session-porting">porting guide</link>.
51 soup_session_sync_new (void)
53 return g_object_new (SOUP_TYPE_SESSION_SYNC, NULL);
57 * soup_session_sync_new_with_options:
58 * @optname1: name of first property to set
59 * @...: value of @optname1, followed by additional property/value pairs
61 * Creates an synchronous #SoupSession with the specified options.
63 * Return value: the new session.
65 * Deprecated: #SoupSessionSync is deprecated; use a plain
66 * #SoupSession, created with soup_session_new_with_options(). See the
67 * <link linkend="libsoup-session-porting">porting guide</link>.
70 soup_session_sync_new_with_options (const char *optname1, ...)
75 va_start (ap, optname1);
76 session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION_SYNC,
84 queue_message_callback (gpointer data)
86 SoupMessageQueueItem *item = data;
88 item->callback (item->session, item->msg, item->callback_data);
89 soup_message_queue_item_unref (item);
94 queue_message_thread (gpointer data)
96 SoupMessageQueueItem *item = data;
98 soup_session_process_queue_item (item->session, item, NULL, TRUE);
100 soup_add_completion (soup_session_get_async_context (item->session),
101 queue_message_callback, item);
103 soup_message_queue_item_unref (item);
109 soup_session_sync_queue_message (SoupSession *session, SoupMessage *msg,
110 SoupSessionCallback callback, gpointer user_data)
112 SoupMessageQueueItem *item;
115 item = soup_session_append_queue_item (session, msg, FALSE, FALSE,
116 callback, user_data);
117 thread = g_thread_new ("SoupSessionSync:queue_message",
118 queue_message_thread, item);
119 g_thread_unref (thread);
123 soup_session_sync_class_init (SoupSessionSyncClass *session_sync_class)
125 SoupSessionClass *session_class = SOUP_SESSION_CLASS (session_sync_class);
127 /* virtual method override */
128 session_class->queue_message = soup_session_sync_queue_message;