Merge pull request #3 from Trial97/netRefactor3
Fail NetRequest on connection close from QT
This commit is contained in:
commit
b47993b736
@ -157,7 +157,7 @@ void NetRequest::downloadError(QNetworkReply::NetworkError error)
|
|||||||
{
|
{
|
||||||
if (error == QNetworkReply::OperationCanceledError) {
|
if (error == QNetworkReply::OperationCanceledError) {
|
||||||
qCCritical(logCat) << getUid().toString() << "Aborted " << m_url.toString();
|
qCCritical(logCat) << getUid().toString() << "Aborted " << m_url.toString();
|
||||||
m_state = State::AbortedByUser;
|
m_state = State::Failed;
|
||||||
} else {
|
} else {
|
||||||
if (m_options & Option::AcceptLocalFiles) {
|
if (m_options & Option::AcceptLocalFiles) {
|
||||||
if (m_sink->hasLocalData()) {
|
if (m_sink->hasLocalData()) {
|
||||||
@ -274,6 +274,13 @@ void NetRequest::downloadFinished()
|
|||||||
if (data.size()) {
|
if (data.size()) {
|
||||||
qCDebug(logCat) << getUid().toString() << "Writing extra" << data.size() << "bytes";
|
qCDebug(logCat) << getUid().toString() << "Writing extra" << data.size() << "bytes";
|
||||||
m_state = m_sink->write(data);
|
m_state = m_sink->write(data);
|
||||||
|
if (m_state != State::Succeeded) {
|
||||||
|
qCDebug(logCat) << getUid().toString() << "Request failed to write:" << m_url.toString();
|
||||||
|
m_sink->abort();
|
||||||
|
emit failed("");
|
||||||
|
emit finished();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, finalize the whole graph
|
// otherwise, finalize the whole graph
|
||||||
@ -309,10 +316,14 @@ void NetRequest::downloadReadyRead()
|
|||||||
|
|
||||||
auto NetRequest::abort() -> bool
|
auto NetRequest::abort() -> bool
|
||||||
{
|
{
|
||||||
if (m_reply) {
|
|
||||||
m_reply->abort();
|
|
||||||
} else {
|
|
||||||
m_state = State::AbortedByUser;
|
m_state = State::AbortedByUser;
|
||||||
|
if (m_reply) {
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
|
||||||
|
disconnect(m_reply.get(), &QNetworkReply::errorOccurred, nullptr, nullptr);
|
||||||
|
#else
|
||||||
|
disconnect(m_reply.get(), QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), nullptr, nullptr);
|
||||||
|
#endif
|
||||||
|
m_reply->abort();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user