MythTV  master
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MythWebSocket Class Reference

An implementation of the WebSocket protocol... More...

#include <mythwebsocket.h>

Inheritance diagram for MythWebSocket:
Inheritance graph
[legend]
Collaboration diagram for MythWebSocket:
Collaboration graph
[legend]

Public Slots

void Read ()
 
void Write (int64_t Written=0)
 
void Close ()
 Initiate the close handshake when we are exiting. More...
 
void SendTextFrame (const QString &Text)
 
void SendBinaryFrame (const QByteArray &Data)
 

Signals

void NewTextMessage (const StringPayload &Text)
 
void NewRawTextMessage (const DataPayloads &Payloads)
 
void NewBinaryMessage (const DataPayloads &Payloads)
 

Public Member Functions

 ~MythWebSocket () override
 

Static Public Member Functions

static MythWebSocketCreateWebsocket (bool Server, QTcpSocket *Socket, MythSocketProtocol Protocol, bool Testing)
 

Protected Member Functions

 MythWebSocket (bool Server, QTcpSocket *Socket, MythSocketProtocol Protocol, bool Testing)
 

Private Types

enum  ReadState {
  ReadHeader = 0, Read16BitLength, Read64BitLength, ReadMask,
  ReadPayload
}
 

Private Member Functions

void PingReceived (DataPayload Payload)
 
void PongReceived (const DataPayload &Payload)
 
void CloseReceived (const DataPayload &Payload)
 
void CheckClose ()
 
void SendClose (WSErrorCode Code, const QString &Message={})
 
void SendPing ()
 
void SendFrame (WSOpCode Code, const DataPayloads &Payloads)
 

Private Attributes

QTcpSocket * m_socket { nullptr }
 
MythSocketProtocol m_protocol { ProtFrame }
 
WSOpCode m_formatForProtocol { WSOpTextFrame }
 
bool m_preferRawText { false }
 
bool m_testing { false }
 
QTimer * m_timer { nullptr }
 
ReadState m_readState { ReadHeader }
 
bool m_serverSide { false }
 
bool m_closeSent { false }
 
bool m_closeReceived { false }
 
bool m_closing { false }
 
WSFrame m_currentFrame { nullptr }
 
WSOpCode m_messageOpCode { WSOpTextFrame }
 
int64_t m_messageSize { 0 }
 
DataPayloads m_dataFragments
 
StringPayload m_string { nullptr }
 
QStringDecoder * m_toUtf16 { new QStringDecoder }
 
QByteArray m_lastPingPayload
 
WSQueue m_writeQueue
 
int64_t m_writeTotal { 0 }
 
QElapsedTimer m_writeTime
 

Detailed Description

An implementation of the WebSocket protocol...

This currently passes all 303 Autobahn test suite conformance and performance tests (1.* -> 10.*) with only 3 'non-strict' passes (6.4.2, 6.4.3 and 6.4.4).

Note
When not in testing mode, connections will be closed if a frame larger than 1MB or a message larger than 4MB is received.

Definition at line 20 of file mythwebsocket.h.

Member Enumeration Documentation

◆ ReadState

Enumerator
ReadHeader 
Read16BitLength 
Read64BitLength 
ReadMask 
ReadPayload 

Definition at line 53 of file mythwebsocket.h.

Constructor & Destructor Documentation

◆ ~MythWebSocket()

MythWebSocket::~MythWebSocket ( )
override

Definition at line 63 of file mythwebsocket.cpp.

◆ MythWebSocket()

MythWebSocket::MythWebSocket ( bool  Server,
QTcpSocket *  Socket,
MythSocketProtocol  Protocol,
bool  Testing 
)
protected

Definition at line 39 of file mythwebsocket.cpp.

Member Function Documentation

◆ CreateWebsocket()

MythWebSocket * MythWebSocket::CreateWebsocket ( bool  Server,
QTcpSocket *  Socket,
MythSocketProtocol  Protocol,
bool  Testing 
)
static

Definition at line 31 of file mythwebsocket.cpp.

Referenced by MythHTTPSocket::SetupWebSocket().

◆ Read

void MythWebSocket::Read ( )
slot

Definition at line 95 of file mythwebsocket.cpp.

Referenced by MythWebSocket().

◆ Write

void MythWebSocket::Write ( int64_t  Written = 0)
slot

Definition at line 432 of file mythwebsocket.cpp.

Referenced by MythWebSocket(), and SendFrame().

◆ Close

void MythWebSocket::Close ( )
slot

Initiate the close handshake when we are exiting.

Note
This is intended to be used when the server or client connection is exiting and we want to be a good netizen and send a proper close request. There is however no expectation that the socket will remain open to complete the close handshake; and thus the close will likely be 'unclean'.

Definition at line 80 of file mythwebsocket.cpp.

Referenced by MythHTTPSocket::Stop().

◆ SendTextFrame

void MythWebSocket::SendTextFrame ( const QString &  Text)
slot

Definition at line 85 of file mythwebsocket.cpp.

Referenced by MythHTTPSocket::SetupWebSocket().

◆ SendBinaryFrame

void MythWebSocket::SendBinaryFrame ( const QByteArray &  Data)
slot

Definition at line 90 of file mythwebsocket.cpp.

◆ NewTextMessage

void MythWebSocket::NewTextMessage ( const StringPayload Text)
signal

◆ NewRawTextMessage

void MythWebSocket::NewRawTextMessage ( const DataPayloads Payloads)
signal

◆ NewBinaryMessage

void MythWebSocket::NewBinaryMessage ( const DataPayloads Payloads)
signal

◆ PingReceived()

void MythWebSocket::PingReceived ( DataPayload  Payload)
private

Definition at line 662 of file mythwebsocket.cpp.

Referenced by Read().

◆ PongReceived()

void MythWebSocket::PongReceived ( const DataPayload Payload)
private

Definition at line 669 of file mythwebsocket.cpp.

Referenced by Read().

◆ CloseReceived()

void MythWebSocket::CloseReceived ( const DataPayload Payload)
private

Definition at line 529 of file mythwebsocket.cpp.

Referenced by Read().

◆ CheckClose()

void MythWebSocket::CheckClose ( )
private

Definition at line 505 of file mythwebsocket.cpp.

Referenced by CloseReceived(), and SendClose().

◆ SendClose()

void MythWebSocket::SendClose ( WSErrorCode  Code,
const QString &  Message = {} 
)
private

Definition at line 578 of file mythwebsocket.cpp.

Referenced by Close(), CloseReceived(), and Read().

◆ SendPing()

void MythWebSocket::SendPing ( )
private

Definition at line 682 of file mythwebsocket.cpp.

Referenced by MythWebSocket().

◆ SendFrame()

void MythWebSocket::SendFrame ( WSOpCode  Code,
const DataPayloads Payloads 
)
private

Member Data Documentation

◆ m_socket

QTcpSocket* MythWebSocket::m_socket { nullptr }
private

Definition at line 62 of file mythwebsocket.h.

Referenced by CheckClose(), MythWebSocket(), Read(), and Write().

◆ m_protocol

MythSocketProtocol MythWebSocket::m_protocol { ProtFrame }
private

Definition at line 63 of file mythwebsocket.h.

Referenced by MythWebSocket(), and Read().

◆ m_formatForProtocol

WSOpCode MythWebSocket::m_formatForProtocol { WSOpTextFrame }
private

Definition at line 64 of file mythwebsocket.h.

Referenced by Read().

◆ m_preferRawText

bool MythWebSocket::m_preferRawText { false }
private

Definition at line 65 of file mythwebsocket.h.

Referenced by MythWebSocket(), and Read().

◆ m_testing

bool MythWebSocket::m_testing { false }
private

Definition at line 66 of file mythwebsocket.h.

Referenced by MythWebSocket(), and Read().

◆ m_timer

QTimer* MythWebSocket::m_timer { nullptr }
private

Definition at line 67 of file mythwebsocket.h.

Referenced by CheckClose(), MythWebSocket(), and ~MythWebSocket().

◆ m_readState

ReadState MythWebSocket::m_readState { ReadHeader }
private

Definition at line 68 of file mythwebsocket.h.

Referenced by Read().

◆ m_serverSide

bool MythWebSocket::m_serverSide { false }
private

Definition at line 69 of file mythwebsocket.h.

Referenced by CheckClose(), Read(), and SendFrame().

◆ m_closeSent

bool MythWebSocket::m_closeSent { false }
private

Definition at line 70 of file mythwebsocket.h.

Referenced by CheckClose(), PingReceived(), SendClose(), and SendFrame().

◆ m_closeReceived

bool MythWebSocket::m_closeReceived { false }
private

Definition at line 71 of file mythwebsocket.h.

Referenced by CheckClose(), CloseReceived(), PingReceived(), Read(), and SendFrame().

◆ m_closing

bool MythWebSocket::m_closing { false }
private

Definition at line 72 of file mythwebsocket.h.

Referenced by CheckClose().

◆ m_currentFrame

WSFrame MythWebSocket::m_currentFrame { nullptr }
private

Definition at line 74 of file mythwebsocket.h.

Referenced by Read().

◆ m_messageOpCode

WSOpCode MythWebSocket::m_messageOpCode { WSOpTextFrame }
private

Definition at line 75 of file mythwebsocket.h.

Referenced by Read().

◆ m_messageSize

int64_t MythWebSocket::m_messageSize { 0 }
private

Definition at line 76 of file mythwebsocket.h.

Referenced by Read().

◆ m_dataFragments

DataPayloads MythWebSocket::m_dataFragments
private

Definition at line 77 of file mythwebsocket.h.

Referenced by Read().

◆ m_string

StringPayload MythWebSocket::m_string { nullptr }
private

Definition at line 78 of file mythwebsocket.h.

Referenced by Read().

◆ m_toUtf16

QStringDecoder* MythWebSocket::m_toUtf16 { new QStringDecoder }
private

Definition at line 83 of file mythwebsocket.h.

Referenced by CloseReceived(), Read(), and ~MythWebSocket().

◆ m_lastPingPayload

QByteArray MythWebSocket::m_lastPingPayload
private

Definition at line 86 of file mythwebsocket.h.

Referenced by PongReceived(), and SendPing().

◆ m_writeQueue

WSQueue MythWebSocket::m_writeQueue
private

Definition at line 87 of file mythwebsocket.h.

Referenced by SendFrame(), and Write().

◆ m_writeTotal

int64_t MythWebSocket::m_writeTotal { 0 }
private

Definition at line 88 of file mythwebsocket.h.

Referenced by Write().

◆ m_writeTime

QElapsedTimer MythWebSocket::m_writeTime
private

Definition at line 89 of file mythwebsocket.h.

Referenced by Write().


The documentation for this class was generated from the following files: