56 m_rewindPositionInFile(0),
60 m_bufferSize(BufferSize),
61 m_reserveBufferSize(BufferSize >> 3),
62 m_writeBufferSize(BufferSize - m_reserveBufferSize),
63 m_buffer(QByteArray(BufferSize, 0)),
65 m_redirectionCount(0),
69 m_replyFinished(false),
70 m_replyBytesAvailable(0),
74 m_replyError(QNetworkReply::NoError),
81 m_byteServingAvailable(false)
89 :
m_type(QNetworkAccessManager::PostOperation),
148 QThread::usleep(50000);
155 return Read(Buffer, BufferSize, Timeout,
true);
186 m_positionInFile = Offset;
203 QThread::usleep(50000);
207 return -ECONNABORTED;
214 LOG(VB_GENERAL, LOG_INFO, QStringLiteral(
"Download complete"));
218 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Waited %1ms for data. Aborting").arg(Timeout));
219 return -ECONNABORTED;
222 available = qMin(available, BufferSize);
228 memcpy(Buffer + rest, (
void*)
m_buffer.constData(), available - rest);
231 m_readPosition = available - rest;
255 bool TorcNetworkRequest::WritePriv(QNetworkReply *Reply,
const char *Buffer,
int Size)
257 if (Reply && Buffer && Size)
259 char *buffer =
const_cast<char *
>(Buffer);
260 int read = Reply->read(buffer, Size);
264 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Error reading '%1'").arg(Reply->errorString()));
278 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Expected %1 bytes, got %2").arg(Size).arg(read));
305 if (!WritePriv(Reply,
m_buffer.constData(), available - rest))
323 LOG(VB_GENERAL, LOG_WARNING, QStringLiteral(
"Byte ranges already set - ignoring"));
329 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Invalid range start"));
378 foreach (QNetworkReply::RawHeaderPair header,
m_rawHeaders)
379 if (header.first == Header)
380 return header.second;
402 LOG(VB_GENERAL, LOG_WARNING, QStringLiteral(
"ReadAll called for a streamed buffer"));
407 QThread::usleep(50000);
413 LOG(VB_GENERAL, LOG_ERR, QStringLiteral(
"Download timed out - probably incomplete"));
TorcNetworkRequest(const QNetworkRequest &Request, QNetworkAccessManager::Operation Type, int BufferSize, int *Abort)
int Read(char *Buffer, qint32 BufferSize, int Timeout, bool Peek=false)
void SetReadSize(int Size)
void SetReplyError(QNetworkReply::NetworkError Error)
qint64 GetPosition(void) const
QNetworkReply::NetworkError GetReplyError(void) const
bool WaitForStart(int Timeout)
QNetworkAccessManager::Operation m_type
const QByteArray m_postData
QByteArray & GetBuffer(void)
int Peek(char *Buffer, qint32 BufferSize, int Timeout)
bool m_byteServingAvailable
#define DEFAULT_STREAMED_READ_SIZE
QString GetContentType(void) const
QUrl GetFinalURL(void) const
bool CanByteServe(void) const
QList< QNetworkReply::RawHeaderPair > m_rawHeaders
QNetworkRequest m_request
qint64 Seek(qint64 Offset)
void DownloadProgress(qint64 Received, qint64 Total)
void Write(QNetworkReply *Reply)
static void Poke(TorcNetworkRequest *Request)
#define LOG(_MASK_, _LEVEL_, _STRING_)
QNetworkReply::NetworkError m_replyError
qint64 m_rewindPositionInFile
QByteArray ReadAll(int Timeout)
QAtomicInt m_availableToRead
int m_replyBytesAvailable
int GetStatus(void) const
QByteArray GetHeader(const QByteArray &Header) const
Return the value of the given header, if present.
void SetRange(int Start, int End=0)
qint64 GetSize(void) const