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 
16 /*
17  * MythDownloadManager leaks memory. For things like the HLS
18  * recorder, this leads to aborts in mythbackend when all the memory
19  * is exhausted. Until the leak can be found in MythDownloadManager,
20  * avoid the issue by using MythSingleDownload instead.
21  */
22 
23 class MBASE_PUBLIC MythSingleDownload : public QObject
24 {
25  Q_OBJECT
26 
27  public:
28  MythSingleDownload(void) = default;
29  ~MythSingleDownload(void) override = default;
30 
31  bool DownloadURL(const QUrl &url, QByteArray *buffer, uint timeout = 30000,
32  uint redirs = 0, qint64 maxsize = 0, QString *final_url = nullptr);
33  void Cancel(void);
34  QString ErrorString(void) const { return m_errorstring; }
35  QNetworkReply::NetworkError ErrorCode(void) const { return m_errorcode; }
36 
37  private slots:
38  void Progress(qint64 bytesRead, qint64 totalBytes);
39 
40  private:
41  QNetworkAccessManager m_mgr;
42  QTimer m_timer;
43  QNetworkReply *m_reply {nullptr};
44  QMutex m_lock;
45  QMutex m_replylock;
46 
47  QString m_errorstring;
48  QNetworkReply::NetworkError m_errorcode {QNetworkReply::NoError};
49  QByteArray *m_buffer {nullptr};
50  qint64 m_maxsize {0};
51 };
52 
53 #endif // MYTH_SINGLE_DOWNLOAD_H
MythSingleDownload::m_lock
QMutex m_lock
Definition: mythsingledownload.h:44
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
MythSingleDownload::MythSingleDownload
MythSingleDownload(void)=default
mythbaseexp.h
slots
unsigned int slots[4]
Definition: element.cpp:38
MythSingleDownload::m_mgr
QNetworkAccessManager m_mgr
Definition: mythsingledownload.h:41
MythSingleDownload::m_timer
QTimer m_timer
Definition: mythsingledownload.h:42
MythSingleDownload::m_errorstring
QString m_errorstring
Definition: mythsingledownload.h:47
MythSingleDownload::~MythSingleDownload
~MythSingleDownload(void) override=default
MBASE_PUBLIC
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
MythSingleDownload::ErrorCode
QNetworkReply::NetworkError ErrorCode(void) const
Definition: mythsingledownload.h:35
uint
unsigned int uint
Definition: compat.h:140
MythSingleDownload
Definition: mythsingledownload.h:24
MythSingleDownload::ErrorString
QString ErrorString(void) const
Definition: mythsingledownload.h:34
MythSingleDownload::m_replylock
QMutex m_replylock
Definition: mythsingledownload.h:45