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-async.h"
14 #include "soup-session-private.h"
15 #include "soup-message-private.h"
16 #include "soup-message-queue.h"
17 #include "soup-misc-private.h"
20 * SECTION:soup-session-async
21 * @short_description: (Deprecated) SoupSession for asynchronous
22 * (main-loop-based) I/O.
24 * #SoupSessionAsync is an implementation of #SoupSession that uses
25 * non-blocking I/O via the glib main loop for all I/O.
27 * As of libsoup 2.42, this is deprecated in favor of the plain
28 * #SoupSession class (which uses both asynchronous and synchronous
29 * I/O, depending on the API used). See the <link
30 * linkend="libsoup-session-porting">porting guide</link>.
33 G_DEFINE_TYPE (SoupSessionAsync, soup_session_async, SOUP_TYPE_SESSION)
36 soup_session_async_init (SoupSessionAsync *sa)
41 * soup_session_async_new:
43 * Creates an asynchronous #SoupSession with the default options.
45 * Return value: the new session.
47 * Deprecated: #SoupSessionAsync is deprecated; use a plain
48 * #SoupSession, created with soup_session_new(). See the <link
49 * linkend="libsoup-session-porting">porting guide</link>.
52 soup_session_async_new (void)
54 return g_object_new (SOUP_TYPE_SESSION_ASYNC, NULL);
58 * soup_session_async_new_with_options:
59 * @optname1: name of first property to set
60 * @...: value of @optname1, followed by additional property/value pairs
62 * Creates an asynchronous #SoupSession with the specified options.
64 * Return value: the new session.
66 * Deprecated: #SoupSessionAsync is deprecated; use a plain
67 * #SoupSession, created with soup_session_new_with_options(). See the
68 * <link linkend="libsoup-session-porting">porting guide</link>.
71 soup_session_async_new_with_options (const char *optname1, ...)
76 va_start (ap, optname1);
77 session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION_ASYNC,
85 soup_session_async_send_message (SoupSession *session, SoupMessage *msg)
87 SoupMessageQueueItem *item;
88 GMainContext *async_context =
89 soup_session_get_async_context (session);
91 item = soup_session_append_queue_item (session, msg, TRUE, FALSE,
93 soup_session_kick_queue (session);
95 while (item->state != SOUP_MESSAGE_FINISHED)
96 g_main_context_iteration (async_context, TRUE);
98 soup_message_queue_item_unref (item);
100 return msg->status_code;
104 soup_session_async_cancel_message (SoupSession *session, SoupMessage *msg,
107 SoupMessageQueue *queue;
108 SoupMessageQueueItem *item;
110 SOUP_SESSION_CLASS (soup_session_async_parent_class)->
111 cancel_message (session, msg, status_code);
113 queue = soup_session_get_queue (session);
114 item = soup_message_queue_lookup (queue, msg);
118 /* Force it to finish immediately, so that
119 * soup_session_abort (session); g_object_unref (session);
120 * will work. (The soup_session_cancel_message() docs
121 * point out that the callback will be invoked from
122 * within the cancel call.)
124 if (soup_message_io_in_progress (msg))
125 soup_message_io_finished (msg);
126 else if (item->state != SOUP_MESSAGE_FINISHED)
127 item->state = SOUP_MESSAGE_FINISHING;
129 if (item->state != SOUP_MESSAGE_FINISHED)
130 soup_session_process_queue_item (session, item, NULL, FALSE);
132 soup_message_queue_item_unref (item);
136 soup_session_async_class_init (SoupSessionAsyncClass *soup_session_async_class)
138 SoupSessionClass *session_class = SOUP_SESSION_CLASS (soup_session_async_class);
140 /* virtual method override */
141 session_class->send_message = soup_session_async_send_message;
142 session_class->cancel_message = soup_session_async_cancel_message;