summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkaccessdebugpipebackend.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-06-23 17:07:37 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2020-08-27 18:58:21 +0200
commitbba0bdb35c2806bcdde8e89965e99b3d412b8d3a (patch)
tree90b695e41a6257b5c2fce295dfbcb732a1d8a896 /src/network/access/qnetworkaccessdebugpipebackend.cpp
parentf7f79483e73fed5664763a125b3d27861586b7d2 (diff)
Redo QNetworkAccessBackend and various cleanups around it
Makes the QNetworkAccessBackendFactory a real interface to be used in plugins. Requires exporting some classes but they're not made public yet. Removes unused features and functions. Some things are likely still unused due to being specific for HTTP but the HTTP network replies don't use this backend system. Changes QNetworkAccessBackend to use a more traditional read(char*, qint64) function for the "downloaded" data. And an optional readPointer if supported. So far no backends have it so it's somewhat useless, but it may be useful going forward. If not it shall be deleted Converts all current backends to the new setup Easy enough, also gets rid of some unused functions. Task-number: QTBUG-80340 Change-Id: I9339e6c6eb394c471c921f5cafd3af6175936399 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/network/access/qnetworkaccessdebugpipebackend.cpp')
-rw-r--r--src/network/access/qnetworkaccessdebugpipebackend.cpp89
1 files changed, 36 insertions, 53 deletions
diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp
index 0029df41fe..51c13b7241 100644
--- a/src/network/access/qnetworkaccessdebugpipebackend.cpp
+++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp
@@ -80,8 +80,13 @@ QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation o
}
QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend()
- : bareProtocol(false), hasUploadFinished(false), hasDownloadFinished(false),
- hasEverythingFinished(false), bytesDownloaded(0), bytesUploaded(0)
+ : QNetworkAccessBackend(QNetworkAccessBackend::TargetType::Networked),
+ bareProtocol(false),
+ hasUploadFinished(false),
+ hasDownloadFinished(false),
+ hasEverythingFinished(false),
+ bytesDownloaded(0),
+ bytesUploaded(0)
{
}
@@ -108,65 +113,46 @@ void QNetworkAccessDebugPipeBackend::open()
if (operation() == QNetworkAccessManager::PutOperation) {
createUploadByteDevice();
- QObject::connect(uploadByteDevice.data(), SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot()));
+ QObject::connect(uploadByteDevice(), SIGNAL(readyRead()), this,
+ SLOT(uploadReadyReadSlot()));
QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection);
}
}
void QNetworkAccessDebugPipeBackend::socketReadyRead()
{
- pushFromSocketToDownstream();
+ readyRead();
}
-void QNetworkAccessDebugPipeBackend::downstreamReadyWrite()
+qint64 QNetworkAccessDebugPipeBackend::read(char *data, qint64 maxlen)
{
- pushFromSocketToDownstream();
+ qint64 haveRead = socket.read(data, maxlen);
+
+ if (haveRead == -1) {
+ hasDownloadFinished = true;
+ // this ensures a good last downloadProgress is emitted
+ setHeader(QNetworkRequest::ContentLengthHeader, QVariant());
+ possiblyFinish();
+ return haveRead;
+ }
+
+ bytesDownloaded += haveRead;
+ return haveRead;
}
-void QNetworkAccessDebugPipeBackend::socketBytesWritten(qint64)
+qint64 QNetworkAccessDebugPipeBackend::bytesAvailable() const
{
- pushFromUpstreamToSocket();
+ return socket.bytesAvailable();
}
-void QNetworkAccessDebugPipeBackend::uploadReadyReadSlot()
+void QNetworkAccessDebugPipeBackend::socketBytesWritten(qint64)
{
pushFromUpstreamToSocket();
}
-void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream()
+void QNetworkAccessDebugPipeBackend::uploadReadyReadSlot()
{
- QByteArray buffer;
-
- if (socket.state() == QAbstractSocket::ConnectingState) {
- return;
- }
-
- forever {
- if (hasDownloadFinished)
- return;
-
- buffer.resize(ReadBufferSize);
- qint64 haveRead = socket.read(buffer.data(), ReadBufferSize);
-
- if (haveRead == -1) {
- hasDownloadFinished = true;
- // this ensures a good last downloadProgress is emitted
- setHeader(QNetworkRequest::ContentLengthHeader, QVariant());
- possiblyFinish();
- break;
- } else if (haveRead == 0) {
- break;
- } else {
- // have read something
- buffer.resize(haveRead);
- bytesDownloaded += haveRead;
-
- QByteDataBuffer list;
- list.append(buffer);
- buffer.clear(); // important because of implicit sharing!
- writeDownstreamData(list);
- }
- }
+ pushFromUpstreamToSocket();
}
void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
@@ -180,20 +166,20 @@ void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
if (socket.bytesToWrite() >= WriteBufferSize)
return;
- qint64 haveRead;
- const char *readPointer = uploadByteDevice->readPointer(WriteBufferSize, haveRead);
+ QByteArray data(WriteBufferSize, Qt::Uninitialized);
+ qint64 haveRead = uploadByteDevice()->peek(data.data(), data.size());
if (haveRead == -1) {
// EOF
hasUploadFinished = true;
- emitReplyUploadProgress(bytesUploaded, bytesUploaded);
possiblyFinish();
break;
- } else if (haveRead == 0 || readPointer == nullptr) {
+ } else if (haveRead == 0) {
// nothing to read right now, we will be called again later
break;
} else {
qint64 haveWritten;
- haveWritten = socket.write(readPointer, haveRead);
+ data.truncate(haveRead);
+ haveWritten = socket.write(std::move(data));
if (haveWritten < 0) {
// write error!
@@ -203,13 +189,11 @@ void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()
finished();
return;
} else {
- uploadByteDevice->advanceReadPointer(haveWritten);
+ uploadByteDevice()->skip(haveWritten);
bytesUploaded += haveWritten;
- emitReplyUploadProgress(bytesUploaded, -1);
}
//QCoreApplication::processEvents();
-
}
}
}
@@ -232,7 +216,7 @@ void QNetworkAccessDebugPipeBackend::possiblyFinish()
}
-void QNetworkAccessDebugPipeBackend::closeDownstreamChannel()
+void QNetworkAccessDebugPipeBackend::close()
{
qWarning("QNetworkAccessDebugPipeBackend::closeDownstreamChannel() %d",operation());;
//if (operation() == QNetworkAccessManager::GetOperation)
@@ -266,11 +250,10 @@ void QNetworkAccessDebugPipeBackend::socketError()
void QNetworkAccessDebugPipeBackend::socketDisconnected()
{
- pushFromSocketToDownstream();
-
if (socket.bytesToWrite() == 0) {
// normal close
} else {
+ readyRead(); // @todo this is odd
// abnormal close
QString msg = QNetworkAccessDebugPipeBackend::tr("Remote host closed the connection prematurely on %1")
.arg(url().toString());