Remove build warning
[platform/upstream/libsoup.git] / libsoup / soup-session-async.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * soup-session-async.c
4  *
5  * Copyright (C) 2000-2003, Ximian, Inc.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include <config.h>
10 #endif
11
12 #include "soup-session-async.h"
13 #include "soup.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"
18
19 /**
20  * SECTION:soup-session-async
21  * @short_description: (Deprecated) SoupSession for asynchronous
22  *   (main-loop-based) I/O.
23  *
24  * #SoupSessionAsync is an implementation of #SoupSession that uses
25  * non-blocking I/O via the glib main loop for all I/O.
26  *
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>.
31  **/
32
33 G_DEFINE_TYPE (SoupSessionAsync, soup_session_async, SOUP_TYPE_SESSION)
34
35 static void
36 soup_session_async_init (SoupSessionAsync *sa)
37 {
38 }
39
40 /**
41  * soup_session_async_new:
42  *
43  * Creates an asynchronous #SoupSession with the default options.
44  *
45  * Return value: the new session.
46  *
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>.
50  **/
51 SoupSession *
52 soup_session_async_new (void)
53 {
54         return g_object_new (SOUP_TYPE_SESSION_ASYNC, NULL);
55 }
56
57 /**
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
61  *
62  * Creates an asynchronous #SoupSession with the specified options.
63  *
64  * Return value: the new session.
65  *
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>.
69  **/
70 SoupSession *
71 soup_session_async_new_with_options (const char *optname1, ...)
72 {
73         SoupSession *session;
74         va_list ap;
75
76         va_start (ap, optname1);
77         session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION_ASYNC,
78                                                       optname1, ap);
79         va_end (ap);
80
81         return session;
82 }
83
84 static guint
85 soup_session_async_send_message (SoupSession *session, SoupMessage *msg)
86 {
87         SoupMessageQueueItem *item;
88         GMainContext *async_context =
89                 soup_session_get_async_context (session);
90
91         item = soup_session_append_queue_item (session, msg, TRUE, FALSE,
92                                                NULL, NULL);
93         soup_session_kick_queue (session);
94
95         while (item->state != SOUP_MESSAGE_FINISHED)
96                 g_main_context_iteration (async_context, TRUE);
97
98         soup_message_queue_item_unref (item);
99
100         return msg->status_code;
101 }
102
103 static void
104 soup_session_async_cancel_message (SoupSession *session, SoupMessage *msg,
105                                    guint status_code)
106 {
107         SoupMessageQueue *queue;
108         SoupMessageQueueItem *item;
109
110         SOUP_SESSION_CLASS (soup_session_async_parent_class)->
111                 cancel_message (session, msg, status_code);
112
113         queue = soup_session_get_queue (session);
114         item = soup_message_queue_lookup (queue, msg);
115         if (!item)
116                 return;
117
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.)
123          */
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;
128
129         if (item->state != SOUP_MESSAGE_FINISHED)
130                 soup_session_process_queue_item (session, item, NULL, FALSE);
131
132         soup_message_queue_item_unref (item);
133 }
134
135 static void
136 soup_session_async_class_init (SoupSessionAsyncClass *soup_session_async_class)
137 {
138         SoupSessionClass *session_class = SOUP_SESSION_CLASS (soup_session_async_class);
139
140         /* virtual method override */
141         session_class->send_message = soup_session_async_send_message;
142         session_class->cancel_message = soup_session_async_cancel_message;
143 }