MythTV master
mythsingledownload.h
Go to the documentation of this file.
1#ifndef MYTH_SINGLE_DOWNLOAD_H
2#define MYTH_SINGLE_DOWNLOAD_H
3
4//#include <QObject>
5#include <QString>
6#include <QByteArray>
7#include <QNetworkAccessManager>
8#include <QNetworkRequest>
9#include <QNetworkReply>
10#include <QMutex>
11#include <QTimer>
12#include <QEventLoop>
13
14#include "mythbaseexp.h"
15
16using namespace std::chrono_literals;
17
18/*
19 * MythDownloadManager leaks memory. For things like the HLS
20 * recorder, this leads to aborts in mythbackend when all the memory
21 * is exhausted. Until the leak can be found in MythDownloadManager,
22 * avoid the issue by using MythSingleDownload instead.
23 */
24
25class MBASE_PUBLIC MythSingleDownload : public QObject
26{
27 Q_OBJECT
28
29 public:
30 MythSingleDownload(void) = default;
31 ~MythSingleDownload(void) override = default;
32
33 bool DownloadURL(const QUrl &url, QByteArray *buffer, std::chrono::seconds timeout = 30s,
34 uint redirs = 0, qint64 maxsize = 0, QString *final_url = nullptr);
35 void Cancel(void);
36 QString ErrorString(void) const { return m_errorstring; }
37 QNetworkReply::NetworkError ErrorCode(void) const { return m_errorcode; }
38
39 private slots:
40 void Progress(qint64 bytesRead, qint64 totalBytes);
41
42 private:
43 QNetworkAccessManager m_mgr;
44 QTimer m_timer;
45 QNetworkReply *m_reply {nullptr};
46 QMutex m_lock;
48
50 QNetworkReply::NetworkError m_errorcode {QNetworkReply::NoError};
51 QByteArray *m_buffer {nullptr};
52 qint64 m_maxsize {0};
53};
54
55#endif // MYTH_SINGLE_DOWNLOAD_H
QString ErrorString(void) const
QNetworkAccessManager m_mgr
QNetworkReply::NetworkError ErrorCode(void) const
MythSingleDownload(void)=default
~MythSingleDownload(void) override=default
unsigned int uint
Definition: freesurround.h:24
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15