wasm: fix network reply timeout and error handling
Fixes: QTBUG-83728 Change-Id: Ib8184a497a028949eea20e9d189d79da51ccc290 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit b2e998d4678b82f823d24f3c97d78dec034f4e71) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
4c9bab54f0
commit
3d452492c6
@ -61,12 +61,16 @@ QNetworkReplyWasmImplPrivate::QNetworkReplyWasmImplPrivate()
|
|||||||
, downloadBufferCurrentSize(0)
|
, downloadBufferCurrentSize(0)
|
||||||
, totalDownloadSize(0)
|
, totalDownloadSize(0)
|
||||||
, percentFinished(0)
|
, percentFinished(0)
|
||||||
|
, m_fetch(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReplyWasmImplPrivate::~QNetworkReplyWasmImplPrivate()
|
QNetworkReplyWasmImplPrivate::~QNetworkReplyWasmImplPrivate()
|
||||||
{
|
{
|
||||||
|
if (m_fetch) {
|
||||||
emscripten_fetch_close(m_fetch);
|
emscripten_fetch_close(m_fetch);
|
||||||
|
m_fetch = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReplyWasmImpl::QNetworkReplyWasmImpl(QObject *parent)
|
QNetworkReplyWasmImpl::QNetworkReplyWasmImpl(QObject *parent)
|
||||||
@ -115,12 +119,10 @@ void QNetworkReplyWasmImpl::abort()
|
|||||||
if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
|
if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setError(QNetworkReply::OperationCanceledError, QStringLiteral("Operation canceled"));
|
|
||||||
|
|
||||||
d->doAbort();
|
|
||||||
|
|
||||||
close();
|
|
||||||
d->state = QNetworkReplyPrivate::Aborted;
|
d->state = QNetworkReplyPrivate::Aborted;
|
||||||
|
d->doAbort();
|
||||||
|
d->m_fetch = 0;
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 QNetworkReplyWasmImpl::bytesAvailable() const
|
qint64 QNetworkReplyWasmImpl::bytesAvailable() const
|
||||||
@ -265,7 +267,7 @@ void QNetworkReplyWasmImplPrivate::doSendRequest()
|
|||||||
attr.onerror = QNetworkReplyWasmImplPrivate::downloadFailed;
|
attr.onerror = QNetworkReplyWasmImplPrivate::downloadFailed;
|
||||||
attr.onprogress = QNetworkReplyWasmImplPrivate::downloadProgress;
|
attr.onprogress = QNetworkReplyWasmImplPrivate::downloadProgress;
|
||||||
attr.onreadystatechange = QNetworkReplyWasmImplPrivate::stateChange;
|
attr.onreadystatechange = QNetworkReplyWasmImplPrivate::stateChange;
|
||||||
attr.timeoutMSecs = 2 * 6000; // FIXME
|
attr.timeoutMSecs = QNetworkRequest::DefaultTransferTimeoutConstant;
|
||||||
attr.userData = reinterpret_cast<void *>(this);
|
attr.userData = reinterpret_cast<void *>(this);
|
||||||
|
|
||||||
QString dPath = QStringLiteral("/home/web_user/") + request.url().fileName();
|
QString dPath = QStringLiteral("/home/web_user/") + request.url().fileName();
|
||||||
@ -276,14 +278,13 @@ void QNetworkReplyWasmImplPrivate::doSendRequest()
|
|||||||
|
|
||||||
void QNetworkReplyWasmImplPrivate::emitReplyError(QNetworkReply::NetworkError errorCode, const QString &errorString)
|
void QNetworkReplyWasmImplPrivate::emitReplyError(QNetworkReply::NetworkError errorCode, const QString &errorString)
|
||||||
{
|
{
|
||||||
Q_UNUSED(errorCode)
|
|
||||||
Q_Q(QNetworkReplyWasmImpl);
|
Q_Q(QNetworkReplyWasmImpl);
|
||||||
|
|
||||||
q->setError(errorCode, errorString);
|
q->setError(errorCode, errorString);
|
||||||
emit q->errorOccurred(errorCode);
|
emit q->errorOccurred(errorCode);
|
||||||
|
doAbort();
|
||||||
q->setFinished(true);
|
m_fetch = 0;
|
||||||
emit q->finished();
|
q->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNetworkReplyWasmImplPrivate::emitDataReadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
void QNetworkReplyWasmImplPrivate::emitDataReadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||||
@ -486,8 +487,13 @@ void QNetworkReplyWasmImplPrivate::downloadProgress(emscripten_fetch_t *fetch)
|
|||||||
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fetch->userData);
|
reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fetch->userData);
|
||||||
Q_ASSERT(reply);
|
Q_ASSERT(reply);
|
||||||
|
|
||||||
if (fetch->status < 400)
|
if (fetch->status < 400) {
|
||||||
reply->emitDataReadProgress((fetch->dataOffset + fetch->numBytes), fetch->totalBytes);
|
uint64_t bytes = fetch->dataOffset + fetch->numBytes;
|
||||||
|
uint64_t tBytes = fetch->totalBytes; // totalBytes can be 0 if server not reporting content length
|
||||||
|
if (tBytes == 0)
|
||||||
|
tBytes = bytes;
|
||||||
|
reply->emitDataReadProgress(bytes, tBytes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QNetworkReplyWasmImplPrivate::downloadFailed(emscripten_fetch_t *fetch)
|
void QNetworkReplyWasmImplPrivate::downloadFailed(emscripten_fetch_t *fetch)
|
||||||
@ -563,6 +569,9 @@ QNetworkReply::NetworkError QNetworkReplyWasmImplPrivate::statusCodeFromHttp(int
|
|||||||
code = QNetworkReply::ServiceUnavailableError;
|
code = QNetworkReply::ServiceUnavailableError;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 65535: //emscripten reply when aborted
|
||||||
|
code = QNetworkReply::OperationCanceledError;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (httpStatusCode > 500) {
|
if (httpStatusCode > 500) {
|
||||||
// some kind of server error
|
// some kind of server error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user