[libsoup] Add a (temporary?) fix for async authentication via SoupRequest
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] Add a (temporary?) fix for async authentication via SoupRequest
- Date: Tue, 8 May 2012 16:55:45 +0000 (UTC)
commit 88632261d3610daed00d1db46a6dc909d39e889e
Author: Dan Winship <danw gnome org>
Date: Tue May 8 12:53:21 2012 -0400
Add a (temporary?) fix for async authentication via SoupRequest
In order to do async authentication, we need to stop the processing of
the request during the soup_request_send_async() call. So re-enable
soup_session_pause_message() for that case. Possibly to be revisited.
https://bugzilla.gnome.org/show_bug.cgi?id=675306
libsoup/soup-message-io.c | 58 ++++++++++++++++++++++++++++++++++++--------
libsoup/soup-session.c | 2 -
2 files changed, 47 insertions(+), 13 deletions(-)
---
diff --git a/libsoup/soup-message-io.c b/libsoup/soup-message-io.c
index b4456d6..145d809 100644
--- a/libsoup/soup-message-io.c
+++ b/libsoup/soup-message-io.c
@@ -690,20 +690,32 @@ io_read (SoupMessage *msg, GCancellable *cancellable, GError **error)
typedef struct {
GSource source;
SoupMessage *msg;
+ gboolean paused;
} SoupMessageSource;
static gboolean
-message_source_prepare (GSource *source,
- gint *timeout)
+message_source_check (GSource *source)
{
- *timeout = -1;
- return FALSE;
+ SoupMessageSource *message_source = (SoupMessageSource *)source;
+
+ if (message_source->paused) {
+ SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (message_source->msg);
+ SoupMessageIOData *io = priv->io_data;
+
+ if (!io || io->paused)
+ return FALSE;
+ else
+ return TRUE;
+ } else
+ return FALSE;
}
static gboolean
-message_source_check (GSource *source)
+message_source_prepare (GSource *source,
+ gint *timeout)
{
- return FALSE;
+ *timeout = -1;
+ return message_source_check (source);
}
static gboolean
@@ -767,7 +779,11 @@ soup_message_io_get_source (SoupMessage *msg, GCancellable *cancellable,
GSource *base_source, *source;
SoupMessageSource *message_source;
- if (io && SOUP_MESSAGE_IO_STATE_POLLABLE (io->read_state)) {
+ if (!io) {
+ base_source = g_timeout_source_new (0);
+ } else if (io->paused) {
+ base_source = NULL;
+ } else if (SOUP_MESSAGE_IO_STATE_POLLABLE (io->read_state)) {
GPollableInputStream *istream;
if (io->body_istream)
@@ -775,7 +791,7 @@ soup_message_io_get_source (SoupMessage *msg, GCancellable *cancellable,
else
istream = G_POLLABLE_INPUT_STREAM (io->istream);
base_source = g_pollable_input_stream_create_source (istream, cancellable);
- } else if (io && SOUP_MESSAGE_IO_STATE_POLLABLE (io->write_state)) {
+ } else if (SOUP_MESSAGE_IO_STATE_POLLABLE (io->write_state)) {
GPollableOutputStream *ostream;
if (io->body_ostream)
@@ -786,15 +802,18 @@ soup_message_io_get_source (SoupMessage *msg, GCancellable *cancellable,
} else
base_source = g_timeout_source_new (0);
- g_source_set_dummy_callback (base_source);
source = g_source_new (&message_source_funcs,
sizeof (SoupMessageSource));
g_source_set_name (source, "SoupMessageSource");
message_source = (SoupMessageSource *)source;
message_source->msg = g_object_ref (msg);
+ message_source->paused = io && io->paused;
- g_source_add_child_source (source, base_source);
- g_source_unref (base_source);
+ if (base_source) {
+ g_source_set_dummy_callback (base_source);
+ g_source_add_child_source (source, base_source);
+ g_source_unref (base_source);
+ }
g_source_set_callback (source, (GSourceFunc) callback, user_data, NULL);
return source;
}
@@ -848,6 +867,14 @@ io_run_until (SoupMessage *msg,
done = (io->read_state >= read_state &&
io->write_state >= write_state);
+ if (io->paused && !done) {
+ g_set_error_literal (error, G_IO_ERROR,
+ G_IO_ERROR_WOULD_BLOCK,
+ _("Operation would block"));
+ g_object_unref (msg);
+ return FALSE;
+ }
+
g_object_unref (msg);
return done;
}
@@ -1059,6 +1086,9 @@ soup_message_io_pause (SoupMessage *msg)
g_return_if_fail (io != NULL);
+ if (io->item && io->item->new_api)
+ g_return_if_fail (io->read_state < SOUP_MESSAGE_IO_STATE_BODY);
+
if (io->io_source) {
g_source_destroy (io->io_source);
g_source_unref (io->io_source);
@@ -1098,6 +1128,12 @@ soup_message_io_unpause (SoupMessage *msg)
g_return_if_fail (io != NULL);
+ if (io->item && io->item->new_api) {
+ g_return_if_fail (io->read_state < SOUP_MESSAGE_IO_STATE_BODY);
+ io->paused = FALSE;
+ return;
+ }
+
if (!io->blocking) {
if (!io->unpause_source) {
io->unpause_source = soup_add_completion (
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index be630a8..fc8d345 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -2228,7 +2228,6 @@ soup_session_pause_message (SoupSession *session,
priv = SOUP_SESSION_GET_PRIVATE (session);
item = soup_message_queue_lookup (priv->queue, msg);
g_return_if_fail (item != NULL);
- g_return_if_fail (!item->new_api);
item->paused = TRUE;
if (item->state == SOUP_MESSAGE_RUNNING)
@@ -2261,7 +2260,6 @@ soup_session_unpause_message (SoupSession *session,
priv = SOUP_SESSION_GET_PRIVATE (session);
item = soup_message_queue_lookup (priv->queue, msg);
g_return_if_fail (item != NULL);
- g_return_if_fail (!item->new_api);
item->paused = FALSE;
if (item->state == SOUP_MESSAGE_RUNNING)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]