Blame libsoup/soup-session-async.c

rpm-build 4f3c61
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
rpm-build 4f3c61
/*
rpm-build 4f3c61
 * soup-session-async.c
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Copyright (C) 2000-2003, Ximian, Inc.
rpm-build 4f3c61
 */
rpm-build 4f3c61
rpm-build 4f3c61
#ifdef HAVE_CONFIG_H
rpm-build 4f3c61
#include <config.h>
rpm-build 4f3c61
#endif
rpm-build 4f3c61
rpm-build 4f3c61
#include "soup-session-async.h"
rpm-build 4f3c61
#include "soup.h"
rpm-build 4f3c61
#include "soup-session-private.h"
rpm-build 4f3c61
#include "soup-message-private.h"
rpm-build 4f3c61
#include "soup-message-queue.h"
rpm-build 4f3c61
#include "soup-misc-private.h"
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * SECTION:soup-session-async
rpm-build 4f3c61
 * @short_description: SoupSession for asynchronous (main-loop-based) I/O
rpm-build 4f3c61
 * (deprecated).
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * #SoupSessionAsync is an implementation of #SoupSession that uses
rpm-build 4f3c61
 * non-blocking I/O via the glib main loop for all I/O.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Deprecated: 2.42: Use the #SoupSession class (which uses both asynchronous
rpm-build 4f3c61
 * and synchronous I/O, depending on the API used). See the
rpm-build 4f3c61
 * <link linkend="libsoup-session-porting">porting guide</link>.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
rpm-build 4f3c61
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
rpm-build 4f3c61
rpm-build 4f3c61
G_DEFINE_TYPE (SoupSessionAsync, soup_session_async, SOUP_TYPE_SESSION)
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
soup_session_async_init (SoupSessionAsync *sa)
rpm-build 4f3c61
{
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_session_async_new:
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Creates an asynchronous #SoupSession with the default options.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the new session.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Deprecated: #SoupSessionAsync is deprecated; use a plain
rpm-build 4f3c61
 * #SoupSession, created with soup_session_new(). See the 
rpm-build 4f3c61
 * linkend="libsoup-session-porting">porting guide</link>.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupSession *
rpm-build 4f3c61
soup_session_async_new (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	return g_object_new (SOUP_TYPE_SESSION_ASYNC, NULL);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
/**
rpm-build 4f3c61
 * soup_session_async_new_with_options:
rpm-build 4f3c61
 * @optname1: name of first property to set
rpm-build 4f3c61
 * @...: value of @optname1, followed by additional property/value pairs
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Creates an asynchronous #SoupSession with the specified options.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Return value: the new session.
rpm-build 4f3c61
 *
rpm-build 4f3c61
 * Deprecated: #SoupSessionAsync is deprecated; use a plain
rpm-build 4f3c61
 * #SoupSession, created with soup_session_new_with_options(). See the
rpm-build 4f3c61
 * <link linkend="libsoup-session-porting">porting guide</link>.
rpm-build 4f3c61
 **/
rpm-build 4f3c61
SoupSession *
rpm-build 4f3c61
soup_session_async_new_with_options (const char *optname1, ...)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupSession *session;
rpm-build 4f3c61
	va_list ap;
rpm-build 4f3c61
rpm-build 4f3c61
	va_start (ap, optname1);
rpm-build 4f3c61
	session = (SoupSession *)g_object_new_valist (SOUP_TYPE_SESSION_ASYNC,
rpm-build 4f3c61
						      optname1, ap);
rpm-build 4f3c61
	va_end (ap);
rpm-build 4f3c61
rpm-build 4f3c61
	return session;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static guint
rpm-build 4f3c61
soup_session_async_send_message (SoupSession *session, SoupMessage *msg)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessageQueueItem *item;
rpm-build 4f3c61
	GMainContext *async_context =
rpm-build 4f3c61
		soup_session_get_async_context (session);
rpm-build 4f3c61
rpm-build 4f3c61
	item = soup_session_append_queue_item (session, msg, TRUE, FALSE,
rpm-build 4f3c61
					       NULL, NULL);
rpm-build 4f3c61
	soup_session_kick_queue (session);
rpm-build 4f3c61
rpm-build 4f3c61
	while (item->state != SOUP_MESSAGE_FINISHED)
rpm-build 4f3c61
		g_main_context_iteration (async_context, TRUE);
rpm-build 4f3c61
rpm-build 4f3c61
	soup_message_queue_item_unref (item);
rpm-build 4f3c61
rpm-build 4f3c61
	return msg->status_code;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
soup_session_async_cancel_message (SoupSession *session, SoupMessage *msg,
rpm-build 4f3c61
				   guint status_code)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessageQueue *queue;
rpm-build 4f3c61
	SoupMessageQueueItem *item;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_SESSION_CLASS (soup_session_async_parent_class)->
rpm-build 4f3c61
		cancel_message (session, msg, status_code);
rpm-build 4f3c61
rpm-build 4f3c61
	queue = soup_session_get_queue (session);
rpm-build 4f3c61
	item = soup_message_queue_lookup (queue, msg);
rpm-build 4f3c61
	if (!item)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	/* Force it to finish immediately, so that
rpm-build 4f3c61
	 * soup_session_abort (session); g_object_unref (session);
rpm-build 4f3c61
	 * will work. (The soup_session_cancel_message() docs
rpm-build 4f3c61
	 * point out that the callback will be invoked from
rpm-build 4f3c61
	 * within the cancel call.)
rpm-build 4f3c61
	 */
rpm-build 4f3c61
	if (soup_message_io_in_progress (msg))
rpm-build 4f3c61
		soup_message_io_finished (msg);
rpm-build 4f3c61
	else if (item->state != SOUP_MESSAGE_FINISHED)
rpm-build 4f3c61
		item->state = SOUP_MESSAGE_FINISHING;
rpm-build 4f3c61
rpm-build 4f3c61
	if (item->state != SOUP_MESSAGE_FINISHED)
rpm-build 4f3c61
		soup_session_process_queue_item (session, item, NULL, FALSE);
rpm-build 4f3c61
rpm-build 4f3c61
	soup_message_queue_item_unref (item);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
soup_session_async_class_init (SoupSessionAsyncClass *soup_session_async_class)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupSessionClass *session_class = SOUP_SESSION_CLASS (soup_session_async_class);
rpm-build 4f3c61
rpm-build 4f3c61
	/* virtual method override */
rpm-build 4f3c61
	session_class->send_message = soup_session_async_send_message;
rpm-build 4f3c61
	session_class->cancel_message = soup_session_async_cancel_message;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
G_GNUC_END_IGNORE_DEPRECATIONS;