From 211bea9838bcc2acd7f54b65468fe1be2d81b1e0 Mon Sep 17 00:00:00 2001
From: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Date: Fri, 24 Apr 2009 14:18:17 +0200
Subject: Re-send network request properly when the socket is in Closing state.

This fixes the "QAbstractSocket::connectToHost() called when already
connecting/connected to <hostname>". The issue was that we were trying
to call connect on a socket that was in a Closing state. We have to
wait for the disconnected signal before we try to connect again.

Reviewed-by: Prasanth
---
 src/network/access/qhttpnetworkconnection.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp
index 980c0e0..5940fba 100644
--- a/src/network/access/qhttpnetworkconnection.cpp
+++ b/src/network/access/qhttpnetworkconnection.cpp
@@ -265,6 +265,11 @@ bool QHttpNetworkConnectionPrivate::ensureConnection(QAbstractSocket *socket)
     if (socket->state() != QAbstractSocket::ConnectedState) {
         // connect to the host if not already connected.
         int index = indexOf(socket);
+        // resend this request after we receive the disconnected signal
+        if (socket->state() == QAbstractSocket::ClosingState) {
+            channels[index].resendCurrent = true;
+            return false;
+        }
         channels[index].state = ConnectingState;
         channels[index].pendingEncrypt = encrypt;
 
@@ -982,6 +987,9 @@ void QHttpNetworkConnectionPrivate::_q_disconnected()
         channels[i].state = ReadingState;
         if (channels[i].reply)
             receiveReply(socket, channels[i].reply);
+    } else if (channels[i].state == IdleState && channels[i].resendCurrent) {
+        // re-sending request because the socket was in ClosingState
+        QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection);
     }
     channels[i].state = IdleState;
 }
-- 
cgit v0.12