sockets: limit buffer size of the internal sockets in proxy engines
authorShane Kearns <shane.kearns@accenture.com>
Tue, 24 May 2011 13:05:48 +0000 (14:05 +0100)
committerQt Continuous Integration System <qt-info@nokia.com>
Wed, 1 Jun 2011 11:38:06 +0000 (13:38 +0200)
The application can normally control the amount of buffering of a
socket or QNetworkReply by using the setReadBufferSize API.
This allows the application to flow control the TCP connection, and
avoids out of memory errors when the data being downloaded is received
faster than the application can process it.

However when using a proxy, the proxy socket engine has an internal
socket which is used to communicate with the proxy server. It is not
visible to the user, and does not have awareness of the buffer size of
the external socket.

To solve this, we limit the internal sockets' buffer size to 64k bytes.
Under normal operation, the data is swiftly copied to the external
socket where the buffer can grow (or not) based on the application's
set value for read buffer size.

Task-number: QT-4966
Reviewed-by: Markus Goetz
(cherry picked from commit c4727a85eed57a4db698326a1bed4aa75b6e5284)

Change-Id: I29e6628e38b79b41c4464ba8cb772a0f03717043
Reviewed-on: http://codereview.qt.nokia.com/153
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Markus Goetz
src/network/socket/qhttpsocketengine.cpp
src/network/socket/qsocks5socketengine.cpp

index 5f5db17..5c672ec 100644 (file)
@@ -149,6 +149,8 @@ bool QHttpSocketEngine::connectInternal()
     // Handshake isn't done. If unconnected, start connecting.
     if (d->state == None && d->socket->state() == QAbstractSocket::UnconnectedState) {
         setState(QAbstractSocket::ConnectingState);
+        //limit buffer in internal socket, data is buffered in the external socket under application control
+        d->socket->setReadBufferSize(65536);
         d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
     }
 
index 575c0bc..ab75798 100644 (file)
@@ -1126,6 +1126,8 @@ bool QSocks5SocketEngine::connectInternal()
     if (d->socks5State == QSocks5SocketEnginePrivate::Uninitialized
         && d->socketState != QAbstractSocket::ConnectingState) {
         setState(QAbstractSocket::ConnectingState);
+        //limit buffer in internal socket, data is buffered in the external socket under application control
+        d->data->controlSocket->setReadBufferSize(65536);
         d->data->controlSocket->connectToHost(d->proxyInfo.hostName(), d->proxyInfo.port());
         return false;
     }