[C++] [Qt5] [Server] read json (#6343)

* [C++] [Qt5] [Server] [Bug] fixed Incomplete Read JSON

Emit signal requestReceived only after request content is entirely received.

* [C++] [Qt5] [Server] [Bug] fixed Incomplete Read JSON

Emit signal requestReceived only after request content is entirely received.
This commit is contained in:
Natan Laverde 2020-05-18 06:32:13 -03:00 committed by GitHub
parent d4b55d6767
commit f8a144bdc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -30,7 +30,16 @@ signals:
protected:
virtual void process(QHttpEngine::Socket *socket, const QString &path){
Q_UNUSED(path);
emit requestReceived(socket);
// If the slot requires all data to be received, check to see if this is
// already the case, otherwise, wait until the rest of it arrives
if (socket->bytesAvailable() >= socket->contentLength()) {
emit requestReceived(socket);
} else {
connect(socket, &Socket::readChannelFinished, [this, socket, m]() {
emit requestReceived(socket);
});
}
}
};

View File

@ -40,7 +40,16 @@ signals:
protected:
virtual void process(QHttpEngine::Socket *socket, const QString &path){
Q_UNUSED(path);
emit requestReceived(socket);
// If the slot requires all data to be received, check to see if this is
// already the case, otherwise, wait until the rest of it arrives
if (socket->bytesAvailable() >= socket->contentLength()) {
emit requestReceived(socket);
} else {
connect(socket, &Socket::readChannelFinished, [this, socket, m]() {
emit requestReceived(socket);
});
}
}
};