MythTV master
mythhttpsocket.h
Go to the documentation of this file.
1#ifndef MYTHHTTPSOCKET_H
2#define MYTHHTTPSOCKET_H
3// Qt
4#include <QObject>
5#include <QTimer>
6#include <QAbstractSocket>
7#include <QElapsedTimer>
8
9// MythTV
12
13class QTcpSocket;
14class QSslSocket;
15class MythWebSocket;
17
18class MythHTTPSocket : public QObject
19{
20 Q_OBJECT
21
22 signals:
23 void Finish();
24 void UpdateServices(const HTTPServices& Services);
25 void ThreadUpgraded(QThread* Thread);
26
27 public slots:
28 void PathsChanged (const QStringList& Paths);
29 void HandlersChanged (const HTTPHandlers& Handlers);
30 void ServicesChanged (const HTTPServices& Services);
31 void HostsChanged (const QStringList& Hosts);
32 void OriginsChanged (const QStringList& Origins);
33 void NewTextMessage (const StringPayload& Text);
34 void NewRawTextMessage(const DataPayloads& Payloads);
35 static void NewBinaryMessage (const DataPayloads& Payloads);
36
37 public:
38 explicit MythHTTPSocket(qintptr Socket, bool SSL, MythHTTPConfig Config);
39 ~MythHTTPSocket() override;
40 void Respond(const HTTPResponse& Response);
41 static void RespondDirect(qintptr Socket, const HTTPResponse& Response, const MythHTTPConfig& Config);
42
43 protected slots:
44 void Disconnected();
45 void Timeout();
46 void Read();
47 void Stop();
48 void Write(int64_t Written = 0);
49 void Error(QAbstractSocket::SocketError Error);
50
51 private:
52 Q_DISABLE_COPY(MythHTTPSocket)
53 void SetupWebSocket();
54
55 qintptr m_socketFD { 0 };
58 bool m_stopping { false };
59 QTcpSocket* m_socket { nullptr };
61 QString m_peer;
62 QTimer m_timer;
65 int64_t m_totalToSend { 0 };
66 int64_t m_totalWritten { 0 };
67 int64_t m_totalSent { 0 };
68 QElapsedTimer m_writeTime;
72 // WebSockets only
73 bool m_testSocket { false };
75};
76
77#endif
HTTPQueue m_queue
QElapsedTimer m_writeTime
void Write(int64_t Written=0)
int64_t m_totalSent
void NewRawTextMessage(const DataPayloads &Payloads)
void NewTextMessage(const StringPayload &Text)
~MythHTTPSocket() override
static void RespondDirect(qintptr Socket, const HTTPResponse &Response, const MythHTTPConfig &Config)
Send an (error) response directly without creating a thread.
HTTPData m_writeBuffer
void Respond(const HTTPResponse &Response)
Send response to client.
void ThreadUpgraded(QThread *Thread)
void Disconnected()
The socket was disconnected.
QTcpSocket * m_socket
MythHTTPParser m_parser
void Timeout()
Close the socket after a period of inactivity.
MythHTTPConfig m_config
void Stop()
Close the socket and quit the thread.
void PathsChanged(const QStringList &Paths)
Update our list of recognised file paths.
static void NewBinaryMessage(const DataPayloads &Payloads)
HTTPServicePtrs m_activeServices
void UpdateServices(const HTTPServices &Services)
void HandlersChanged(const HTTPHandlers &Handlers)
void OriginsChanged(const QStringList &Origins)
Update the list of allowed Origins.
void Read()
Read data from the socket which is parsed by MythHTTPParser.
int64_t m_totalToSend
MythHTTPConnection m_nextConnection
MythWebSocket * m_websocket
qintptr m_socketFD
MythWebSocketEvent * m_websocketevent
void Error(QAbstractSocket::SocketError Error)
MythHTTPSocket(qintptr Socket, bool SSL, MythHTTPConfig Config)
void ServicesChanged(const HTTPServices &Services)
int64_t m_totalWritten
void SetupWebSocket()
Transition socket to a WebSocket.
void HostsChanged(const QStringList &Hosts)
MythSocketProtocol m_protocol
An implementation of the WebSocket protocol...
Definition: mythwebsocket.h:21
std::vector< DataPayload > DataPayloads
std::shared_ptr< MythSharedString > StringPayload
MythSocketProtocol
@ ProtHTTP
MythHTTPConnection
@ HTTPConnectionClose
std::vector< HTTPHandler > HTTPHandlers
Definition: mythhttptypes.h:48
std::shared_ptr< MythHTTPResponse > HTTPResponse
Definition: mythhttptypes.h:40
std::shared_ptr< MythHTTPData > HTTPData
Definition: mythhttptypes.h:37
std::vector< HTTPService > HTTPServices
Definition: mythhttptypes.h:55
std::vector< HTTPServicePtr > HTTPServicePtrs
Definition: mythhttptypes.h:52
std::deque< HTTPVariant > HTTPQueue
Definition: mythhttptypes.h:43