Fix handling of connections that time out while IN_USE
authorDan Winship <danw@gnome.org>
Sun, 13 Nov 2011 20:02:34 +0000 (15:02 -0500)
committerDan Winship <danw@gnome.org>
Sun, 13 Nov 2011 20:06:17 +0000 (15:06 -0500)
To avoid looping, we only resend a request on
unexpected-connection-close if it was sent on a connection that has
previously been succesfully used. But we were only setting the
"successfully" used flag after a message *completed*, so if a message
just got restarted, and the connection got closed before the second
sending, then the connection was seen as having never been used, and
so the message wouldn't get re-sent.

Fix this by marking the connection as having been used if a message it
is sending gets restarted.

https://bugzilla.gnome.org/show_bug.cgi?id=660057

libsoup/soup-connection.c

index 3e7f0ee..15260e4 100644 (file)
@@ -407,6 +407,15 @@ stop_idle_timer (SoupConnectionPrivate *priv)
 }
 
 static void
+current_item_restarted (SoupMessage *msg, gpointer user_data)
+{
+       SoupConnection *conn = user_data;
+       SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
+
+       priv->unused_timeout = 0;
+}
+
+static void
 set_current_item (SoupConnection *conn, SoupMessageQueueItem *item)
 {
        SoupConnectionPrivate *priv = SOUP_CONNECTION_GET_PRIVATE (conn);
@@ -421,6 +430,9 @@ set_current_item (SoupConnection *conn, SoupMessageQueueItem *item)
        priv->cur_item = item;
        g_object_notify (G_OBJECT (conn), "message");
 
+       g_signal_connect (item->msg, "restarted",
+                         G_CALLBACK (current_item_restarted), conn);
+
        if (priv->state == SOUP_CONNECTION_IDLE ||
            item->msg->method != SOUP_METHOD_CONNECT)
                soup_connection_set_state (conn, SOUP_CONNECTION_IN_USE);
@@ -445,6 +457,8 @@ clear_current_item (SoupConnection *conn)
                priv->cur_item = NULL;
                g_object_notify (G_OBJECT (conn), "message");
 
+               g_signal_handlers_disconnect_by_func (item->msg, G_CALLBACK (current_item_restarted), conn);
+
                if (item->msg->method == SOUP_METHOD_CONNECT &&
                    SOUP_STATUS_IS_SUCCESSFUL (item->msg->status_code)) {
                        /* We're now effectively no longer proxying */