Fixes issue #12, closes socket when done

Closing the socket after calling the invokeSlot and not in QHttpServer
after process, because the invocation can be deferred if more data
needs to be read from the socket, so closing the socket after calling
invokeSlot guarantees that the socket is close when the slot finishes.
This commit is contained in:
Ilan Pegoraro
2016-11-03 09:39:29 +00:00
parent 651fb87314
commit 927d6436d1
2 changed files with 5 additions and 0 deletions

View File

@@ -85,6 +85,9 @@ void QFilesystemHandlerPrivate::processFile(QHttpSocket *socket, const QString &
QIODeviceCopier *copier = new QIODeviceCopier(file, socket);
connect(copier, &QIODeviceCopier::finished, copier, &QIODeviceCopier::deleteLater);
connect(copier, &QIODeviceCopier::finished, file, &QFile::deleteLater);
connect(copier, &QIODeviceCopier::finished, [socket]() {
socket->close();
});
qint64 fileSize = file->size();

View File

@@ -90,9 +90,11 @@ void QObjectHandler::process(QHttpSocket *socket, const QString &path)
// already the case, otherwise, wait until the rest of it arrives
if (!m.readAll || socket->bytesAvailable() >= socket->contentLength()) {
d->invokeSlot(socket, m);
socket->close();
} else {
connect(socket, &QHttpSocket::readChannelFinished, [this, socket, m]() {
d->invokeSlot(socket, m);
socket->close();
});
}
}