qnetworkaccessdebugpipebackend.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessdebugpipebackend.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtNetwork module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qnetworkaccessdebugpipebackend_p.h"-
41#include "QtCore/qdatastream.h"-
42#include <QCoreApplication>-
43#include <QStringList>-
44#include <QUrlQuery>-
45#include "private/qnoncontiguousbytedevice_p.h"-
46-
47QT_BEGIN_NAMESPACE-
48-
49#ifdef QT_BUILD_INTERNAL-
50-
51enum {-
52 ReadBufferSize = 16384,-
53 WriteBufferSize = ReadBufferSize-
54};-
55-
56QStringList QNetworkAccessDebugPipeBackendFactory::supportedSchemes() const-
57{-
58 return QStringList(QStringLiteral("debugpipe"));
never executed: return QStringList(([]() -> QString { enum { Size = sizeof(u"" "debugpipe")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "debugpipe" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));
never executed: return qstring_literal_temp;
0
59}-
60-
61QNetworkAccessBackend *-
62QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation op,-
63 const QNetworkRequest &request) const-
64{-
65 // is it an operation we know of?-
66 switch (op) {-
67 case QNetworkAccessManager::GetOperation:
executed 8 times by 1 test: case QNetworkAccessManager::GetOperation:
Executed by:
  • tst_QNetworkReply
8
68 case QNetworkAccessManager::PutOperation:
executed 46 times by 1 test: case QNetworkAccessManager::PutOperation:
Executed by:
  • tst_QNetworkReply
46
69 break;
executed 54 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
54
70-
71 default:
never executed: default:
0
72 // no, we can't handle this operation-
73 return 0;
never executed: return 0;
0
74 }-
75-
76 QUrl url = request.url();-
77 if (url.scheme() == QLatin1String("debugpipe"))
url.scheme() =...g("debugpipe")Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 47 times by 1 test
Evaluated by:
  • tst_QNetworkReply
7-47
78 return new QNetworkAccessDebugPipeBackend;
executed 7 times by 1 test: return new QNetworkAccessDebugPipeBackend;
Executed by:
  • tst_QNetworkReply
7
79 return 0;
executed 47 times by 1 test: return 0;
Executed by:
  • tst_QNetworkReply
47
80}-
81-
82QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend()-
83 : bareProtocol(false), hasUploadFinished(false), hasDownloadFinished(false),-
84 hasEverythingFinished(false), bytesDownloaded(0), bytesUploaded(0)-
85{-
86}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
87-
88QNetworkAccessDebugPipeBackend::~QNetworkAccessDebugPipeBackend()-
89{-
90 // this is signals disconnect, not network!-
91 socket.disconnect(this); // we're not interested in the signals at this point-
92}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
93-
94void QNetworkAccessDebugPipeBackend::open()-
95{-
96 socket.connectToHost(url().host(), url().port(12345));-
97 socket.setReadBufferSize(ReadBufferSize);-
98-
99 // socket ready read -> we can push from socket to downstream-
100 connect(&socket, SIGNAL(readyRead()), SLOT(socketReadyRead()));-
101 connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(socketError()));-
102 connect(&socket, SIGNAL(disconnected()), SLOT(socketDisconnected()));-
103 connect(&socket, SIGNAL(connected()), SLOT(socketConnected()));-
104 // socket bytes written -> we can push more from upstream to socket-
105 connect(&socket, SIGNAL(bytesWritten(qint64)), SLOT(socketBytesWritten(qint64)));-
106-
107 bareProtocol = QUrlQuery(url()).queryItemValue(QLatin1String("bare")) == QLatin1String("1");-
108-
109 if (operation() == QNetworkAccessManager::PutOperation) {
operation() ==...::PutOperationDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-7
110 uploadByteDevice = createUploadByteDevice();-
111 QObject::connect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(uploadReadyReadSlot()));-
112 QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection);-
113 }
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
114}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
115-
116void QNetworkAccessDebugPipeBackend::socketReadyRead()-
117{-
118 pushFromSocketToDownstream();-
119}
never executed: end of block
0
120-
121void QNetworkAccessDebugPipeBackend::downstreamReadyWrite()-
122{-
123 pushFromSocketToDownstream();-
124}
never executed: end of block
0
125-
126void QNetworkAccessDebugPipeBackend::socketBytesWritten(qint64)-
127{-
128 pushFromUpstreamToSocket();-
129}
executed 136 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
136
130-
131void QNetworkAccessDebugPipeBackend::uploadReadyReadSlot()-
132{-
133 pushFromUpstreamToSocket();-
134}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
135-
136void QNetworkAccessDebugPipeBackend::pushFromSocketToDownstream()-
137{-
138 QByteArray buffer;-
139-
140 if (socket.state() == QAbstractSocket::ConnectingState) {
socket.state()...onnectingStateDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
0-1
141 return;
never executed: return;
0
142 }-
143-
144 forever {-
145 if (hasDownloadFinished)
hasDownloadFinishedDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
0-1
146 return;
never executed: return;
0
147-
148 buffer.resize(ReadBufferSize);-
149 qint64 haveRead = socket.read(buffer.data(), ReadBufferSize);-
150-
151 if (haveRead == -1) {
haveRead == -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-1
152 hasDownloadFinished = true;-
153 // this ensures a good last downloadProgress is emitted-
154 setHeader(QNetworkRequest::ContentLengthHeader, QVariant());-
155 possiblyFinish();-
156 break;
executed 1 time by 1 test: break;
Executed by:
  • tst_QNetworkReply
1
157 } else if (haveRead == 0) {
haveRead == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
158 break;
never executed: break;
0
159 } else {-
160 // have read something-
161 buffer.resize(haveRead);-
162 bytesDownloaded += haveRead;-
163-
164 QByteDataBuffer list;-
165 list.append(buffer);-
166 buffer.clear(); // important because of implicit sharing!-
167 writeDownstreamData(list);-
168 }
never executed: end of block
0
169 }-
170}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkReply
1
171-
172void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket()-
173{-
174 // FIXME-
175 if (operation() == QNetworkAccessManager::PutOperation) {
operation() ==...::PutOperationDescription
TRUEevaluated 143 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-143
176 if (hasUploadFinished)
hasUploadFinishedDescription
TRUEnever evaluated
FALSEevaluated 143 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-143
177 return;
never executed: return;
0
178-
179 forever {-
180 if (socket.bytesToWrite() >= WriteBufferSize)
socket.bytesTo...riteBufferSizeDescription
TRUEevaluated 136 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 149 times by 1 test
Evaluated by:
  • tst_QNetworkReply
136-149
181 return;
executed 136 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
136
182-
183 qint64 haveRead;-
184 const char *readPointer = uploadByteDevice->readPointer(WriteBufferSize, haveRead);-
185 if (haveRead == -1) {
haveRead == -1Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QNetworkReply
7-142
186 // EOF-
187 hasUploadFinished = true;-
188 emitReplyUploadProgress(bytesUploaded, bytesUploaded);-
189 possiblyFinish();-
190 break;
executed 7 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
7
191 } else if (haveRead == 0 || readPointer == 0) {
haveRead == 0Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QNetworkReply
readPointer == 0Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-142
192 // nothing to read right now, we will be called again later-
193 break;
never executed: break;
0
194 } else {-
195 qint64 haveWritten;-
196 haveWritten = socket.write(readPointer, haveRead);-
197-
198 if (haveWritten < 0) {
haveWritten < 0Description
TRUEnever evaluated
FALSEevaluated 142 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-142
199 // write error!-
200 QString msg = QCoreApplication::translate("QNetworkAccessDebugPipeBackend", "Write error writing to %1: %2")-
201 .arg(url().toString(), socket.errorString());-
202 error(QNetworkReply::ProtocolFailure, msg);-
203 finished();-
204 return;
never executed: return;
0
205 } else {-
206 uploadByteDevice->advanceReadPointer(haveWritten);-
207 bytesUploaded += haveWritten;-
208 emitReplyUploadProgress(bytesUploaded, -1);-
209 }
executed 142 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
142
210-
211 //QCoreApplication::processEvents();-
212-
213 }-
214 }-
215 }
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
216}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
217-
218void QNetworkAccessDebugPipeBackend::possiblyFinish()-
219{-
220 if (hasEverythingFinished)
hasEverythingFinishedDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
1-7
221 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QNetworkReply
1
222 hasEverythingFinished = true;-
223-
224 if ((operation() == QNetworkAccessManager::GetOperation) && hasDownloadFinished) {
(operation() =...:GetOperation)Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
hasDownloadFinishedDescription
TRUEnever evaluated
FALSEnever evaluated
0-7
225 socket.close();-
226 finished();-
227 } else if ((operation() == QNetworkAccessManager::PutOperation) && hasUploadFinished) {
never executed: end of block
(operation() =...:PutOperation)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
hasUploadFinishedDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-7
228 socket.close();-
229 finished();-
230 }
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
231-
232-
233}
executed 7 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
7
234-
235void QNetworkAccessDebugPipeBackend::closeDownstreamChannel()-
236{-
237 qWarning("QNetworkAccessDebugPipeBackend::closeDownstreamChannel() %d",operation());;-
238 //if (operation() == QNetworkAccessManager::GetOperation)-
239 // socket.disconnectFromHost();-
240}
never executed: end of block
0
241-
242-
243void QNetworkAccessDebugPipeBackend::socketError()-
244{-
245 qWarning("QNetworkAccessDebugPipeBackend::socketError() %d",socket.error());-
246 QNetworkReply::NetworkError code;-
247 switch (socket.error()) {-
248 case QAbstractSocket::RemoteHostClosedError:
never executed: case QAbstractSocket::RemoteHostClosedError:
0
249 return; // socketDisconnected will be called
never executed: return;
0
250-
251 case QAbstractSocket::NetworkError:
never executed: case QAbstractSocket::NetworkError:
0
252 code = QNetworkReply::UnknownNetworkError;-
253 break;
never executed: break;
0
254-
255 default:
never executed: default:
0
256 code = QNetworkReply::ProtocolFailure;-
257 break;
never executed: break;
0
258 }-
259-
260 error(code, QNetworkAccessDebugPipeBackend::tr("Socket error on %1: %2")-
261 .arg(url().toString(), socket.errorString()));-
262 finished();-
263 disconnect(&socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()));-
264-
265}
never executed: end of block
0
266-
267void QNetworkAccessDebugPipeBackend::socketDisconnected()-
268{-
269 pushFromSocketToDownstream();-
270-
271 if (socket.bytesToWrite() == 0) {
socket.bytesToWrite() == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-1
272 // normal close-
273 } else {
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkReply
1
274 // abnormal close-
275 QString msg = QNetworkAccessDebugPipeBackend::tr("Remote host closed the connection prematurely on %1")-
276 .arg(url().toString());-
277 error(QNetworkReply::RemoteHostClosedError, msg);-
278 finished();-
279 }
never executed: end of block
0
280}-
281-
282void QNetworkAccessDebugPipeBackend::socketConnected()-
283{-
284}-
285-
286-
287#endif-
288-
289QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9