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

Performs all the protocol-level work for a single websocket connection. More...

#include <websocket.h>

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

Public Types

enum  ErrorCode {
  kCloseNormal = 1000, kCloseGoingAway = 1001, kCloseProtocolError = 1002, kCloseUnsupported = 1003,
  kCloseNoStatus = 1005, kCloseAbnormal = 1006, kCloseBadData = 1007, kClosePolicy = 1008,
  kCloseTooLarge = 1009, kCloseNoExtensions = 1010, kCloseUnexpectedErr = 1011, kCloseNoTLS = 1012
}
 

Public Slots

void doRead ()
 
void CloseConnection ()
 
void SendHeartBeat ()
 
bool SendText (const QString &message)
 
bool SendText (const QByteArray &message)
 
bool SendBinary (const QByteArray &data)
 

Public Member Functions

 WebSocketWorker (WebSocketServer &webSocketServer, qt_socket_fd_t sock, PoolServerType type, const QSslConfiguration &sslConfig)
 
 ~WebSocketWorker () override
 
void Exec ()
 

Protected Member Functions

bool ProcessHandshake (QTcpSocket *socket)
 
void ProcessFrames (QTcpSocket *socket)
 Returns false if an error occurs. More...
 
void HandleControlFrame (const WebSocketFrame &frame)
 Returns false if an error occurs. More...
 
void HandleDataFrame (const WebSocketFrame &frame)
 
void HandleCloseConnection (const QByteArray &payload)
 
bool SendFrame (const QByteArray &frame)
 
bool SendPing (const QByteArray &payload)
 
bool SendPong (const QByteArray &payload)
 
bool SendClose (ErrorCode errCode, const QString &message=QString())
 
void SetupSocket ()
 
void CleanupSocket ()
 
void RegisterExtension (WebSocketExtension *extension)
 
void DeregisterExtension (WebSocketExtension *extension)
 

Static Protected Member Functions

static QByteArray CreateFrame (WebSocketFrame::OpCode type, const QByteArray &payload)
 

Protected Attributes

QEventLoop * m_eventLoop {nullptr}
 
WebSocketServerm_webSocketServer
 
qt_socket_fd_t m_socketFD
 
QTcpSocket * m_socket {nullptr}
 
PoolServerType m_connectionType
 
bool m_webSocketMode {false}
 
WebSocketFrame m_readFrame
 
uint8_t m_errorCount {0}
 
bool m_isRunning {false}
 
QTimer * m_heartBeat {nullptr}
 
QSslConfiguration m_sslConfig
 
bool m_fuzzTesting {false}
 
QList< WebSocketExtension * > m_extensions
 

Detailed Description

Performs all the protocol-level work for a single websocket connection.

The worker is created by WebSocketServer after a raw socket is opened. It runs in it's own thread, an instance of WebSocketServerThread.

The worker parses the initial HTTP connection and upgrades the connection to use the WebSocket protocol. It manages the heartbeat, parses and validates frames, reconstitutes payloads from fragmented frames and handles other basic protocol level tasks.

When complete data frames have been received, it checks whether any registered extensions wish to handle them. It is also responsible for creating properly formatted, valid frames and transmitting them to the client.

Definition at line 197 of file websocket.h.

Member Enumeration Documentation

◆ ErrorCode

Enumerator
kCloseNormal 
kCloseGoingAway 
kCloseProtocolError 
kCloseUnsupported 
kCloseNoStatus 
kCloseAbnormal 
kCloseBadData 
kClosePolicy 
kCloseTooLarge 
kCloseNoExtensions 
kCloseUnexpectedErr 
kCloseNoTLS 

Definition at line 219 of file websocket.h.

Constructor & Destructor Documentation

◆ WebSocketWorker()

WebSocketWorker::WebSocketWorker ( WebSocketServer webSocketServer,
qt_socket_fd_t  sock,
PoolServerType  type,
const QSslConfiguration &  sslConfig 
)
Parameters
webSocketServerThe parent server of this request
sockThe socket
typeThe type of connection - Plain TCP or TLS?
sslConfigThe TLS (ssl) configuration (for TLS sockets)

Definition at line 101 of file websocket.cpp.

◆ ~WebSocketWorker()

WebSocketWorker::~WebSocketWorker ( )
override

Definition at line 128 of file websocket.cpp.

Member Function Documentation

◆ Exec()

void WebSocketWorker::Exec ( )

Definition at line 146 of file websocket.cpp.

◆ doRead

void WebSocketWorker::doRead ( )
slot

Definition at line 283 of file websocket.cpp.

Referenced by SetupSocket().

◆ CloseConnection

void WebSocketWorker::CloseConnection ( )
slot

Definition at line 151 of file websocket.cpp.

Referenced by doRead(), SendClose(), and SetupSocket().

◆ SendHeartBeat

void WebSocketWorker::SendHeartBeat ( )
slot

Definition at line 923 of file websocket.cpp.

Referenced by SetupSocket().

◆ SendText [1/2]

bool WebSocketWorker::SendText ( const QString &  message)
slot

Definition at line 858 of file websocket.cpp.

Referenced by HandleDataFrame(), and RegisterExtension().

◆ SendText [2/2]

bool WebSocketWorker::SendText ( const QByteArray &  message)
slot

Definition at line 863 of file websocket.cpp.

◆ SendBinary

bool WebSocketWorker::SendBinary ( const QByteArray &  data)
slot

Definition at line 878 of file websocket.cpp.

Referenced by HandleDataFrame(), and RegisterExtension().

◆ ProcessHandshake()

bool WebSocketWorker::ProcessHandshake ( QTcpSocket *  socket)
protected

Definition at line 311 of file websocket.cpp.

Referenced by doRead().

◆ ProcessFrames()

void WebSocketWorker::ProcessFrames ( QTcpSocket *  socket)
protected

Returns false if an error occurs.

Definition at line 483 of file websocket.cpp.

Referenced by doRead().

◆ HandleControlFrame()

void WebSocketWorker::HandleControlFrame ( const WebSocketFrame frame)
protected

Returns false if an error occurs.

Definition at line 670 of file websocket.cpp.

◆ HandleDataFrame()

void WebSocketWorker::HandleDataFrame ( const WebSocketFrame frame)
protected

Definition at line 674 of file websocket.cpp.

Referenced by ProcessFrames().

◆ HandleCloseConnection()

void WebSocketWorker::HandleCloseConnection ( const QByteArray &  payload)
protected

Definition at line 722 of file websocket.cpp.

Referenced by ProcessFrames().

◆ CreateFrame()

QByteArray WebSocketWorker::CreateFrame ( WebSocketFrame::OpCode  type,
const QByteArray &  payload 
)
staticprotected

Definition at line 767 of file websocket.cpp.

Referenced by SendBinary(), SendClose(), SendPing(), SendPong(), and SendText().

◆ SendFrame()

bool WebSocketWorker::SendFrame ( const QByteArray &  frame)
protected

Definition at line 843 of file websocket.cpp.

Referenced by SendBinary(), SendClose(), SendPing(), SendPong(), and SendText().

◆ SendPing()

bool WebSocketWorker::SendPing ( const QByteArray &  payload)
protected

Definition at line 885 of file websocket.cpp.

Referenced by SendHeartBeat().

◆ SendPong()

bool WebSocketWorker::SendPong ( const QByteArray &  payload)
protected

Definition at line 892 of file websocket.cpp.

Referenced by ProcessFrames().

◆ SendClose()

bool WebSocketWorker::SendClose ( ErrorCode  errCode,
const QString &  message = QString() 
)
protected

◆ SetupSocket()

void WebSocketWorker::SetupSocket ( )
protected

Definition at line 160 of file websocket.cpp.

Referenced by WebSocketWorker().

◆ CleanupSocket()

void WebSocketWorker::CleanupSocket ( )
protected

Definition at line 222 of file websocket.cpp.

Referenced by ~WebSocketWorker().

◆ RegisterExtension()

void WebSocketWorker::RegisterExtension ( WebSocketExtension extension)
protected

Definition at line 928 of file websocket.cpp.

Referenced by WebSocketWorker().

◆ DeregisterExtension()

void WebSocketWorker::DeregisterExtension ( WebSocketExtension extension)
protected

Definition at line 941 of file websocket.cpp.

Member Data Documentation

◆ m_eventLoop

QEventLoop* WebSocketWorker::m_eventLoop {nullptr}
protected

Definition at line 273 of file websocket.h.

Referenced by CloseConnection(), Exec(), and ~WebSocketWorker().

◆ m_webSocketServer

WebSocketServer& WebSocketWorker::m_webSocketServer
protected

Definition at line 274 of file websocket.h.

Referenced by CleanupSocket(), and doRead().

◆ m_socketFD

qt_socket_fd_t WebSocketWorker::m_socketFD
protected

Definition at line 275 of file websocket.h.

Referenced by CleanupSocket(), SetupSocket(), and WebSocketWorker().

◆ m_socket

QTcpSocket* WebSocketWorker::m_socket {nullptr}
protected

Definition at line 276 of file websocket.h.

Referenced by CleanupSocket(), doRead(), SendFrame(), and SetupSocket().

◆ m_connectionType

PoolServerType WebSocketWorker::m_connectionType
protected

Definition at line 277 of file websocket.h.

Referenced by SetupSocket().

◆ m_webSocketMode

bool WebSocketWorker::m_webSocketMode {false}
protected

Definition at line 280 of file websocket.h.

Referenced by doRead(), and ProcessHandshake().

◆ m_readFrame

WebSocketFrame WebSocketWorker::m_readFrame
protected

Definition at line 281 of file websocket.h.

Referenced by HandleDataFrame(), and ProcessFrames().

◆ m_errorCount

uint8_t WebSocketWorker::m_errorCount {0}
protected

Definition at line 283 of file websocket.h.

Referenced by ProcessFrames().

◆ m_isRunning

bool WebSocketWorker::m_isRunning {false}
protected

Definition at line 284 of file websocket.h.

Referenced by CloseConnection(), doRead(), ProcessFrames(), and WebSocketWorker().

◆ m_heartBeat

QTimer* WebSocketWorker::m_heartBeat {nullptr}
protected

Definition at line 286 of file websocket.h.

Referenced by ProcessHandshake(), SetupSocket(), and ~WebSocketWorker().

◆ m_sslConfig

QSslConfiguration WebSocketWorker::m_sslConfig
protected

Definition at line 289 of file websocket.h.

Referenced by SetupSocket().

◆ m_fuzzTesting

bool WebSocketWorker::m_fuzzTesting {false}
protected

Definition at line 292 of file websocket.h.

Referenced by HandleDataFrame(), ProcessFrames(), and ProcessHandshake().

◆ m_extensions

QList<WebSocketExtension *> WebSocketWorker::m_extensions
protected

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