Ensure socket is not prematurely destroyed when client disconnects (fixes #15).
This commit is contained in:
@@ -345,6 +345,11 @@ Q_SIGNALS:
|
||||
*/
|
||||
void headersParsed();
|
||||
|
||||
/**
|
||||
* @brief Indicate that the client has disconnected
|
||||
*/
|
||||
void disconnected();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,6 +92,9 @@ void FilesystemHandlerPrivate::processFile(Socket *socket, const QString &absolu
|
||||
socket->close();
|
||||
});
|
||||
|
||||
// Stop the copier if the socket is disconnected
|
||||
connect(socket, &Socket::disconnected, copier, &QIODeviceCopier::stop);
|
||||
|
||||
qint64 fileSize = file->size();
|
||||
|
||||
// Checking for partial content request
|
||||
|
||||
@@ -50,9 +50,6 @@ void ServerPrivate::process(QTcpSocket *socket)
|
||||
httpSocket->writeError(Socket::InternalServerError);
|
||||
}
|
||||
});
|
||||
|
||||
// Destroy the socket once the client is disconnected
|
||||
connect(socket, &QTcpSocket::disconnected, httpSocket, &Socket::deleteLater);
|
||||
}
|
||||
|
||||
Server::Server(QObject *parent)
|
||||
|
||||
@@ -69,6 +69,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::disconnected, q, &Socket::disconnected);
|
||||
|
||||
// Process anything already received by the socket
|
||||
onReadyRead();
|
||||
|
||||
Reference in New Issue
Block a user