summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-05-24 13:05:48 (GMT)
committerShane Kearns <shane.kearns@accenture.com>2011-05-24 13:36:18 (GMT)
commitc4727a85eed57a4db698326a1bed4aa75b6e5284 (patch)
tree63c402e7bef820ba7c5c927902812277a3483d4b
parent3b6c77da8c8b2b7db4d75f122464462656ef8daf (diff)
downloadQt-c4727a85eed57a4db698326a1bed4aa75b6e5284.zip
Qt-c4727a85eed57a4db698326a1bed4aa75b6e5284.tar.gz
Qt-c4727a85eed57a4db698326a1bed4aa75b6e5284.tar.bz2
sockets: limit buffer size of the internal sockets in proxy engines
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
-rw-r--r--src/network/socket/qhttpsocketengine.cpp2
-rw-r--r--src/network/socket/qsocks5socketengine.cpp2
2 files changed, 4 insertions, 0 deletions
diff --git a/src/network/socket/qhttpsocketengine.cpp b/src/network/socket/qhttpsocketengine.cpp
index 81a2c61..b002bec 100644
--- a/src/network/socket/qhttpsocketengine.cpp
+++ b/src/network/socket/qhttpsocketengine.cpp
@@ -145,6 +145,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());
}
diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp
index 87e7700..f7acc4e 100644
--- a/src/network/socket/qsocks5socketengine.cpp
+++ b/src/network/socket/qsocks5socketengine.cpp
@@ -1119,6 +1119,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;
}