Torc  0.1
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | List of all members
TorcWebSocket Class Reference

Overlays the Websocket protocol over a QTcpSocket. More...

#include <torcwebsocket.h>

Inheritance diagram for TorcWebSocket:
[legend]

Public Types

enum  SocketState {
  DisconnectedSt = (0 << 0), ConnectingTo = (1 << 1), ConnectedTo = (1 << 2), Upgrading = (1 << 3),
  Upgraded = (1 << 4), Disconnecting = (1 << 5), ErroredSt = (1 << 6)
}
 

Public Slots

void Start (void)
 Initialise the websocket once its parent thread is ready. More...
 
void CloseSocket (void)
 
void PropertyChanged (void)
 Receives notifications when a property for a subscribed service has changed. More...
 
bool HandleNotification (const QString &Method)
 
void RemoteRequest (TorcRPCRequest *Request)
 Initiate a Remote Procedure Call. More...
 
void CancelRequest (TorcRPCRequest *Request)
 Cancel a Remote Procedure Call. More...
 
void Encrypted (void)
 
void SSLErrors (const QList< QSslError > &Errors)
 

Signals

void ConnectionEstablished (void)
 
void ConnectionUpgraded (void)
 
void Disconnected (void)
 
void Disconnect (void)
 

Public Member Functions

 TorcWebSocket (TorcWebSocketThread *Parent, qintptr SocketDescriptor, bool Secure)
 
 TorcWebSocket (TorcWebSocketThread *Parent, const QHostAddress &Address, quint16 Port, bool Secure, TorcWebSocketReader::WSSubProtocol Protocol=TorcWebSocketReader::SubProtocolJSONRPC)
 
 ~TorcWebSocket ()
 
bool IsSecure (void)
 

Static Public Member Functions

static QVariantList GetSupportedSubProtocols (void)
 Return a list of supported WebSocket sub-protocols. More...
 

Protected Slots

void ReadyRead (void)
 Process incoming data. More...
 
void Connected (void)
 
void Error (QAbstractSocket::SocketError)
 
void SubscriberDeleted (QObject *Subscriber)
 A subscriber object has been deleted. More...
 
void TimedOut (void)
 
void BytesWritten (qint64)
 

Protected Member Functions

bool event (QEvent *Event) override
 

Detailed Description

Overlays the Websocket protocol over a QTcpSocket.

See also
TorcHTTPServer
TorcHTTPRequest
TorcWebSocketThread

TorcWebSocket is NOT thread safe. It will make direct function calls to registered services - which must ensure those functions are thread safe. Likewise RemoteRequest etc can be called from any thread. For thread safe operation - use TorcWebSocketThread.

Note
SubProtocol support is currently limited to JSON-RPC. New subprotocols with mixed frame support (Binary and Text) are not currently supported.
To test using the Autobahn python test suite, configure the suite to request a connection using 'echo' as the method (e.g. 'http://your-ip-address:your-port/echo').
Todo:

Limit frame size for reading

Fix testsuite partial failures (fail fast on invalid UTF-8)

Add timeout for response to upgrade request

Definition at line 23 of file torcwebsocket.h.

Member Enumeration Documentation

Enumerator
DisconnectedSt 
ConnectingTo 
ConnectedTo 
Upgrading 
Upgraded 
Disconnecting 
ErroredSt 

Definition at line 28 of file torcwebsocket.h.

Constructor & Destructor Documentation

TorcWebSocket::TorcWebSocket ( TorcWebSocketThread Parent,
qintptr  SocketDescriptor,
bool  Secure 
)

Definition at line 62 of file torcwebsocket.cpp.

TorcWebSocket::TorcWebSocket ( TorcWebSocketThread Parent,
const QHostAddress &  Address,
quint16  Port,
bool  Secure,
TorcWebSocketReader::WSSubProtocol  Protocol = TorcWebSocketReader::SubProtocolJSONRPC 
)

Definition at line 88 of file torcwebsocket.cpp.

TorcWebSocket::~TorcWebSocket ( )

Definition at line 113 of file torcwebsocket.cpp.

Member Function Documentation

void TorcWebSocket::BytesWritten ( qint64  )
protectedslot

Definition at line 977 of file torcwebsocket.cpp.

void TorcWebSocket::CancelRequest ( TorcRPCRequest Request)
slot

Cancel a Remote Procedure Call.

Note
We assume the request will only ever be referenced by its owner and by TorcWebSocket.

Definition at line 572 of file torcwebsocket.cpp.

void TorcWebSocket::CloseSocket ( void  )
slot

Definition at line 761 of file torcwebsocket.cpp.

void TorcWebSocket::Connected ( void  )
protectedslot

Definition at line 774 of file torcwebsocket.cpp.

void TorcWebSocket::ConnectionEstablished ( void  )
signal
void TorcWebSocket::ConnectionUpgraded ( void  )
signal
void TorcWebSocket::Disconnect ( void  )
signal
void TorcWebSocket::Disconnected ( void  )
signal
void TorcWebSocket::Encrypted ( void  )
slot

Definition at line 404 of file torcwebsocket.cpp.

void TorcWebSocket::Error ( QAbstractSocket::SocketError  SocketError)
protectedslot

Definition at line 959 of file torcwebsocket.cpp.

bool TorcWebSocket::event ( QEvent *  Event)
overrideprotected

Definition at line 983 of file torcwebsocket.cpp.

QVariantList TorcWebSocket::GetSupportedSubProtocols ( void  )
static

Return a list of supported WebSocket sub-protocols.

Definition at line 394 of file torcwebsocket.cpp.

bool TorcWebSocket::HandleNotification ( const QString &  Method)
slot

Definition at line 508 of file torcwebsocket.cpp.

bool TorcWebSocket::IsSecure ( void  )

Definition at line 423 of file torcwebsocket.cpp.

void TorcWebSocket::PropertyChanged ( void  )
slot

Receives notifications when a property for a subscribed service has changed.

Definition at line 496 of file torcwebsocket.cpp.

void TorcWebSocket::ReadyRead ( void  )
protectedslot

Process incoming data.

Data for any given frame may be received over a number of packets, hence the need to track the current read status.

Definition at line 668 of file torcwebsocket.cpp.

void TorcWebSocket::RemoteRequest ( TorcRPCRequest Request)
slot

Initiate a Remote Procedure Call.

Note
This should always be called from within the websocket's thread.

Definition at line 529 of file torcwebsocket.cpp.

void TorcWebSocket::SSLErrors ( const QList< QSslError > &  Errors)
slot

Definition at line 416 of file torcwebsocket.cpp.

void TorcWebSocket::Start ( void  )
slot

Initialise the websocket once its parent thread is ready.

Definition at line 429 of file torcwebsocket.cpp.

void TorcWebSocket::SubscriberDeleted ( QObject *  Object)
protectedslot

A subscriber object has been deleted.

If subscribers exit without unsubscribing, the subscriber list will never be cleaned up. So listen for deletion signals and act if necessary.

Definition at line 745 of file torcwebsocket.cpp.

void TorcWebSocket::TimedOut ( void  )
protectedslot

Definition at line 968 of file torcwebsocket.cpp.


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