Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QNetworkReplyImplPrivate Class Reference

#include <qnetworkreplyimpl_p.h>

Inheritance diagram for QNetworkReplyImplPrivate:
QNetworkReplyPrivate QIODevicePrivate QNetworkHeadersPrivate QObjectPrivate QObjectData

Public Types

enum  InternalNotifications { NotifyDownstreamReadyWrite, NotifyCloseDownstreamChannel, NotifyCopyFinished }
 
typedef QQueue< InternalNotificationsNotificationQueue
 
enum  State {
  Idle, Buffering, Working, Finished,
  Aborted, WaitingForSession, Reconnecting
}
 
- Public Types inherited from QIODevicePrivate
enum  AccessMode { Unset, Sequential, RandomAccess }
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 
- Public Types inherited from QNetworkHeadersPrivate
typedef QHash< QNetworkRequest::Attribute, QVariantAttributesMap
 
typedef QHash< QNetworkRequest::KnownHeaders, QVariantCookedHeadersMap
 
typedef QPair< QByteArray, QByteArrayRawHeaderPair
 
typedef QList< RawHeaderPairRawHeadersList
 

Public Functions

void _q_bufferOutgoingData ()
 
void _q_bufferOutgoingDataFinished ()
 
void _q_cacheDestroyed ()
 
void _q_copyReadChannelFinished ()
 
void _q_copyReadyRead ()
 
void _q_networkSessionConnected ()
 
void _q_networkSessionFailed ()
 
void _q_sourceReadChannelFinished ()
 
void _q_sourceReadyRead ()
 
void _q_startOperation ()
 
void appendDownstreamData (QByteDataBuffer &data)
 
void appendDownstreamData (QIODevice *data)
 
void appendDownstreamData (const QByteArray &data)
 
void appendDownstreamDataDownloadBuffer (qint64, qint64)
 
void appendDownstreamDataSignalEmissions ()
 
void backendNotify (InternalNotifications notification)
 
void completeCacheSave ()
 
void consume (qint64 count)
 
void createCache ()
 
void emitUploadProgress (qint64 bytesSent, qint64 bytesTotal)
 
void error (QNetworkReply::NetworkError code, const QString &errorString)
 
void finished ()
 
char * getDownloadBuffer (qint64 size)
 
void handleNotifications ()
 
void initCacheSaveDevice ()
 
bool isCachingEnabled () const
 
void metaDataChanged ()
 
bool migrateBackend ()
 
QAbstractNetworkCachenetworkCache () const
 
qint64 nextDownstreamBlockSize () const
 
void pauseNotificationHandling ()
 
 QNetworkReplyImplPrivate ()
 
void redirectionRequested (const QUrl &target)
 
void resumeNotificationHandling ()
 
void setCachingEnabled (bool enable)
 
void setDownloadBuffer (QSharedPointer< char > sp, qint64 size)
 
void setup (QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
 
void sslErrors (const QList< QSslError > &errors)
 
- Public Functions inherited from QNetworkReplyPrivate
 QNetworkReplyPrivate ()
 
- Public Functions inherited from QIODevicePrivate
bool isSequential () const
 
virtual qint64 peek (char *data, qint64 maxSize)
 
virtual QByteArray peek (qint64 maxSize)
 
virtual bool putCharHelper (char c)
 
 QIODevicePrivate ()
 
virtual ~QIODevicePrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 
- Public Functions inherited from QNetworkHeadersPrivate
RawHeadersList allRawHeaders () const
 
RawHeadersList::ConstIterator findRawHeader (const QByteArray &key) const
 
QList< QByteArrayrawHeadersKeys () const
 
void setAllRawHeaders (const RawHeadersList &list)
 Sets the internal raw headers list to match list. More...
 
void setCookedHeader (QNetworkRequest::KnownHeaders header, const QVariant &value)
 
void setRawHeader (const QByteArray &key, const QByteArray &value)
 

Public Variables

QNetworkAccessBackendbackend
 
qint64 bytesDownloaded
 
qint64 bytesUploaded
 
bool cacheEnabled
 
QIODevicecacheSaveDevice
 
QIODevicecopyDevice
 
char * downloadBuffer
 
qint64 downloadBufferCurrentSize
 
qint64 downloadBufferMaximumSize
 
QSharedPointer< char > downloadBufferPointer
 
qint64 downloadBufferReadPosition
 
QString httpReasonPhrase
 
int httpStatusCode
 
qint64 lastBytesDownloaded
 
QNetworkProxy lastProxyAuthentication
 
bool notificationHandlingPaused
 
QIODeviceoutgoingData
 
QSharedPointer< QRingBufferoutgoingDataBuffer
 
NotificationQueue pendingNotifications
 
qint64 preMigrationDownloaded
 
QList< QNetworkProxyproxyList
 
QByteDataBuffer readBuffer
 
State state
 
QUrl urlForLastAuthentication
 
- Public Variables inherited from QNetworkReplyPrivate
QNetworkReply::NetworkError errorCode
 
bool isFinished
 
QPointer< QNetworkAccessManagermanager
 
QNetworkAccessManager::Operation operation
 
qint64 readBufferMaxSize
 
QNetworkRequest request
 
QUrl url
 
- Public Variables inherited from QIODevicePrivate
AccessMode accessMode
 
bool baseReadLineDataCalled
 
QIODevicePrivateLinearBuffer buffer
 
qint64 devicePos
 
QString errorString
 
bool firstRead
 
QIODevice::OpenMode openMode
 
qint64pDevicePos
 
qint64 pos
 
qint64pPos
 
qint64 seqDumpPos
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 
- Public Variables inherited from QNetworkHeadersPrivate
AttributesMap attributes
 
CookedHeadersMap cookedHeaders
 
QWeakPointer< QObjectoriginatingObject
 
RawHeadersList rawHeaders
 

Additional Inherited Members

- Static Public Functions inherited from QNetworkReplyPrivate
static void setManager (QNetworkReply *reply, QNetworkAccessManager *manager)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 
- Static Public Functions inherited from QNetworkHeadersPrivate
static QDateTime fromHttpDate (const QByteArray &value)
 
static QByteArray toHttpDate (const QDateTime &dt)
 

Detailed Description

Definition at line 110 of file qnetworkreplyimpl_p.h.

Typedefs

◆ NotificationQueue

Definition at line 129 of file qnetworkreplyimpl_p.h.

Enumerations

◆ InternalNotifications

◆ State

Enumerator
Idle 
Buffering 
Working 
Finished 
Aborted 
WaitingForSession 
Reconnecting 

Definition at line 119 of file qnetworkreplyimpl_p.h.

119  {
120  Idle, // The reply is idle.
121  Buffering, // The reply is buffering outgoing data.
122  Working, // The reply is uploading/downloading data.
123  Finished, // The reply has finished.
124  Aborted, // The reply has been aborted.
125  WaitingForSession, // The reply is waiting for the session to open before connecting.
126  Reconnecting // The reply will reconnect to once roaming has completed.
127  };

Constructors and Destructors

◆ QNetworkReplyImplPrivate()

QNetworkReplyImplPrivate::QNetworkReplyImplPrivate ( )
inline

Definition at line 59 of file qnetworkreplyimpl.cpp.

60  : backend(0), outgoingData(0),
61  copyDevice(0),
62  cacheEnabled(false), cacheSaveDevice(0),
65  httpStatusCode(0),
66  state(Idle)
70  , downloadBuffer(0)
71 {
72 }
QNetworkAccessBackend * backend

Functions

◆ _q_bufferOutgoingData()

void QNetworkReplyImplPrivate::_q_bufferOutgoingData ( )

Definition at line 220 of file qnetworkreplyimpl.cpp.

Referenced by _q_bufferOutgoingDataFinished().

221 {
223 
224  if (!outgoingDataBuffer) {
225  // first call, create our buffer
227 
230  }
231 
232  qint64 bytesBuffered = 0;
233  qint64 bytesToBuffer = 0;
234 
235  // read data into our buffer
236  forever {
237  bytesToBuffer = outgoingData->bytesAvailable();
238  // unknown? just try 2 kB, this also ensures we always try to read the EOF
239  if (bytesToBuffer <= 0)
240  bytesToBuffer = 2*1024;
241 
242  char *dst = outgoingDataBuffer->reserve(bytesToBuffer);
243  bytesBuffered = outgoingData->read(dst, bytesToBuffer);
244 
245  if (bytesBuffered == -1) {
246  // EOF has been reached.
247  outgoingDataBuffer->chop(bytesToBuffer);
248 
250  break;
251  } else if (bytesBuffered == 0) {
252  // nothing read right now, just wait until we get called again
253  outgoingDataBuffer->chop(bytesToBuffer);
254 
255  break;
256  } else {
257  // don't break, try to read() again
258  outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered);
259  }
260  }
261 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_Q(Class)
Definition: qglobal.h:2483
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
#define SIGNAL(a)
Definition: qobjectdefs.h:227
char * reserve(int bytes)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
__int64 qint64
Definition: qglobal.h:942
QSharedPointer< QRingBuffer > outgoingDataBuffer
void chop(int bytes)
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ _q_bufferOutgoingDataFinished()

void QNetworkReplyImplPrivate::_q_bufferOutgoingDataFinished ( )

Definition at line 203 of file qnetworkreplyimpl.cpp.

Referenced by _q_bufferOutgoingData().

204 {
206 
207  // make sure this is only called once, ever.
208  //_q_bufferOutgoingData may call it or the readChannelFinished emission
209  if (state != Buffering)
210  return;
211 
212  // disconnect signals
215 
216  // finally, start the request
217  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
218 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ _q_cacheDestroyed()

void QNetworkReplyImplPrivate::_q_cacheDestroyed ( )

Definition at line 501 of file qnetworkreplyimpl.cpp.

Referenced by completeCacheSave(), initCacheSaveDevice(), and setCachingEnabled().

502 {
503  //destruction of cache invalidates cacheSaveDevice
504  cacheSaveDevice = 0;
505  cacheEnabled = false;
506 }

◆ _q_copyReadChannelFinished()

void QNetworkReplyImplPrivate::_q_copyReadChannelFinished ( )

Definition at line 198 of file qnetworkreplyimpl.cpp.

Referenced by appendDownstreamData().

199 {
201 }

◆ _q_copyReadyRead()

void QNetworkReplyImplPrivate::_q_copyReadyRead ( )

Definition at line 140 of file qnetworkreplyimpl.cpp.

Referenced by _q_copyReadChannelFinished(), appendDownstreamData(), and handleNotifications().

141 {
143  if (state != Working)
144  return;
145  if (!copyDevice || !q->isOpen())
146  return;
147 
148  // FIXME Optimize to use download buffer if it is a QBuffer.
149  // Needs to be done where sendCacheContents() (?) of HTTP is emitting
150  // metaDataChanged ?
151 
152  forever {
153  qint64 bytesToRead = nextDownstreamBlockSize();
154  if (bytesToRead == 0)
155  // we'll be called again, eventually
156  break;
157 
158  bytesToRead = qBound<qint64>(1, bytesToRead, copyDevice->bytesAvailable());
159  QByteArray byteData;
160  byteData.resize(bytesToRead);
161  qint64 bytesActuallyRead = copyDevice->read(byteData.data(), byteData.size());
162  if (bytesActuallyRead == -1) {
163  byteData.clear();
165  break;
166  }
167 
168  byteData.resize(bytesActuallyRead);
169  readBuffer.append(byteData);
170 
171  if (!copyDevice->isSequential() && copyDevice->atEnd()) {
173  bytesDownloaded += bytesActuallyRead;
174  break;
175  }
176 
177  bytesDownloaded += bytesActuallyRead;
178  }
179 
181  // we didn't read anything
182  return;
183  }
184 
188  totalSize = totalSize.toLongLong() + preMigrationDownloaded;
190  // emit readyRead before downloadProgress incase this will cause events to be
191  // processed and we get into a recursive call (as in QProgressDialog).
192  emit q->readyRead();
193  emit q->downloadProgress(bytesDownloaded,
194  totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
196 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void append(QByteDataBuffer &other)
Definition: qbytedata_p.h:77
qint64 nextDownstreamBlockSize() const
virtual bool atEnd() const
Returns true if the current read and write position is at the end of the device (i.e.
Definition: qiodevice.cpp:711
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
#define emit
Definition: qobjectdefs.h:76
__int64 qint64
Definition: qglobal.h:942
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
#define Q_INT64_C(c)
Definition: qglobal.h:940
CookedHeadersMap cookedHeaders
void resize(int size)
Sets the size of the byte array to size bytes.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
Definition: qiodevice.cpp:752
void backendNotify(InternalNotifications notification)
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ _q_networkSessionConnected()

void QNetworkReplyImplPrivate::_q_networkSessionConnected ( )

Definition at line 264 of file qnetworkreplyimpl.cpp.

265 {
267 
268  if (manager.isNull())
269  return;
270 
271  QSharedPointer<QNetworkSession> session = manager->d_func()->getNetworkSession();
272  if (!session)
273  return;
274 
275  if (session->state() != QNetworkSession::Connected)
276  return;
277 
278  #ifndef QT_NO_NETWORKPROXY
279  // Re-set proxies here as new session might have changed them
280  proxyList = manager->d_func()->queryProxy(QNetworkProxyQuery(request.url()));
281  #endif
282 
283  switch (state) {
287  // Migrate existing downloads to new network connection.
288  migrateBackend();
289  break;
291  // Start waiting requests.
292  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
293  break;
294  default:
295  ;
296  }
297 }
QPointer< QNetworkAccessManager > manager
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
QList< QNetworkProxy > proxyList
QUrl url() const
Returns the URL this network request is referring to.
#define Q_Q(Class)
Definition: qglobal.h:2483
State state() const
Returns the state of the session.
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
Definition: qnetworkproxy.h:60
QNetworkRequest request
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ _q_networkSessionFailed()

void QNetworkReplyImplPrivate::_q_networkSessionFailed ( )

Definition at line 299 of file qnetworkreplyimpl.cpp.

Referenced by _q_startOperation().

300 {
301  // Abort waiting and working replies.
302  if (state == WaitingForSession || state == Working) {
303  state = Working;
305  QCoreApplication::translate("QNetworkReply", "Network session error."));
306  finished();
307  }
308 }
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
void error(QNetworkReply::NetworkError code, const QString &errorString)

◆ _q_sourceReadChannelFinished()

void QNetworkReplyImplPrivate::_q_sourceReadChannelFinished ( )

◆ _q_sourceReadyRead()

void QNetworkReplyImplPrivate::_q_sourceReadyRead ( )

◆ _q_startOperation()

void QNetworkReplyImplPrivate::_q_startOperation ( )

Definition at line 74 of file qnetworkreplyimpl.cpp.

Referenced by setup().

75 {
76  // ensure this function is only being called once
77  if (state == Working || state == Finished) {
78  qDebug("QNetworkReplyImpl::_q_startOperation was called more than once");
79  return;
80  }
81  state = Working;
82 
83  // note: if that method is called directly, it cannot happen that the backend is 0,
84  // because we just checked via a qobject_cast that we got a http backend (see
85  // QNetworkReplyImplPrivate::setup())
86  if (!backend) {
88  QCoreApplication::translate("QNetworkReply", "Protocol \"%1\" is unknown").arg(url.scheme())); // not really true!;
89  finished();
90  return;
91  }
92 
93  if (!backend->start()) {
94 #ifndef QT_NO_BEARERMANAGEMENT
95  // backend failed to start because the session state is not Connected.
96  // QNetworkAccessManager will call _q_startOperation again for us when the session
97  // state changes.
99 
100  QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession());
101 
102  if (session) {
104 
107 
108  if (!session->isOpen())
109  session->open();
110  } else {
111  qWarning("Backend is waiting for QNetworkSession to connect, but there is none!");
112  state = Working;
114  QCoreApplication::translate("QNetworkReply", "Network session error."));
115  finished();
116  }
117 #else
118  qWarning("Backend start failed");
119  state = Working;
121  QCoreApplication::translate("QNetworkReply", "backend start error."));
122  finished();
123 #endif
124  return;
125  }
126 
127  if (backend && backend->isSynchronous()) {
128  state = Finished;
129  q_func()->setFinished(true);
130  } else {
131  if (state != Finished) {
134 
136  }
137  }
138 }
QPointer< QNetworkAccessManager > manager
#define SLOT(a)
Definition: qobjectdefs.h:226
QNetworkAccessBackend * backend
NotificationQueue pendingNotifications
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
SessionError
This enum describes the session errors that can occur.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
Q_CORE_EXPORT void qWarning(const char *,...)
QNetworkAccessManager::Operation operation
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
void error(QNetworkReply::NetworkError code, const QString &errorString)
virtual bool start()
Starts the backend.

◆ appendDownstreamData() [1/3]

void QNetworkReplyImplPrivate::appendDownstreamData ( QByteDataBuffer data)

Definition at line 584 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::writeDownstreamData().

585 {
587  if (!q->isOpen())
588  return;
589 
590  if (cacheEnabled && !cacheSaveDevice) {
592  }
593 
594  qint64 bytesWritten = 0;
595  for (int i = 0; i < data.bufferCount(); i++) {
596  QByteArray const &item = data[i];
597 
598  if (cacheSaveDevice)
599  cacheSaveDevice->write(item.constData(), item.size());
600  readBuffer.append(item);
601 
602  bytesWritten += item.size();
603  }
604  data.clear();
605 
606  bytesDownloaded += bytesWritten;
608 
610 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void append(QByteDataBuffer &other)
Definition: qbytedata_p.h:77
#define Q_Q(Class)
Definition: qglobal.h:2483
__int64 qint64
Definition: qglobal.h:942
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
qint64 bufferCount() const
Definition: qbytedata_p.h:187

◆ appendDownstreamData() [2/3]

void QNetworkReplyImplPrivate::appendDownstreamData ( QIODevice data)

Definition at line 635 of file qnetworkreplyimpl.cpp.

636 {
638  if (!q->isOpen())
639  return;
640 
641  // read until EOF from data
642  if (copyDevice) {
643  qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- "
644  "backend probly needs to be fixed");
645  return;
646  }
647 
648  copyDevice = data;
649  q->connect(copyDevice, SIGNAL(readyRead()), SLOT(_q_copyReadyRead()));
650  q->connect(copyDevice, SIGNAL(readChannelFinished()), SLOT(_q_copyReadChannelFinished()));
651 
652  // start the copy:
654 }
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static const char * data(const QByteArray &arr)
Q_CORE_EXPORT void qCritical(const char *,...)

◆ appendDownstreamData() [3/3]

void QNetworkReplyImplPrivate::appendDownstreamData ( const QByteArray data)

Definition at line 656 of file qnetworkreplyimpl.cpp.

657 {
658  Q_UNUSED(data)
659  // TODO implement
660 
661  // TODO call
662 
663  qFatal("QNetworkReplyImplPrivate::appendDownstreamData not implemented");
664 }
Q_CORE_EXPORT void qFatal(const char *,...)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ appendDownstreamDataDownloadBuffer()

void QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer ( qint64  bytesReceived,
qint64  bytesTotal 
)

Definition at line 704 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::writeDownstreamDataDownloadBuffer().

705 {
707  if (!q->isOpen())
708  return;
709 
712 
713  if (cacheSaveDevice && bytesReceived == bytesTotal) {
714 // if (lastBytesDownloaded == -1)
715 // lastBytesDownloaded = 0;
716 // cacheSaveDevice->write(downloadBuffer + lastBytesDownloaded, bytesReceived - lastBytesDownloaded);
717 
718  // Write everything in one go if we use a download buffer. might be more performant.
719  cacheSaveDevice->write(downloadBuffer, bytesTotal);
720  }
721 
722  bytesDownloaded = bytesReceived;
723  lastBytesDownloaded = bytesReceived;
724 
725  downloadBufferCurrentSize = bytesReceived;
726 
727  // Only emit readyRead when actual data is there
728  // emit readyRead before downloadProgress incase this will cause events to be
729  // processed and we get into a recursive call (as in QProgressDialog).
730  if (bytesDownloaded > 0)
731  emit q->readyRead();
732  emit q->downloadProgress(bytesDownloaded, bytesTotal);
733 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ appendDownstreamDataSignalEmissions()

void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions ( )

Definition at line 612 of file qnetworkreplyimpl.cpp.

Referenced by appendDownstreamData().

613 {
615 
618  totalSize = totalSize.toLongLong() + preMigrationDownloaded;
620  // important: At the point of this readyRead(), the data parameter list must be empty,
621  // else implicit sharing will trigger memcpy when the user is reading data!
622  emit q->readyRead();
623  // emit readyRead before downloadProgress incase this will cause events to be
624  // processed and we get into a recursive call (as in QProgressDialog).
625  emit q->downloadProgress(bytesDownloaded,
626  totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
627 
629  // do we still have room in the buffer?
630  if (nextDownstreamBlockSize() > 0)
632 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
qint64 nextDownstreamBlockSize() const
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
#define emit
Definition: qobjectdefs.h:76
#define Q_INT64_C(c)
Definition: qglobal.h:940
CookedHeadersMap cookedHeaders
void backendNotify(InternalNotifications notification)

◆ backendNotify()

void QNetworkReplyImplPrivate::backendNotify ( InternalNotifications  notification)

Definition at line 387 of file qnetworkreplyimpl.cpp.

Referenced by _q_copyReadyRead(), and appendDownstreamDataSignalEmissions().

388 {
390  if (!pendingNotifications.contains(notification))
391  pendingNotifications.enqueue(notification);
392 
393  if (pendingNotifications.size() == 1)
395 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
NotificationQueue pendingNotifications
#define Q_Q(Class)
Definition: qglobal.h:2483
QBool contains(const T &t) const
Returns true if the list contains an occurrence of value; otherwise returns false.
Definition: qlist.h:880
void enqueue(const T &t)
Adds value t to the tail of the queue.
Definition: qqueue.h:60
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ completeCacheSave()

void QNetworkReplyImplPrivate::completeCacheSave ( )

Definition at line 508 of file qnetworkreplyimpl.cpp.

Referenced by finished().

509 {
511  if (cacheEnabled) {
513  networkCache()->remove(url);
514  } else if (cacheSaveDevice) {
516  }
518  }
519  cacheSaveDevice = 0;
520  cacheEnabled = false;
521 }
#define SLOT(a)
Definition: qobjectdefs.h:226
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
virtual void insert(QIODevice *device)=0
Inserts the data in device and the prepared meta data into the cache.
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAbstractNetworkCache * networkCache() const
QNetworkReply::NetworkError errorCode
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895

◆ consume()

void QNetworkReplyImplPrivate::consume ( qint64  count)

◆ createCache()

void QNetworkReplyImplPrivate::createCache ( )

Definition at line 455 of file qnetworkreplyimpl.cpp.

Referenced by setCachingEnabled().

456 {
457  // check if we can save and if we're allowed to
458  if (!networkCache()
463  return;
464  cacheEnabled = true;
465 }
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QAbstractNetworkCache * networkCache() const
QNetworkRequest request

◆ emitUploadProgress()

void QNetworkReplyImplPrivate::emitUploadProgress ( qint64  bytesSent,
qint64  bytesTotal 
)

Definition at line 523 of file qnetworkreplyimpl.cpp.

524 {
526  bytesUploaded = bytesSent;
528  emit q->uploadProgress(bytesSent, bytesTotal);
530 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76

◆ error()

void QNetworkReplyImplPrivate::error ( QNetworkReply::NetworkError  code,
const QString errorString 
)

Definition at line 799 of file qnetworkreplyimpl.cpp.

Referenced by _q_networkSessionFailed(), _q_startOperation(), QNetworkAccessBackend::error(), and finished().

800 {
802  // Can't set and emit multiple errors.
804  qWarning("QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once.");
805  return;
806  }
807 
808  errorCode = code;
809  q->setErrorString(errorMessage);
810 
811  // note: might not be a good idea, since users could decide to delete us
812  // which would delete the backend too...
813  // maybe we should protect the backend
814  emit q->error(code);
815 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
Q_CORE_EXPORT void qWarning(const char *,...)
QNetworkReply::NetworkError errorCode

◆ finished()

void QNetworkReplyImplPrivate::finished ( )

Definition at line 735 of file qnetworkreplyimpl.cpp.

Referenced by _q_networkSessionFailed(), _q_startOperation(), and QNetworkAccessBackend::finished().

736 {
738 
739  if (state == Finished || state == Aborted || state == WaitingForSession)
740  return;
741 
745  totalSize = totalSize.toLongLong() + preMigrationDownloaded;
746 
747  if (!manager.isNull()) {
748 #ifndef QT_NO_BEARERMANAGEMENT
749  QSharedPointer<QNetworkSession> session (manager->d_func()->getNetworkSession());
750  if (session && session->state() == QNetworkSession::Roaming &&
752  // only content with a known size will fail with a temporary network failure error
753  if (!totalSize.isNull()) {
754  if (bytesDownloaded != totalSize) {
755  if (migrateBackend()) {
756  // either we are migrating or the request is finished/aborted
757  if (state == Reconnecting || state == WaitingForSession) {
759  return; // exit early if we are migrating.
760  }
761  } else {
763  QNetworkReply::tr("Temporary network failure."));
764  }
765  }
766  }
767  }
768 #endif
769  }
771 
772  state = Finished;
773  q->setFinished(true);
774 
776 
778  if (totalSize.isNull() || totalSize == -1) {
779  emit q->downloadProgress(bytesDownloaded, bytesDownloaded);
780  }
781 
783  emit q->uploadProgress(0, 0);
785 
786  // if we don't know the total size of or we received everything save the cache
787  if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize)
789 
790  // note: might not be a good idea, since users could decide to delete us
791  // which would delete the backend too...
792  // maybe we should protect the backend
794  emit q->readChannelFinished();
795  emit q->finished();
797 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
QPointer< QNetworkAccessManager > manager
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
NotificationQueue pendingNotifications
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
#define emit
Definition: qobjectdefs.h:76
void clear()
Removes all items from the list.
Definition: qlist.h:764
QNetworkReply::NetworkError errorCode
#define Q_INT64_C(c)
Definition: qglobal.h:940
QSharedPointer< QRingBuffer > outgoingDataBuffer
CookedHeadersMap cookedHeaders
void error(QNetworkReply::NetworkError code, const QString &errorString)

◆ getDownloadBuffer()

char * QNetworkReplyImplPrivate::getDownloadBuffer ( qint64  size)

Definition at line 671 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::getDownloadBuffer().

672 {
674 
675  if (!downloadBuffer) {
676  // We are requested to create it
677  // Check attribute() if allocating a buffer of that size can be allowed
679  if (bufferAllocationPolicy.isValid() && bufferAllocationPolicy.toLongLong() >= size) {
682  downloadBuffer = new char[downloadBufferMaximumSize]; // throws if allocation fails
684 
686  }
687  }
688 
689  return downloadBuffer;
690 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QVariant qVariantFromValue(const T &)
Definition: qvariant.h:451
static void downloadBufferDeleter(char *ptr)
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
QSharedPointer< char > downloadBufferPointer
#define Q_Q(Class)
Definition: qglobal.h:2483
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
QNetworkRequest request
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485

◆ handleNotifications()

void QNetworkReplyImplPrivate::handleNotifications ( )

Definition at line 397 of file qnetworkreplyimpl.cpp.

Referenced by _q_startOperation().

398 {
400  return;
401 
404 
405  if (state != Working)
406  return;
407 
408  while (state == Working && !current.isEmpty()) {
409  InternalNotifications notification = current.dequeue();
410  switch (notification) {
412  if (copyDevice)
414  else
416  break;
417 
420  break;
421 
422  case NotifyCopyFinished: {
423  QIODevice *dev = copyDevice;
424  copyDevice = 0;
425  backend->copyFinished(dev);
426  break;
427  }
428  }
429  }
430 }
QQueue< InternalNotifications > NotificationQueue
virtual void closeDownstreamChannel()=0
QNetworkAccessBackend * backend
NotificationQueue pendingNotifications
void clear()
Removes all items from the list.
Definition: qlist.h:764
virtual void copyFinished(QIODevice *)
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ initCacheSaveDevice()

void QNetworkReplyImplPrivate::initCacheSaveDevice ( )

Definition at line 542 of file qnetworkreplyimpl.cpp.

Referenced by appendDownstreamData(), and appendDownstreamDataDownloadBuffer().

543 {
545 
546  // The disk cache does not support partial content, so don't even try to
547  // save any such content into the cache.
548  if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
549  cacheEnabled = false;
550  return;
551  }
552 
553  // save the meta data
554  QNetworkCacheMetaData metaData;
555  metaData.setUrl(url);
556  metaData = backend->fetchCacheMetaData(metaData);
557 
558  // save the redirect request also in the cache
559  QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute);
560  if (redirectionTarget.isValid()) {
562  attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
563  metaData.setAttributes(attributes);
564  }
565 
566  cacheSaveDevice = networkCache()->prepare(metaData);
567 
570  qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- "
571  "class %s probably needs to be fixed",
573 
574  networkCache()->remove(url);
575  cacheSaveDevice = 0;
576  cacheEnabled = false;
577  } else {
578  q->connect(networkCache(), SIGNAL(destroyed()), SLOT(_q_cacheDestroyed()));
579  }
580 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define SLOT(a)
Definition: qobjectdefs.h:226
QNetworkAccessBackend * backend
void setAttributes(const AttributesMap &attributes)
Sets all attributes of this cache item to be the map attributes.
virtual QNetworkCacheMetaData fetchCacheMetaData(const QNetworkCacheMetaData &metaData) const
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
void setUrl(const QUrl &url)
Sets the URL this network cache meta data to to be url.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
AttributesMap attributes() const
Returns all the attributes stored with this cache item.
QAbstractNetworkCache * networkCache() const
virtual QIODevice * prepare(const QNetworkCacheMetaData &metaData)=0
Returns the device that should be populated with the data for the cache item metaData.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
The QNetworkCacheMetaData class provides cache information.
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
Q_CORE_EXPORT void qCritical(const char *,...)

◆ isCachingEnabled()

bool QNetworkReplyImplPrivate::isCachingEnabled ( ) const

Definition at line 467 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::isCachingEnabled().

468 {
469  return (cacheEnabled && networkCache() != 0);
470 }
QAbstractNetworkCache * networkCache() const

◆ metaDataChanged()

void QNetworkReplyImplPrivate::metaDataChanged ( )

Definition at line 817 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::metaDataChanged().

818 {
820  // 1. do we have cookies?
821  // 2. are we allowed to set them?
823  && (static_cast<QNetworkRequest::LoadControl>
826  QList<QNetworkCookie> cookies =
829  if (jar)
830  jar->setCookiesFromUrl(cookies, url);
831  }
832  emit q->metaDataChanged();
833 }
QPointer< QNetworkAccessManager > manager
bool isNull() const
Returns true if the referenced object has been destroyed or if there is no referenced object; otherwi...
Definition: qpointer.h:70
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
#define emit
Definition: qobjectdefs.h:76
LoadControl
Indicates if an aspect of the request&#39;s loading mechanism has been manually overridden, e.
virtual bool setCookiesFromUrl(const QList< QNetworkCookie > &cookieList, const QUrl &url)
Adds the cookies in the list cookieList to this cookie jar.
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
QNetworkRequest request
CookedHeadersMap cookedHeaders
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
QNetworkCookieJar * cookieJar() const
Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cook...

◆ migrateBackend()

bool QNetworkReplyImplPrivate::migrateBackend ( )

Definition at line 1043 of file qnetworkreplyimpl.cpp.

Referenced by _q_networkSessionConnected(), and finished().

1044 {
1046 
1047  // Network reply is already finished or aborted, don't need to migrate.
1048  if (state == Finished || state == Aborted)
1049  return true;
1050 
1051  // Request has outgoing data, not migrating.
1052  if (outgoingData)
1053  return false;
1054 
1055  // Request is serviced from the cache, don't need to migrate.
1056  if (copyDevice)
1057  return true;
1058 
1059  // Backend does not support resuming download.
1060  if (backend && !backend->canResume())
1061  return false;
1062 
1064 
1065  if (backend) {
1066  delete backend;
1067  backend = 0;
1068  }
1069 
1070  cookedHeaders.clear();
1071  rawHeaders.clear();
1072 
1074 
1075  backend = manager->d_func()->findBackend(operation, request);
1076 
1077  if (backend) {
1078  backend->setParent(q);
1079  backend->reply = this;
1081  }
1082 
1083 #ifndef QT_NO_HTTP
1084  if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) {
1086  } else {
1087  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
1088  }
1089 #else
1090  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
1091 #endif // QT_NO_HTTP
1092 
1093  return true;
1094 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QPointer< QNetworkAccessManager > manager
QNetworkAccessBackend * backend
virtual bool canResume() const
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define Q_Q(Class)
Definition: qglobal.h:2483
QNetworkReplyImplPrivate * reply
QNetworkAccessManager::Operation operation
void clear()
Removes all items from the list.
Definition: qlist.h:764
QNetworkRequest request
CookedHeadersMap cookedHeaders
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
virtual void setResumeOffset(quint64 offset)

◆ networkCache()

QAbstractNetworkCache * QNetworkReplyImplPrivate::networkCache ( ) const

Definition at line 448 of file qnetworkreplyimpl.cpp.

Referenced by completeCacheSave(), createCache(), initCacheSaveDevice(), isCachingEnabled(), and setCachingEnabled().

449 {
450  if (!backend)
451  return 0;
452  return backend->networkCache();
453 }
QNetworkAccessBackend * backend
QAbstractNetworkCache * networkCache() const

◆ nextDownstreamBlockSize()

qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize ( ) const

Definition at line 533 of file qnetworkreplyimpl.cpp.

Referenced by _q_copyReadyRead(), appendDownstreamDataSignalEmissions(), and QNetworkAccessBackend::nextDownstreamBlockSize().

534 {
535  enum { DesiredBufferSize = 32 * 1024 };
536  if (readBufferMaxSize == 0)
537  return DesiredBufferSize;
538 
539  return qMax<qint64>(0, readBufferMaxSize - readBuffer.byteAmount());
540 }
qint64 byteAmount() const
Definition: qbytedata_p.h:181

◆ pauseNotificationHandling()

void QNetworkReplyImplPrivate::pauseNotificationHandling ( )

◆ redirectionRequested()

void QNetworkReplyImplPrivate::redirectionRequested ( const QUrl target)

Definition at line 835 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::redirectionRequested().

836 {
838 }
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753

◆ resumeNotificationHandling()

void QNetworkReplyImplPrivate::resumeNotificationHandling ( )

Definition at line 440 of file qnetworkreplyimpl.cpp.

Referenced by _q_copyReadyRead(), appendDownstreamDataSignalEmissions(), emitUploadProgress(), and finished().

441 {
444  if (pendingNotifications.size() >= 1)
446 }
static void postEvent(QObject *receiver, QEvent *event)
Adds the event event, with the object receiver as the receiver of the event, to an event queue and re...
NotificationQueue pendingNotifications
#define Q_Q(Class)
Definition: qglobal.h:2483
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56

◆ setCachingEnabled()

void QNetworkReplyImplPrivate::setCachingEnabled ( bool  enable)

Definition at line 472 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::setCachingEnabled().

473 {
475  if (!enable && !cacheEnabled)
476  return; // nothing to do
477  if (enable && cacheEnabled)
478  return; // nothing to do either!
479 
480  if (enable) {
481  if (bytesDownloaded) {
482  // refuse to enable in this case
483  qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written");
484  return;
485  }
486 
487  createCache();
488  } else {
489  // someone told us to turn on, then back off?
490  // ok... but you should make up your mind
491  qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- "
492  "backend %s probably needs to be fixed",
494  networkCache()->remove(url);
495  cacheSaveDevice = 0;
496  cacheEnabled = false;
498  }
499 }
#define SLOT(a)
Definition: qobjectdefs.h:226
QNetworkAccessBackend * backend
virtual bool remove(const QUrl &url)=0
Removes the cache entry for url, returning true if success otherwise false.
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QAbstractNetworkCache * networkCache() const
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
Q_CORE_EXPORT void qCritical(const char *,...)

◆ setDownloadBuffer()

void QNetworkReplyImplPrivate::setDownloadBuffer ( QSharedPointer< char >  sp,
qint64  size 
)

Definition at line 692 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessHttpBackend::replyDownloadMetaData().

693 {
695 
701 }
QVariant qVariantFromValue(const T &)
Definition: qvariant.h:451
QSharedPointer< char > downloadBufferPointer
#define Q_Q(Class)
Definition: qglobal.h:2483
T * data() const
Returns the value of the pointer referenced by this object.

◆ setup()

void QNetworkReplyImplPrivate::setup ( QNetworkAccessManager::Operation  op,
const QNetworkRequest request,
QIODevice outgoingData 
)

Definition at line 311 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessManager::createRequest().

313 {
315 
316  outgoingData = data;
317  request = req;
318  url = request.url();
319  operation = op;
320 
321  q->QIODevice::open(QIODevice::ReadOnly);
322  // Internal code that does a HTTP reply for the synchronous Ajax
323  // in QtWebKit.
324  QVariant synchronousHttpAttribute = req.attribute(
325  static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute));
326  // The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer.
327  // Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway.
328  if (synchronousHttpAttribute.toBool() && outgoingData) {
330  qint64 previousDataSize = 0;
331  do {
332  previousDataSize = outgoingDataBuffer->size();
333  outgoingDataBuffer->append(outgoingData->readAll());
334  } while (outgoingDataBuffer->size() != previousDataSize);
335  }
336 
337  if (backend)
338  backend->setSynchronous(synchronousHttpAttribute.toBool());
339 
340 
341  if (outgoingData && backend && !backend->isSynchronous()) {
342  // there is data to be uploaded, e.g. HTTP POST.
343 
344  if (!backend->needsResetableUploadData() || !outgoingData->isSequential()) {
345  // backend does not need upload buffering or
346  // fixed size non-sequential
347  // just start the operation
348  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
349  } else {
350  bool bufferingDisallowed =
352  false).toBool();
353 
354  if (bufferingDisallowed) {
355  // if a valid content-length header for the request was supplied, we can disable buffering
356  // if not, we will buffer anyway
357  if (req.header(QNetworkRequest::ContentLengthHeader).isValid()) {
358  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
359  } else {
360  state = Buffering;
361  QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection);
362  }
363  } else {
364  // _q_startOperation will be called when the buffering has finished.
365  state = Buffering;
366  QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection);
367  }
368  }
369  } else {
370  // for HTTP, we want to send out the request as fast as possible to the network, without
371  // invoking methods in a QueuedConnection
372 #ifndef QT_NO_HTTP
373  if (qobject_cast<QNetworkAccessHttpBackend *>(backend) || (backend && backend->isSynchronous())) {
375  } else {
376  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
377  }
378 #else
379  if (backend && backend->isSynchronous())
381  else
382  QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection);
383 #endif // QT_NO_HTTP
384  }
385 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
virtual bool needsResetableUploadData()
void append(const QByteArray &qba)
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
Definition: qvariant.cpp:2691
QNetworkAccessBackend * backend
QUrl url() const
Returns the URL this network request is referring to.
#define Q_Q(Class)
Definition: qglobal.h:2483
static const char * data(const QByteArray &arr)
QNetworkAccessManager::Operation operation
__int64 qint64
Definition: qglobal.h:942
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
Definition: qiodevice.cpp:454
QSharedPointer< QRingBuffer > outgoingDataBuffer
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
Definition: qiodevice.cpp:1025
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
int size() const

◆ sslErrors()

void QNetworkReplyImplPrivate::sslErrors ( const QList< QSslError > &  errors)

Definition at line 840 of file qnetworkreplyimpl.cpp.

Referenced by QNetworkAccessBackend::sslErrors().

841 {
842 #ifndef QT_NO_OPENSSL
844  emit q->sslErrors(errors);
845 #else
846  Q_UNUSED(errors);
847 #endif
848 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Properties

◆ backend

QNetworkAccessBackend* QNetworkReplyImplPrivate::backend

◆ bytesDownloaded

qint64 QNetworkReplyImplPrivate::bytesDownloaded

◆ bytesUploaded

qint64 QNetworkReplyImplPrivate::bytesUploaded

Definition at line 203 of file qnetworkreplyimpl_p.h.

Referenced by emitUploadProgress(), and finished().

◆ cacheEnabled

bool QNetworkReplyImplPrivate::cacheEnabled

◆ cacheSaveDevice

QIODevice* QNetworkReplyImplPrivate::cacheSaveDevice

◆ copyDevice

QIODevice* QNetworkReplyImplPrivate::copyDevice

◆ downloadBuffer

char* QNetworkReplyImplPrivate::downloadBuffer

◆ downloadBufferCurrentSize

qint64 QNetworkReplyImplPrivate::downloadBufferCurrentSize

◆ downloadBufferMaximumSize

qint64 QNetworkReplyImplPrivate::downloadBufferMaximumSize

Definition at line 215 of file qnetworkreplyimpl_p.h.

Referenced by getDownloadBuffer(), and setDownloadBuffer().

◆ downloadBufferPointer

QSharedPointer<char> QNetworkReplyImplPrivate::downloadBufferPointer

Definition at line 216 of file qnetworkreplyimpl_p.h.

Referenced by getDownloadBuffer(), and setDownloadBuffer().

◆ downloadBufferReadPosition

qint64 QNetworkReplyImplPrivate::downloadBufferReadPosition

Definition at line 213 of file qnetworkreplyimpl_p.h.

◆ httpReasonPhrase

QString QNetworkReplyImplPrivate::httpReasonPhrase

Definition at line 206 of file qnetworkreplyimpl_p.h.

◆ httpStatusCode

int QNetworkReplyImplPrivate::httpStatusCode

Definition at line 207 of file qnetworkreplyimpl_p.h.

◆ lastBytesDownloaded

qint64 QNetworkReplyImplPrivate::lastBytesDownloaded

◆ lastProxyAuthentication

QNetworkProxy QNetworkReplyImplPrivate::lastProxyAuthentication

◆ notificationHandlingPaused

bool QNetworkReplyImplPrivate::notificationHandlingPaused

◆ outgoingData

QIODevice* QNetworkReplyImplPrivate::outgoingData

◆ outgoingDataBuffer

QSharedPointer<QRingBuffer> QNetworkReplyImplPrivate::outgoingDataBuffer

Definition at line 181 of file qnetworkreplyimpl_p.h.

Referenced by _q_bufferOutgoingData(), finished(), and setup().

◆ pendingNotifications

NotificationQueue QNetworkReplyImplPrivate::pendingNotifications

◆ preMigrationDownloaded

qint64 QNetworkReplyImplPrivate::preMigrationDownloaded

◆ proxyList

QList<QNetworkProxy> QNetworkReplyImplPrivate::proxyList

◆ readBuffer

QByteDataBuffer QNetworkReplyImplPrivate::readBuffer

◆ state

State QNetworkReplyImplPrivate::state

◆ urlForLastAuthentication

QUrl QNetworkReplyImplPrivate::urlForLastAuthentication

The documentation for this class was generated from the following files: