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) = 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
unsigned int slots[4]
Definition: element.c:38
#define MBASE_PUBLIC
Definition: mythbaseexp.h:15
QNetworkAccessManager m_mgr
unsigned int uint
Definition: compat.h:140
QString ErrorString(void) const
QNetworkReply::NetworkError ErrorCode(void) const