Ensure readChannelFinished() is only emitted once (fixes #21).
This commit is contained in:
@@ -68,7 +68,7 @@ SocketPrivate::SocketPrivate(Socket *httpSocket, QTcpSocket *tcpSocket)
|
||||
|
||||
connect(socket, &QTcpSocket::readyRead, this, &SocketPrivate::onReadyRead);
|
||||
connect(socket, &QTcpSocket::bytesWritten, this, &SocketPrivate::onBytesWritten);
|
||||
connect(socket, &QTcpSocket::readChannelFinished, q, &Socket::readChannelFinished);
|
||||
connect(socket, &QTcpSocket::readChannelFinished, this, &SocketPrivate::onReadChannelFinished);
|
||||
connect(socket, &QTcpSocket::disconnected, q, &Socket::disconnected);
|
||||
|
||||
// Process anything already received by the socket
|
||||
@@ -137,6 +137,13 @@ void SocketPrivate::onBytesWritten(qint64 bytes)
|
||||
}
|
||||
}
|
||||
|
||||
void SocketPrivate::onReadChannelFinished()
|
||||
{
|
||||
if (requestDataTotal == -1) {
|
||||
emit q->readChannelFinished();
|
||||
}
|
||||
}
|
||||
|
||||
bool SocketPrivate::readHeaders()
|
||||
{
|
||||
// Check for the double CRLF that signals the end of the headers and
|
||||
|
||||
@@ -73,6 +73,7 @@ private Q_SLOTS:
|
||||
|
||||
void onReadyRead();
|
||||
void onBytesWritten(qint64 bytes);
|
||||
void onReadChannelFinished();
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -132,9 +132,9 @@ void TestSocket::testSignals()
|
||||
|
||||
QSignalSpy headersParsedSpy(server, SIGNAL(headersParsed()));
|
||||
QSignalSpy readyReadSpy(server, SIGNAL(readyRead()));
|
||||
QSignalSpy readChannelFinishedSpy(server, SIGNAL(readChannelFinished()));
|
||||
QSignalSpy bytesWrittenSpy(server, SIGNAL(bytesWritten(qint64)));
|
||||
QSignalSpy aboutToCloseSpy(server, SIGNAL(aboutToClose()));
|
||||
QSignalSpy readChannelFinishedSpy(server, SIGNAL(readChannelFinished()));
|
||||
|
||||
client.sendHeaders(Method, Path, headers);
|
||||
|
||||
@@ -145,7 +145,6 @@ void TestSocket::testSignals()
|
||||
|
||||
QTRY_COMPARE(server->bytesAvailable(), Data.length());
|
||||
QVERIFY(readyReadSpy.count() > 0);
|
||||
QCOMPARE(readChannelFinishedSpy.count(), 1);
|
||||
|
||||
server->writeHeaders();
|
||||
server->write(Data);
|
||||
@@ -162,6 +161,8 @@ void TestSocket::testSignals()
|
||||
QTRY_COMPARE(aboutToCloseSpy.count(), 0);
|
||||
server->close();
|
||||
QTRY_COMPARE(aboutToCloseSpy.count(), 1);
|
||||
|
||||
QCOMPARE(readChannelFinishedSpy.count(), 1);
|
||||
}
|
||||
|
||||
void TestSocket::testJson()
|
||||
|
||||
Reference in New Issue
Block a user