[libsoup] SoupSession: Do not actually send a request if it was cancelled before.
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] SoupSession: Do not actually send a request if it was cancelled before.
- Date: Wed, 18 Jan 2012 14:37:36 +0000 (UTC)
commit 5c20e8186fa241f31e4c0d07ec94aa40337b4db3
Author: Raphael Kubo da Costa <kubo profusion mobi>
Date: Tue Jan 17 12:30:48 2012 -0200
SoupSession: Do not actually send a request if it was cancelled before.
soup_session_cancel_message() may have been called in a REQUEST_STARTED
callback, so it is safer to make sure that
soup_connection_send_request() is called only if that is not the case.
https://bugzilla.gnome.org/show_bug.cgi?id=668098
libsoup/soup-session-async.c | 1 +
libsoup/soup-session-sync.c | 2 +-
libsoup/soup-session.c | 4 +++-
tests/misc-test.c | 26 ++++++++++++++++++++++++++
4 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/libsoup/soup-session-async.c b/libsoup/soup-session-async.c
index e872102..9baa78e 100644
--- a/libsoup/soup-session-async.c
+++ b/libsoup/soup-session-async.c
@@ -285,6 +285,7 @@ tunnel_message_completed (SoupMessage *msg, gpointer user_data)
if (item->state == SOUP_MESSAGE_RESTARTING) {
soup_message_restarted (msg);
if (item->conn) {
+ item->state = SOUP_MESSAGE_RUNNING;
soup_session_send_queue_item (session, item, tunnel_message_completed);
return;
}
diff --git a/libsoup/soup-session-sync.c b/libsoup/soup-session-sync.c
index c54975c..1a919c7 100644
--- a/libsoup/soup-session-sync.c
+++ b/libsoup/soup-session-sync.c
@@ -156,8 +156,8 @@ tunnel_connect (SoupSession *session, SoupMessageQueueItem *related)
status = item->msg->status_code;
if (item->state == SOUP_MESSAGE_RESTARTING &&
soup_message_io_in_progress (item->msg)) {
- item->state = SOUP_MESSAGE_STARTING;
soup_message_restarted (item->msg);
+ item->state = SOUP_MESSAGE_RUNNING;
} else {
if (item->state == SOUP_MESSAGE_RESTARTING)
status = SOUP_STATUS_TRY_AGAIN;
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index eb5dd6e..79ed51d 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1723,7 +1723,8 @@ soup_session_send_queue_item (SoupSession *session,
g_signal_emit (session, signals[REQUEST_STARTED], 0,
item->msg, soup_connection_get_socket (item->conn));
- soup_connection_send_request (item->conn, item, completion_cb, item);
+ if (item->state == SOUP_MESSAGE_RUNNING)
+ soup_connection_send_request (item->conn, item, completion_cb, item);
}
gboolean
@@ -1844,6 +1845,7 @@ soup_session_make_connect_message (SoupSession *session,
item = soup_message_queue_lookup (priv->queue, msg);
soup_message_queue_item_set_connection (item, conn);
g_object_unref (msg);
+ item->state = SOUP_MESSAGE_RUNNING;
g_signal_emit (session, signals[TUNNELING], 0, conn);
return item;
diff --git a/tests/misc-test.c b/tests/misc-test.c
index a8ddc21..358031d 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -591,6 +591,12 @@ ea_connection_created (SoupSession *session, GObject *conn, gpointer user_data)
}
static void
+ea_request_started (SoupSession *session, SoupMessage *msg, SoupSocket *socket, gpointer user_data)
+{
+ soup_session_cancel_message (session, msg, SOUP_STATUS_CANCELLED);
+}
+
+static void
do_early_abort_test (void)
{
SoupSession *session;
@@ -633,6 +639,26 @@ do_early_abort_test (void)
g_main_context_iteration (context, FALSE);
soup_test_session_abort_unref (session);
+
+ session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+ msg = soup_message_new_from_uri ("GET", base_uri);
+
+ g_signal_connect (session, "request-started",
+ G_CALLBACK (ea_request_started), NULL);
+ soup_session_send_message (session, msg);
+ debug_printf (2, " Message 3 completed\n");
+
+ if (msg->status_code != SOUP_STATUS_CANCELLED) {
+ debug_printf (1, " Unexpected response: %d %s\n",
+ msg->status_code, msg->reason_phrase);
+ errors++;
+ }
+ g_object_unref (msg);
+
+ while (g_main_context_pending (context))
+ g_main_context_iteration (context, FALSE);
+
+ soup_test_session_abort_unref (session);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]