CoreComponents 4.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
WebSocketStream Class Referencefinal

WebSocket message stream. More...

#include <cc/WebSocketStream>

Inheritance diagram for WebSocketStream:

Public Types

enum  Type { ServerToClient = 0 , ClientToServer = 1 }
 Communication direction. More...
 
- Public Types inherited from Object
using NullAccess = cc::NullAccess
 Error thrown when trying to access a null object.
 
using VirginityTestFailed = cc::VirginityTestFailed
 Error thrown when trying to initialize an object with a non-virgin state.
 

Public Member Functions

 WebSocketStream ()=default
 Create a null object.
 
 WebSocketStream (const Stream &stream, Type type)
 Create a new frame stream.
 
WebSocketStreammaxOutgoingFramePayloadSize (long size)
 Set the maximum frame payload size
 
WebSocketStreammaxIncomingMessageSize (long size)
 Set a limit for the maximum incoming message size
 
WebSocketStreamonPingReceived (Function< void()> &&f)
 Set a callback handler f to be invoked whenever a ping frame is received
 
WebSocketStreamonPongReceived (Function< void()> &&f)
 Set a callback handler f to be invoked whenever a pong frame is received
 
bool read (Out< String > message, Out< WebSocketMessage::Type > type=None{})
 Receive a message.
 
bool write (const String &message, WebSocketMessage::Type type=WebSocketMessage::Type::Text, uint32_t mask=0)
 Send a message.
 
bool write (const Bytes &message, WebSocketMessage::Type type=WebSocketMessage::Type::Binary, uint32_t mask=0)
 Send a message.
 
bool isOpen () const
 Tell if this WebSocket connection is still open.
 
bool close (WebSocketStatus status)
 Close this WebSocket connection.
 
WebSocketStatus status () const
 Status of this WebSocket connection
 
bool ping ()
 Send a ping frame.
 
bool pong ()
 Send an unsolicited pong frame.
 
- Public Member Functions inherited from Object
 Object ()=default
 Create a null object.
 
 operator bool () const
 Check if this is a non-null object.
 
bool isNull () const
 Check if this is a null object.
 
int useCount () const
 Reference count.
 
template<class T >
bool is () const
 Check if this object is of type T.
 
template<class T >
as () const
 Cast this object to type T.
 
bool isWeak () const
 Check if the underlying object reference is weak.
 
bool operator== (const Object &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Object &other) const
 Ordering operator.
 

Additional Inherited Members

- Protected Member Functions inherited from Object
template<class T >
weak () const
 
template<class T >
void initOnce ()
 Create the object state when called the first time.
 
template<class T >
void initOncePerThread ()
 Create a distinct object state for each thread when called the first time in that thread.
 
 Object (State *newState)
 Initialize object with newState.
 
 Object (State *state, Alias)
 
 Object (State *state, Weak)
 
Objectoperator= (std::nullptr_t)
 
- Static Protected Member Functions inherited from Object
template<class T >
static T alias (const State *state)
 Create an alias object for the given state.
 
template<class T >
static T weak (const State *state)
 
- Protected Attributes inherited from Object
Handle< Stateme
 Internal object state
 

Detailed Description

WebSocket message stream.

Todo:

add a waitUntil();

add configuration option and logic for websocket keep alive interval (two misses result in connection termination)

make sure WebSocket connections are brought down cleanly on server shutdown

Member Enumeration Documentation

◆ Type

enum Type

Communication direction.

Enumerator
ServerToClient 

This WebSocketStream is used by the server.

ClientToServer 

This WebSocketStream is used by the client.

Constructor & Destructor Documentation

◆ WebSocketStream() [1/2]

WebSocketStream ( )
default

Create a null object.

◆ WebSocketStream() [2/2]

WebSocketStream ( const Stream stream,
Type  type 
)
explicit

Create a new frame stream.

Member Function Documentation

◆ maxOutgoingFramePayloadSize()

WebSocketStream & maxOutgoingFramePayloadSize ( long  size)

Set the maximum frame payload size

◆ maxIncomingMessageSize()

WebSocketStream & maxIncomingMessageSize ( long  size)

Set a limit for the maximum incoming message size

◆ onPingReceived()

WebSocketStream & onPingReceived ( Function< void()> &&  f)

Set a callback handler f to be invoked whenever a ping frame is received

◆ onPongReceived()

WebSocketStream & onPongReceived ( Function< void()> &&  f)

Set a callback handler f to be invoked whenever a pong frame is received

◆ read()

bool read ( Out< String message,
Out< WebSocketMessage::Type type = None{} 
)

Receive a message.

◆ write() [1/2]

bool write ( const String message,
WebSocketMessage::Type  type = WebSocketMessage::Type::Text,
uint32_t  mask = 0 
)

Send a message.

◆ write() [2/2]

bool write ( const Bytes message,
WebSocketMessage::Type  type = WebSocketMessage::Type::Binary,
uint32_t  mask = 0 
)

Send a message.

◆ isOpen()

bool isOpen ( ) const

Tell if this WebSocket connection is still open.

◆ close()

bool close ( WebSocketStatus  status)

Close this WebSocket connection.

◆ status()

WebSocketStatus status ( ) const

Status of this WebSocket connection

◆ ping()

bool ping ( )

Send a ping frame.

◆ pong()

bool pong ( )

Send an unsolicited pong frame.