aboutsummaryrefslogtreecommitdiff
path: root/src/protocols/guppyclient.hpp
blob: ebe76cb2132456d5456daf88fd926d50970aea5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef GUPPYCLIENT_HPP
#define GUPPYCLIENT_HPP

#include <QObject>
#include <QUdpSocket>
#include <QUrl>
#include <QTimer>

#include "protocolhandler.hpp"

class GuppyClient : public ProtocolHandler
{
    Q_OBJECT
public:
    explicit GuppyClient(QObject *parent = nullptr);

    ~GuppyClient() override;

    bool supportsScheme(QString const & scheme) const override;

    bool startRequest(QUrl const & url, RequestOptions options) override;

    bool isInProgress() const override;

    bool cancelRequest() override;

private: // slots
    void on_connected();
    void on_readRead();
    void on_finished();
    void on_timerTick();
    void on_socketError(QAbstractSocket::SocketError errorCode);


private:
    QUdpSocket socket;
    QHash<long, QByteArray> chunks;
    QByteArray body;
    QUrl requested_url;
    QByteArray request;
    bool was_cancelled;
    int prev_seq, first_seq, last_seq;
    QString mime;
    QTimer timer;
};

#endif // GUPPYCLIENT_HPP