QAbstractSocket: fix setReadBufferSize from readyRead slot.
In a slot connected to readyRead, if the app detects that the buffer size is too small and increases it, it expects that readyRead() will be emitted again. setReadBufferSize() doesn't re-enable the socket notifier when calling from within readyRead, and readyRead itself was missing the code to do it. Change-Id: Ia00a3066ad3ba09d5cfae0716adc5691ae96c3fa Done-with: Thiago Reviewed-by: Peter Hartmann <phartmann@blackberry.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8fb497d1f4
commit
13c246ee11
@ -736,8 +736,8 @@ bool QAbstractSocketPrivate::canReadNotification()
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!hasData && socketEngine)
|
||||
socketEngine->setReadNotificationEnabled(true);
|
||||
if (isBuffered && socketEngine)
|
||||
socketEngine->setReadNotificationEnabled(readBufferMaxSize == 0 || readBufferMaxSize > q->bytesAvailable());
|
||||
|
||||
// reset the read socket notifier state if we reentered inside the
|
||||
// readyRead() connected slot.
|
||||
|
@ -189,6 +189,7 @@ private slots:
|
||||
void connectToMultiIP();
|
||||
void moveToThread0();
|
||||
void increaseReadBufferSize();
|
||||
void increaseReadBufferSizeFromSlot();
|
||||
void taskQtBug5799ConnectionErrorWaitForConnected();
|
||||
void taskQtBug5799ConnectionErrorEventLoop();
|
||||
void taskQtBug7054TimeoutErrorResetting();
|
||||
@ -225,6 +226,7 @@ protected slots:
|
||||
#endif
|
||||
void earlySocketBytesSent(qint64 bytes);
|
||||
void earlySocketReadyRead();
|
||||
void slotIncreaseReadBufferSizeReadyRead();
|
||||
|
||||
private:
|
||||
QByteArray expectedReplyIMAP();
|
||||
@ -2459,6 +2461,57 @@ void tst_QTcpSocket::increaseReadBufferSize()
|
||||
delete active;
|
||||
}
|
||||
|
||||
void tst_QTcpSocket::increaseReadBufferSizeFromSlot() // like KIO's socketconnectionbackend
|
||||
{
|
||||
QFETCH_GLOBAL(bool, setProxy);
|
||||
if (setProxy)
|
||||
return; //proxy not useful for localhost test case
|
||||
QTcpServer server;
|
||||
QTcpSocket *active = newSocket();
|
||||
connect(active, SIGNAL(readyRead()), SLOT(slotIncreaseReadBufferSizeReadyRead()));
|
||||
|
||||
// connect two sockets to each other:
|
||||
QVERIFY(server.listen(QHostAddress::LocalHost));
|
||||
active->connectToHost("127.0.0.1", server.serverPort());
|
||||
QVERIFY(active->waitForConnected(5000));
|
||||
QVERIFY(server.waitForNewConnection(5000));
|
||||
|
||||
QTcpSocket *passive = server.nextPendingConnection();
|
||||
QVERIFY(passive);
|
||||
|
||||
// now write 512 bytes of data on one end
|
||||
QByteArray data(512, 'a');
|
||||
passive->write(data);
|
||||
QVERIFY2(passive->waitForBytesWritten(5000), "Network timeout");
|
||||
|
||||
// set the read buffer size to less than what was written,
|
||||
// and increase it from the slot, first to 384 then to 1024.
|
||||
active->setReadBufferSize(256);
|
||||
enterLoop(10);
|
||||
QVERIFY2(!timeout(), "Network timeout");
|
||||
QCOMPARE(active->bytesAvailable(), qint64(data.size()));
|
||||
|
||||
// drain it and compare
|
||||
QCOMPARE(active->readAll(), data);
|
||||
|
||||
delete active;
|
||||
}
|
||||
|
||||
void tst_QTcpSocket::slotIncreaseReadBufferSizeReadyRead()
|
||||
{
|
||||
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
|
||||
const int currentBufferSize = socket->readBufferSize();
|
||||
QCOMPARE(currentBufferSize, socket->bytesAvailable());
|
||||
if (currentBufferSize == 256)
|
||||
socket->setReadBufferSize(384);
|
||||
else if (currentBufferSize == 384)
|
||||
socket->setReadBufferSize(512);
|
||||
else if (currentBufferSize == 512)
|
||||
exitLoopSlot();
|
||||
else // should not happen
|
||||
qFatal("buffer size was %d", currentBufferSize);
|
||||
}
|
||||
|
||||
void tst_QTcpSocket::taskQtBug5799ConnectionErrorWaitForConnected()
|
||||
{
|
||||
QFETCH_GLOBAL(bool, setProxy);
|
||||
|
Loading…
Reference in New Issue
Block a user