Kurlyk
Loading...
Searching...
No Matches
kurlyk::BaseWebSocketClient Class Referenceabstract

Base class implementing core functionality for WebSocket clients, managing events, states, and message sending. More...

#include <BaseWebSocketClient.hpp>

Inheritance diagram for kurlyk::BaseWebSocketClient:
kurlyk::IWebSocketClient kurlyk::IWebSocketSender kurlyk::SimpleWebSocketClientAdapter

Classes

struct  FSMEventData
 Represents an event in the finite state machine (FSM) with optional associated data and callback. More...

Public Member Functions

 BaseWebSocketClient ()=default
 Default constructor.
virtual ~BaseWebSocketClient ()=default
 Virtual destructor.
std::function< void(std::unique_ptr< WebSocketEventData >)> & event_handler () override final
 Accessor for the event handler function.
std::function< void()> & notify_handler () override final
 Accesses the notification handler for WebSocket events.
void set_config (std::unique_ptr< WebSocketConfig > config, std::function< void(bool)> callback) override final
 Sets the configuration for the WebSocket client.
void connect (std::function< void(bool)> callback) override final
 Initiates a connection to the WebSocket server.
void disconnect (std::function< void(bool)> callback) override final
 Closes the connection to the WebSocket server.
bool is_connected () const override final
 Checks if the WebSocket client is actively running.
bool is_running () const override final
 Checks if the WebSocket client is actively running.
std::list< std::unique_ptr< WebSocketEventData > > receive_events () const override final
 Retrieves all pending WebSocket events in a batch.
std::unique_ptr< WebSocketEventDatareceive_event () const override final
 Retrieves the next available WebSocket event, if any.
SubmitResult submit_message (const std::string &message, long rate_limit_id, std::function< void(const std::error_code &ec)> callback=nullptr) override final
 Attempts to submit a message through the WebSocket.
bool send_message (const std::string &message, long rate_limit_id, std::function< void(const std::error_code &ec)> callback=nullptr) override final
 Sends a message through the WebSocket.
SubmitResult submit_close (const int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &ec)> callback=nullptr) override final
 Attempts to submit a close request through the WebSocket.
bool send_close (const int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &ec)> callback=nullptr) override final
 Sends a close request through the WebSocket.
void process () override final
 Processes internal operations such as event handling and state updates.
void shutdown () override final
 Shuts down the WebSocket client, disconnecting and clearing all pending events.
Public Member Functions inherited from kurlyk::IWebSocketClient
 IWebSocketClient ()=default
 Default constructor.
virtual ~IWebSocketClient ()=default
 Virtual destructor for safe cleanup in derived classes.
Public Member Functions inherited from kurlyk::IWebSocketSender
 IWebSocketSender ()=default
 Default constructor for IWebSocketSender.
virtual ~IWebSocketSender ()=default
 Virtual destructor for safe cleanup through the sender abstraction.
virtual std::string get_http_version ()=0
 Retrieves the HTTP version used in the WebSocket connection.
virtual Headers get_headers ()=0
 Retrieves the headers associated with the WebSocket connection.
virtual std::string get_remote_endpoint ()=0
 Retrieves the remote endpoint information.
virtual bool send_message (const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)=0
 Sends a WebSocket message.
virtual SubmitResult submit_message (const std::string &message, long rate_limit_id=0, std::function< void(const std::error_code &)> callback=nullptr)
 Attempts to submit a WebSocket message and reports the admission result.
virtual bool send_close (int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)=0
 Sends a close request to the WebSocket server.
virtual SubmitResult submit_close (int status=1000, const std::string &reason=std::string(), std::function< void(const std::error_code &)> callback=nullptr)
 Attempts to submit a close request and reports the admission result.

Protected Types

enum class  FsmState {
  INIT , CONNECTING , WORKING , RECONNECTING ,
  STOPPED
}
 Finite State Machine (FSM) states for the WebSocket connection. More...
enum class  FsmEvent {
  RequestConnect , RequestDisconnect , ConnectionOpened , ConnectionClosed ,
  ConnectionError , MessageReceived , UpdateConfig
}
 Represents events in the finite state machine. More...

Protected Member Functions

virtual bool init_websocket ()=0
 Initializes the WebSocket connection. Must be implemented in derived classes.
virtual void deinit_websocket ()=0
 Deinitializes the WebSocket connection. Must be implemented in derived classes.
virtual void send_message (std::shared_ptr< WebSocketSendInfo > &send_info)=0
 Sends a WebSocket message.
virtual void send_close (std::shared_ptr< WebSocketSendInfo > &send_info)=0
 Sends a close request.
std::unique_ptr< WebSocketEventDatacreate_websocket_event ()
 Creates a generic WebSocket event.
std::unique_ptr< WebSocketEventDatacreate_websocket_close_event (const std::string &reason="Normal Closure", int status_code=1000)
 Creates a WebSocket close event with a specified reason and status code.
std::unique_ptr< WebSocketEventDatacreate_websocket_error_event (const std::error_code &error_code)
 Creates a WebSocket error event with a specified error code.
void add_send_callback (const std::error_code &error_code, const std::function< void(const std::error_code &ec)> &callback)
 Adds a send callback to the queue.
void add_fsm_event (FsmEvent event_type, std::unique_ptr< WebSocketEventData > event_data)
 Adds an FSM event to the event queue and triggers the notify handler.

Protected Attributes

std::unique_ptr< WebSocketConfigm_config
 Current configuration for the WebSocket.
enum kurlyk::BaseWebSocketClient::FsmState m_fsm_state = FsmState::INIT

Private Types

using event_data_ptr_t = std::unique_ptr<WebSocketEventData>
 Alias for unique pointers to WebSocketEventData.
using send_info_ptr_t = std::shared_ptr<WebSocketSendInfo>
 Alias for shared pointers to WebSocketSendInfo.
using send_callback_t = std::pair<std::error_code, std::function<void(const std::error_code& ec)>>
 Alias for callback pairs with error codes.

Private Member Functions

void process_fsm_state ()
 Processes the current FSM state and transitions to the appropriate next state.
void process_state_init ()
 Handles the INIT state. Initializes connection or updates configuration.
void process_state_connecting ()
 Handles the CONNECTING state. Manages connection attempt, errors, or disconnection.
void process_state_working ()
 Handles the WORKING state. Processes incoming events and manages connection health.
void process_state_reconnecting ()
 Handles the RECONNECTING state. Attempts to reconnect based on configuration settings.
void process_state_stopped ()
 Processes the STOPPED state in the FSM.
void process_message_queue ()
 Processes the queue of messages to be sent over the WebSocket.
void process_send_callback_queue ()
 Processes the queue of send callbacks.
void handle_open_event (std::unique_ptr< WebSocketEventData > event)
 Handles the event when the WebSocket connection is opened.
void handle_close_event (std::unique_ptr< WebSocketEventData > event=nullptr)
 Handles the event when the WebSocket connection is closed.
void handle_error_event (std::unique_ptr< WebSocketEventData > event)
 Handles WebSocket error events and queues them if no event handler is set.
void handle_error_event (const std::error_code &error_code)
 Overloaded method to handle WebSocket error events using an error code.
void handle_message_event (std::unique_ptr< WebSocketEventData > event)
 Handles incoming WebSocket message events and queues them if no event handler is set.

Private Attributes

std::function< void(std::unique_ptr< WebSocketEventData >)> m_on_event
 Function to handle WebSocket events. Called when a new event is received.
std::function< void()> m_on_event_notify
 Function to notify about new events in the FSM.
utils::EventQueue< FSMEventDatam_fsm_event_queue
 Queue for FSM events, managing the event sequence for the FSM.
long m_reconnect_attempt = 0
 Counter for the number of reconnection attempts.
std::atomic< bool > m_is_running = ATOMIC_VAR_INIT(false)
 Atomic flag indicating if the client is running.
std::atomic< bool > m_is_connected = ATOMIC_VAR_INIT(false)
 Atomic flag indicating if the client is connected.
std::atomic< std::size_t > m_max_send_queue_size = ATOMIC_VAR_INIT(0)
 Maximum number of queued outbound send operations, or zero if unbounded.
WebSocketRateLimiter m_rate_limiter
 Rate limiter for controlling the frequency of message sending.
std::chrono::steady_clock::time_point m_close_time
 Timestamp of the last WebSocket close event, used for reconnection timing.
std::mutex m_event_queue_mutex
 Mutex for synchronizing access to the event queue.
std::list< event_data_ptr_tm_event_queue
 Queue holding pending WebSocket events.
std::mutex m_message_queue_mutex
 Mutex for synchronizing access to the message queue.
std::list< send_info_ptr_tm_message_queue
 Queue holding messages to be sent over the WebSocket.
std::mutex m_send_callback_queue_mutex
 Mutex for synchronizing access to the send callback queue.
std::list< send_callback_tm_send_callback_queue
 Queue holding send callbacks with their respective error codes.

Detailed Description

Base class implementing core functionality for WebSocket clients, managing events, states, and message sending.

Definition at line 17 of file BaseWebSocketClient.hpp.

Member Typedef Documentation

◆ event_data_ptr_t

Alias for unique pointers to WebSocketEventData.

Definition at line 385 of file BaseWebSocketClient.hpp.

◆ send_callback_t

using kurlyk::BaseWebSocketClient::send_callback_t = std::pair<std::error_code, std::function<void(const std::error_code& ec)>>
private

Alias for callback pairs with error codes.

Definition at line 393 of file BaseWebSocketClient.hpp.

◆ send_info_ptr_t

Alias for shared pointers to WebSocketSendInfo.

Definition at line 389 of file BaseWebSocketClient.hpp.

Member Enumeration Documentation

◆ FsmEvent

enum class kurlyk::BaseWebSocketClient::FsmEvent
strongprotected

Represents events in the finite state machine.

Enumerator
RequestConnect 

Request to connect.

RequestDisconnect 

Request to disconnect.

ConnectionOpened 

Connection opened successfully.

ConnectionClosed 

Connection closed.

ConnectionError 

Error in connection.

MessageReceived 

Incoming WebSocket message.

UpdateConfig 

Update configuration.

Definition at line 209 of file BaseWebSocketClient.hpp.

◆ FsmState

enum class kurlyk::BaseWebSocketClient::FsmState
strongprotected

Finite State Machine (FSM) states for the WebSocket connection.

Enumerator
INIT 

Initialization state.

CONNECTING 

Awaiting connection.

WORKING 

Connection active and working.

RECONNECTING 

Reconnection attempt.

STOPPED 

Stopped state.

Definition at line 200 of file BaseWebSocketClient.hpp.

Constructor & Destructor Documentation

◆ BaseWebSocketClient()

kurlyk::BaseWebSocketClient::BaseWebSocketClient ( )
default

Default constructor.

◆ ~BaseWebSocketClient()

virtual kurlyk::BaseWebSocketClient::~BaseWebSocketClient ( )
virtualdefault

Virtual destructor.

Member Function Documentation

◆ add_fsm_event()

void kurlyk::BaseWebSocketClient::add_fsm_event ( FsmEvent event_type,
std::unique_ptr< WebSocketEventData > event_data )
inlineprotected

Adds an FSM event to the event queue and triggers the notify handler.

Parameters
event_typeThe event type to be pushed.
event_dataThe event data to be associated with the event.

Definition at line 288 of file BaseWebSocketClient.hpp.

◆ add_send_callback()

void kurlyk::BaseWebSocketClient::add_send_callback ( const std::error_code & error_code,
const std::function< void(const std::error_code &ec)> & callback )
inlineprotected

Adds a send callback to the queue.

Parameters
error_codeThe error code returned after the send operation.
callbackThe callback function to be called with the error code.

Definition at line 278 of file BaseWebSocketClient.hpp.

◆ connect()

void kurlyk::BaseWebSocketClient::connect ( std::function< void(bool)> callback)
inlinefinaloverridevirtual

Initiates a connection to the WebSocket server.

Parameters
callbackCallback function to be executed upon connection completion, receiving a success status.

Implements kurlyk::IWebSocketClient.

Definition at line 52 of file BaseWebSocketClient.hpp.

◆ create_websocket_close_event()

std::unique_ptr< WebSocketEventData > kurlyk::BaseWebSocketClient::create_websocket_close_event ( const std::string & reason = "Normal Closure",
int status_code = 1000 )
inlineprotected

Creates a WebSocket close event with a specified reason and status code.

This method generates a WebSocket close event, setting the event type to "Close" and including an optional reason and status code.

Parameters
reasonThe reason for the closure. Defaults to "Normal Closure."
status_codeThe status code associated with the closure. Defaults to 1000 (normal closure).
Returns
Unique pointer to a WebSocketEventData representing the close event.

Definition at line 252 of file BaseWebSocketClient.hpp.

◆ create_websocket_error_event()

std::unique_ptr< WebSocketEventData > kurlyk::BaseWebSocketClient::create_websocket_error_event ( const std::error_code & error_code)
inlineprotected

Creates a WebSocket error event with a specified error code.

This method generates a WebSocket error event, setting the event type to "Error" and associating it with the provided error code.

Parameters
error_codeThe error code representing the nature of the error.
Returns
Unique pointer to a WebSocketEventData representing the error event.

Definition at line 267 of file BaseWebSocketClient.hpp.

◆ create_websocket_event()

std::unique_ptr< WebSocketEventData > kurlyk::BaseWebSocketClient::create_websocket_event ( )
inlineprotected

Creates a generic WebSocket event.

Returns
Unique pointer to the created WebSocketEventData.

Definition at line 236 of file BaseWebSocketClient.hpp.

◆ deinit_websocket()

virtual void kurlyk::BaseWebSocketClient::deinit_websocket ( )
protectedpure virtual

Deinitializes the WebSocket connection. Must be implemented in derived classes.

Implemented in kurlyk::SimpleWebSocketClientAdapter.

◆ disconnect()

void kurlyk::BaseWebSocketClient::disconnect ( std::function< void(bool)> callback)
inlinefinaloverridevirtual

Closes the connection to the WebSocket server.

Parameters
callbackCallback function to be executed upon disconnection completion, receiving a success status.

Implements kurlyk::IWebSocketClient.

Definition at line 58 of file BaseWebSocketClient.hpp.

◆ event_handler()

std::function< void(std::unique_ptr< WebSocketEventData >)> & kurlyk::BaseWebSocketClient::event_handler ( )
inlinefinaloverridevirtual

Accessor for the event handler function.

This method provides access to the event handler function used for handling WebSocket events. The returned reference allows getting or setting the function that will be called when a WebSocket event occurs.

Returns
A reference to a std::function<void(std::unique_ptr<WebSocketEventData>)> representing the event handler function.

Implements kurlyk::IWebSocketClient.

Definition at line 30 of file BaseWebSocketClient.hpp.

◆ handle_close_event()

void kurlyk::BaseWebSocketClient::handle_close_event ( std::unique_ptr< WebSocketEventData > event = nullptr)
inlineprivate

Handles the event when the WebSocket connection is closed.

Sets the connection state to disconnected and triggers the event handler, if set. Otherwise, stores the event in the event queue. Generates a close event if none is provided.

Parameters
eventUnique pointer to the WebSocket close event data. Defaults to nullptr.

Definition at line 797 of file BaseWebSocketClient.hpp.

◆ handle_error_event() [1/2]

void kurlyk::BaseWebSocketClient::handle_error_event ( const std::error_code & error_code)
inlineprivate

Overloaded method to handle WebSocket error events using an error code.

Parameters
error_codeThe error code representing the WebSocket error.

Definition at line 826 of file BaseWebSocketClient.hpp.

◆ handle_error_event() [2/2]

void kurlyk::BaseWebSocketClient::handle_error_event ( std::unique_ptr< WebSocketEventData > event)
inlineprivate

Handles WebSocket error events and queues them if no event handler is set.

If an event handler exists, it directly processes the error event.

Parameters
eventUnique pointer to the WebSocket error event data.

Definition at line 815 of file BaseWebSocketClient.hpp.

◆ handle_message_event()

void kurlyk::BaseWebSocketClient::handle_message_event ( std::unique_ptr< WebSocketEventData > event)
inlineprivate

Handles incoming WebSocket message events and queues them if no event handler is set.

If an event handler exists, it directly processes the message event.

Parameters
eventUnique pointer to the WebSocket message event data.

Definition at line 833 of file BaseWebSocketClient.hpp.

◆ handle_open_event()

void kurlyk::BaseWebSocketClient::handle_open_event ( std::unique_ptr< WebSocketEventData > event)
inlineprivate

Handles the event when the WebSocket connection is opened.

Sets the connection state to connected and triggers the event handler, if set. Otherwise, stores the event in the event queue.

Parameters
eventUnique pointer to the WebSocket open event data.

Definition at line 781 of file BaseWebSocketClient.hpp.

◆ init_websocket()

virtual bool kurlyk::BaseWebSocketClient::init_websocket ( )
protectedpure virtual

Initializes the WebSocket connection. Must be implemented in derived classes.

Implemented in kurlyk::SimpleWebSocketClientAdapter.

◆ is_connected()

bool kurlyk::BaseWebSocketClient::is_connected ( ) const
inlinefinaloverridevirtual

Checks if the WebSocket client is actively running.

Returns
True if the client is running, otherwise false.

Implements kurlyk::IWebSocketSender.

Definition at line 64 of file BaseWebSocketClient.hpp.

◆ is_running()

bool kurlyk::BaseWebSocketClient::is_running ( ) const
inlinefinaloverridevirtual

Checks if the WebSocket client is actively running.

Returns
True if the client is running, false otherwise.

Implements kurlyk::IWebSocketClient.

Definition at line 70 of file BaseWebSocketClient.hpp.

◆ notify_handler()

std::function< void()> & kurlyk::BaseWebSocketClient::notify_handler ( )
inlinefinaloverridevirtual

Accesses the notification handler for WebSocket events.

The notification handler triggers the network worker to process WebSocket events by notifying it that an event has occurred, typically through NetworkWorker::get_instance().notify().

Returns
A reference to the notification handler callback function.

Implements kurlyk::IWebSocketClient.

Definition at line 39 of file BaseWebSocketClient.hpp.

◆ process()

void kurlyk::BaseWebSocketClient::process ( )
inlinefinaloverridevirtual

Processes internal operations such as event handling and state updates.

This function should be called periodically to ensure timely processing of internal state changes, events, and messages.

Implements kurlyk::IWebSocketClient.

Definition at line 179 of file BaseWebSocketClient.hpp.

◆ process_fsm_state()

void kurlyk::BaseWebSocketClient::process_fsm_state ( )
inlineprivate

Processes the current FSM state and transitions to the appropriate next state.

Definition at line 397 of file BaseWebSocketClient.hpp.

◆ process_message_queue()

void kurlyk::BaseWebSocketClient::process_message_queue ( )
inlineprivate

Processes the queue of messages to be sent over the WebSocket.

Filters the message queue according to the rate limiter. Messages allowed by the rate limiter are transferred to a temporary list and sent sequentially. Close requests are sent immediately.

Definition at line 735 of file BaseWebSocketClient.hpp.

◆ process_send_callback_queue()

void kurlyk::BaseWebSocketClient::process_send_callback_queue ( )
inlineprivate

Processes the queue of send callbacks.

For each callback in the queue, it calls the callback function with the associated error code. This method is typically called after a message has been sent or an error has occurred.

Definition at line 766 of file BaseWebSocketClient.hpp.

◆ process_state_connecting()

void kurlyk::BaseWebSocketClient::process_state_connecting ( )
inlineprivate

Handles the CONNECTING state. Manages connection attempt, errors, or disconnection.

Definition at line 457 of file BaseWebSocketClient.hpp.

◆ process_state_init()

void kurlyk::BaseWebSocketClient::process_state_init ( )
inlineprivate

Handles the INIT state. Initializes connection or updates configuration.

Definition at line 418 of file BaseWebSocketClient.hpp.

◆ process_state_reconnecting()

void kurlyk::BaseWebSocketClient::process_state_reconnecting ( )
inlineprivate

Handles the RECONNECTING state. Attempts to reconnect based on configuration settings.

Definition at line 607 of file BaseWebSocketClient.hpp.

◆ process_state_stopped()

void kurlyk::BaseWebSocketClient::process_state_stopped ( )
inlineprivate

Processes the STOPPED state in the FSM.

Definition at line 681 of file BaseWebSocketClient.hpp.

◆ process_state_working()

void kurlyk::BaseWebSocketClient::process_state_working ( )
inlineprivate

Handles the WORKING state. Processes incoming events and manages connection health.

Definition at line 532 of file BaseWebSocketClient.hpp.

◆ receive_event()

std::unique_ptr< WebSocketEventData > kurlyk::BaseWebSocketClient::receive_event ( ) const
inlinefinaloverridevirtual

Retrieves the next available WebSocket event, if any.

This method supports event-by-event processing by returning the next event in the queue.

Returns
A unique pointer to a WebSocketEventData object representing an event, or nullptr if no events are available.

Implements kurlyk::IWebSocketClient.

Definition at line 89 of file BaseWebSocketClient.hpp.

◆ receive_events()

std::list< std::unique_ptr< WebSocketEventData > > kurlyk::BaseWebSocketClient::receive_events ( ) const
inlinefinaloverridevirtual

Retrieves all pending WebSocket events in a batch.

This method enables efficient processing of multiple accumulated events at once.

Returns
A list of unique pointers to WebSocketEventData objects representing the events.

Implements kurlyk::IWebSocketClient.

Definition at line 78 of file BaseWebSocketClient.hpp.

◆ send_close() [1/2]

bool kurlyk::BaseWebSocketClient::send_close ( const int status = 1000,
const std::string & reason = std::string(),
std::function< void(const std::error_code &ec)> callback = nullptr )
inlinefinaloverride

Sends a close request through the WebSocket.

Parameters
statusThe status code to send with the close request.
reasonThe reason for closing the connection.
callbackThe callback to be invoked after sending.
Returns
True if the close request was successfully queued, false otherwise.

Definition at line 167 of file BaseWebSocketClient.hpp.

◆ send_close() [2/2]

virtual void kurlyk::BaseWebSocketClient::send_close ( std::shared_ptr< WebSocketSendInfo > & send_info)
protectedpure virtual

Sends a close request.

Parameters
send_infoReference to WebSocketSendInfo containing close details.

Implemented in kurlyk::SimpleWebSocketClientAdapter.

◆ send_message() [1/2]

bool kurlyk::BaseWebSocketClient::send_message ( const std::string & message,
long rate_limit_id,
std::function< void(const std::error_code &ec)> callback = nullptr )
inlinefinaloverride

Sends a message through the WebSocket.

Parameters
messageThe message to send.
rate_limit_idThe rate limit type to apply.
callbackThe callback to be invoked after sending.
Returns
True if the message was successfully queued, false otherwise.

Definition at line 130 of file BaseWebSocketClient.hpp.

◆ send_message() [2/2]

virtual void kurlyk::BaseWebSocketClient::send_message ( std::shared_ptr< WebSocketSendInfo > & send_info)
protectedpure virtual

Sends a WebSocket message.

Parameters
send_infoReference to WebSocketSendInfo containing message details.

Implemented in kurlyk::SimpleWebSocketClientAdapter.

◆ set_config()

void kurlyk::BaseWebSocketClient::set_config ( std::unique_ptr< WebSocketConfig > config,
std::function< void(bool)> callback )
inlinefinaloverridevirtual

Sets the configuration for the WebSocket client.

Parameters
configA unique pointer to the WebSocket configuration object.
callbackCallback function to be executed upon configuration completion.

Implements kurlyk::IWebSocketClient.

Definition at line 46 of file BaseWebSocketClient.hpp.

◆ shutdown()

void kurlyk::BaseWebSocketClient::shutdown ( )
inlinefinaloverridevirtual

Shuts down the WebSocket client, disconnecting and clearing all pending events.

Initiates a disconnect event and processes any remaining events until the client stops running.

Implements kurlyk::IWebSocketClient.

Definition at line 187 of file BaseWebSocketClient.hpp.

◆ submit_close()

SubmitResult kurlyk::BaseWebSocketClient::submit_close ( const int status = 1000,
const std::string & reason = std::string(),
std::function< void(const std::error_code &ec)> callback = nullptr )
inlinefinaloverride

Attempts to submit a close request through the WebSocket.

Parameters
statusThe status code to send with the close request.
reasonThe reason for closing the connection.
callbackThe callback to be invoked after sending.
Returns
SubmitResult describing whether the close request was successfully queued.

Definition at line 142 of file BaseWebSocketClient.hpp.

◆ submit_message()

SubmitResult kurlyk::BaseWebSocketClient::submit_message ( const std::string & message,
long rate_limit_id,
std::function< void(const std::error_code &ec)> callback = nullptr )
inlinefinaloverride

Attempts to submit a message through the WebSocket.

Parameters
messageThe message to send.
rate_limit_idThe rate limit type to apply.
callbackThe callback to be invoked after sending.
Returns
SubmitResult describing whether the message was successfully queued.

Definition at line 102 of file BaseWebSocketClient.hpp.

Member Data Documentation

◆ m_close_time

std::chrono::steady_clock::time_point kurlyk::BaseWebSocketClient::m_close_time
private

Timestamp of the last WebSocket close event, used for reconnection timing.

Definition at line 382 of file BaseWebSocketClient.hpp.

◆ m_config

std::unique_ptr<WebSocketConfig> kurlyk::BaseWebSocketClient::m_config
protected

Current configuration for the WebSocket.

Definition at line 197 of file BaseWebSocketClient.hpp.

◆ m_event_queue

std::list<event_data_ptr_t> kurlyk::BaseWebSocketClient::m_event_queue
mutableprivate

Queue holding pending WebSocket events.

Definition at line 386 of file BaseWebSocketClient.hpp.

◆ m_event_queue_mutex

std::mutex kurlyk::BaseWebSocketClient::m_event_queue_mutex
mutableprivate

Mutex for synchronizing access to the event queue.

Definition at line 384 of file BaseWebSocketClient.hpp.

◆ m_fsm_event_queue

utils::EventQueue<FSMEventData> kurlyk::BaseWebSocketClient::m_fsm_event_queue
private

Queue for FSM events, managing the event sequence for the FSM.

Definition at line 375 of file BaseWebSocketClient.hpp.

◆ m_fsm_state

enum kurlyk::BaseWebSocketClient::FsmState kurlyk::BaseWebSocketClient::m_fsm_state = FsmState::INIT
protected

◆ m_is_connected

std::atomic<bool> kurlyk::BaseWebSocketClient::m_is_connected = ATOMIC_VAR_INIT(false)
private

Atomic flag indicating if the client is connected.

Definition at line 378 of file BaseWebSocketClient.hpp.

◆ m_is_running

std::atomic<bool> kurlyk::BaseWebSocketClient::m_is_running = ATOMIC_VAR_INIT(false)
private

Atomic flag indicating if the client is running.

Definition at line 377 of file BaseWebSocketClient.hpp.

◆ m_max_send_queue_size

std::atomic<std::size_t> kurlyk::BaseWebSocketClient::m_max_send_queue_size = ATOMIC_VAR_INIT(0)
private

Maximum number of queued outbound send operations, or zero if unbounded.

Definition at line 379 of file BaseWebSocketClient.hpp.

◆ m_message_queue

std::list<send_info_ptr_t> kurlyk::BaseWebSocketClient::m_message_queue
private

Queue holding messages to be sent over the WebSocket.

Definition at line 390 of file BaseWebSocketClient.hpp.

◆ m_message_queue_mutex

std::mutex kurlyk::BaseWebSocketClient::m_message_queue_mutex
private

Mutex for synchronizing access to the message queue.

Definition at line 388 of file BaseWebSocketClient.hpp.

◆ m_on_event

std::function<void(std::unique_ptr<WebSocketEventData>)> kurlyk::BaseWebSocketClient::m_on_event
private

Function to handle WebSocket events. Called when a new event is received.

Definition at line 295 of file BaseWebSocketClient.hpp.

◆ m_on_event_notify

std::function<void()> kurlyk::BaseWebSocketClient::m_on_event_notify
private

Function to notify about new events in the FSM.

Definition at line 296 of file BaseWebSocketClient.hpp.

◆ m_rate_limiter

WebSocketRateLimiter kurlyk::BaseWebSocketClient::m_rate_limiter
private

Rate limiter for controlling the frequency of message sending.

Definition at line 381 of file BaseWebSocketClient.hpp.

◆ m_reconnect_attempt

long kurlyk::BaseWebSocketClient::m_reconnect_attempt = 0
private

Counter for the number of reconnection attempts.

Definition at line 376 of file BaseWebSocketClient.hpp.

◆ m_send_callback_queue

std::list<send_callback_t> kurlyk::BaseWebSocketClient::m_send_callback_queue
private

Queue holding send callbacks with their respective error codes.

Definition at line 394 of file BaseWebSocketClient.hpp.

◆ m_send_callback_queue_mutex

std::mutex kurlyk::BaseWebSocketClient::m_send_callback_queue_mutex
private

Mutex for synchronizing access to the send callback queue.

Definition at line 392 of file BaseWebSocketClient.hpp.


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