RESTinio
|
Context for handling websocket connections. More...
#include <ws_connection.hpp>
Classes | |
class | one_shot_action_t |
A helper class for running exclusive action. Only a first action will run. More... | |
Public Types | |
using | message_handler_t = WS_Message_Handler |
using | timer_manager_t = typename Traits::timer_manager_t |
using | timer_manager_handle_t = std::shared_ptr< timer_manager_t > |
using | timer_guard_t = typename timer_manager_t::timer_guard_t |
using | logger_t = typename Traits::logger_t |
using | strand_t = typename Traits::strand_t |
using | stream_socket_t = typename Traits::stream_socket_t |
using | lifetime_monitor_t = typename connection_count_limit_types< Traits >::lifetime_monitor_t |
using | ws_weak_handle_t = std::weak_ptr< ws_t > |
Public Member Functions | |
ws_connection_t (const ws_connection_t &)=delete | |
ws_connection_t (ws_connection_t &&)=delete | |
ws_connection_t & | operator= (const ws_connection_t &)=delete |
ws_connection_t & | operator= (ws_connection_t &&)=delete |
~ws_connection_t () override | |
virtual void | shutdown () override |
Shutdown websocket. More... | |
virtual void | kill () override |
Kill websocket. More... | |
void | init_read (ws_handle_t wsh) override |
Start reading ws-messages. More... | |
virtual void | write_data (write_group_t wg, bool is_close_frame) override |
Write pieces of outgoing data. More... | |
![]() | |
ws_connection_base_t (connection_id_t id) | |
virtual void | shutdown ()=0 |
Shutdown websocket. More... | |
virtual void | kill ()=0 |
Kill websocket. More... | |
virtual void | init_read (ws_handle_t wsh)=0 |
Start reading ws-messages. More... | |
virtual void | write_data (write_group_t wg, bool is_close_frame)=0 |
Write pieces of outgoing data. More... | |
![]() | |
tcp_connection_ctx_base_t (connection_id_t id) | |
virtual | ~tcp_connection_ctx_base_t ()=default |
connection_id_t | connection_id () const noexcept |
Get connection id. More... | |
virtual void | check_timeout (std::shared_ptr< tcp_connection_ctx_base_t > &self)=0 |
Check timeouts for all activities. More... | |
![]() | |
executor_wrapper_t (Init_Executor &&init_executor) | |
virtual | ~executor_wrapper_t ()=default |
Traits::strand_t & | get_executor () noexcept |
An executor for callbacks on async operations. More... | |
Private Types | |
enum class | write_state_t { write_enabled , write_disabled } |
Websocket output states. More... | |
enum class | read_state_t { read_any_frame , read_only_close_frame , read_nothing } |
Websocket input states. More... | |
using | executor_wrapper_base_t = restinio::impl::executor_wrapper_t< typename Traits::strand_t > |
using | none_write_operation_t = ::restinio::impl::write_group_output_ctx_t::none_write_operation_t |
using | trivial_write_operation_t = ::restinio::impl::write_group_output_ctx_t::trivial_write_operation_t |
using | file_write_operation_t = ::restinio::impl::write_group_output_ctx_t::file_write_operation_t |
Private Member Functions | |
void | close_impl () noexcept |
Standard close routine. More... | |
void | start_waiting_close_frame_only () |
Start waiting for close-frame. More... | |
void | graceful_close () |
Close WebSocket connection in a graceful manner. More... | |
void | send_close_frame_to_peer (std::string payload) |
Send close frame to peer. More... | |
void | send_close_frame_to_peer (status_code_t code, std::string desc=std::string{}) |
Send close frame to peer. More... | |
template<typename MSG_BUILDER > | |
void | trigger_error_and_close (status_code_t status, MSG_BUILDER msg_builder) noexcept |
Trigger an error. More... | |
void | start_read_header () |
Start the process of reading ws messages from socket. More... | |
void | consume_header_from_socket () |
Initiate read operation on socket to receive bytes for header. More... | |
void | handle_read_error (const char *desc, const asio_ns::error_code &ec) |
Handle read error (reading header or payload) More... | |
void | after_read_header (const asio_ns::error_code &ec, std::size_t length) |
Handle read operation result, when reading header. More... | |
void | consume_header_from_buffer (const char *data, std::size_t length) |
Parse header from internal buffer. More... | |
void | handle_parsed_header (const message_details_t &md) |
Handle parsed header. More... | |
void | handle_parsed_and_valid_header (const message_details_t &md) |
Handle parsed and valid header. More... | |
void | start_read_payload (char *payload_data, std::size_t length_remaining, bool do_validate_payload_and_call_msg_handler=true) |
Start reading message payload. More... | |
void | after_read_payload (char *payload_data, std::size_t length_remaining, const asio_ns::error_code &ec, std::size_t length, bool do_validate_payload_and_call_msg_handler=true) |
Handle read operation result, when reading payload. More... | |
void | call_message_handler (message_handle_t close_frame) |
Call user message handler with current message. More... | |
bool | validate_payload_part (char *payload_data, std::size_t length, std::size_t next_length_remaining) |
Validates a part of received payload. More... | |
void | handle_invalid_payload (validation_state_t validation_result) |
Handle payload errors. More... | |
void | call_handler_on_current_message () |
void | call_close_handler_if_necessary (status_code_t status) |
void | write_data_impl (write_group_t wg, bool is_close_frame) |
Implementation of writing data performed on the asio_ns::io_context. More... | |
void | init_write_if_necessary () |
Checks if there is something to write, and if so starts write operation. More... | |
void | init_write () |
Initiate write operation. More... | |
void | handle_current_write_ctx () |
void | handle_trivial_write_operation (const trivial_write_operation_t &op) |
void | finish_handling_current_write_ctx () |
Do post write actions for current write group. More... | |
void | after_write (const asio_ns::error_code &ec) |
Handle write response finished. More... | |
Additional Inherited Members | |
![]() | |
template<typename Derived > | |
std::shared_ptr< Derived > | shared_from_concrete () |
Cast self to derived class. More... | |
Context for handling websocket connections.
Definition at line 122 of file ws_connection.hpp.
|
private |
Definition at line 126 of file ws_connection.hpp.
|
private |
Definition at line 1103 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::lifetime_monitor_t = typename connection_count_limit_types<Traits>::lifetime_monitor_t |
Definition at line 137 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::logger_t = typename Traits::logger_t |
Definition at line 134 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::message_handler_t = WS_Message_Handler |
Definition at line 129 of file ws_connection.hpp.
|
private |
Definition at line 1101 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::strand_t = typename Traits::strand_t |
Definition at line 135 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::stream_socket_t = typename Traits::stream_socket_t |
Definition at line 136 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::timer_guard_t = typename timer_manager_t::timer_guard_t |
Definition at line 133 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::timer_manager_handle_t = std::shared_ptr< timer_manager_t > |
Definition at line 132 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::timer_manager_t = typename Traits::timer_manager_t |
Definition at line 131 of file ws_connection.hpp.
|
private |
Definition at line 1102 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::ws_weak_handle_t = std::weak_ptr< ws_t > |
Definition at line 140 of file ws_connection.hpp.
|
strongprivate |
Websocket input states.
Definition at line 1393 of file ws_connection.hpp.
|
strongprivate |
Websocket output states.
Enumerator | |
---|---|
write_enabled | Able to append outgoing data. |
write_disabled | No more outgoing data can be added (e.g. close-frame was sent). |
Definition at line 1381 of file ws_connection.hpp.
|
delete |
|
delete |
|
inlineoverride |
Definition at line 192 of file ws_connection.hpp.
|
inlineprivate |
Handle read operation result, when reading header.
Definition at line 562 of file ws_connection.hpp.
|
inlineprivate |
Handle read operation result, when reading payload.
Definition at line 748 of file ws_connection.hpp.
|
inlineprivate |
Handle write response finished.
Definition at line 1216 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1003 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 935 of file ws_connection.hpp.
|
inlineprivate |
Call user message handler with current message.
Definition at line 816 of file ws_connection.hpp.
|
inlinestaticprivate |
Timers.
Definition at line 1265 of file ws_connection.hpp.
|
inlineoverrideprivatevirtual |
Definition at line 1271 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1307 of file ws_connection.hpp.
|
inlineprivatenoexcept |
Standard close routine.
Definition at line 371 of file ws_connection.hpp.
|
inlineprivate |
Parse header from internal buffer.
Definition at line 586 of file ws_connection.hpp.
|
inlineprivate |
Initiate read operation on socket to receive bytes for header.
Definition at line 510 of file ws_connection.hpp.
|
inlineprivate |
Do post write actions for current write group.
Definition at line 1197 of file ws_connection.hpp.
|
inlineprivate |
Close WebSocket connection in a graceful manner.
Definition at line 413 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1352 of file ws_connection.hpp.
|
inlineprivate |
Start guard write operation if necessary.
Definition at line 1345 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1106 of file ws_connection.hpp.
|
inlineprivate |
Handle payload errors.
Definition at line 883 of file ws_connection.hpp.
|
inlineprivate |
Handle parsed and valid header.
Definition at line 651 of file ws_connection.hpp.
|
inlineprivate |
Handle parsed header.
Definition at line 605 of file ws_connection.hpp.
|
inlineprivate |
Handle read error (reading header or payload)
Definition at line 546 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1140 of file ws_connection.hpp.
|
inlineprivate |
schedule next timeout checking.
Definition at line 1338 of file ws_connection.hpp.
|
inlineoverridevirtual |
Start reading ws-messages.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 284 of file ws_connection.hpp.
|
inlineprivate |
Initiate write operation.
Definition at line 1075 of file ws_connection.hpp.
|
inlineprivate |
Checks if there is something to write, and if so starts write operation.
Definition at line 1065 of file ws_connection.hpp.
|
inlineoverridevirtual |
Kill websocket.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 245 of file ws_connection.hpp.
|
delete |
|
delete |
|
inlineprivate |
Send close frame to peer.
Definition at line 446 of file ws_connection.hpp.
|
inlineprivate |
Send close frame to peer.
Definition at line 424 of file ws_connection.hpp.
|
inlineoverridevirtual |
Shutdown websocket.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 209 of file ws_connection.hpp.
|
inlineprivate |
Start the process of reading ws messages from socket.
Definition at line 485 of file ws_connection.hpp.
|
inlineprivate |
Start reading message payload.
payload_data | A pointer to the remainder of unfetched payload. |
length_remaining | The size of the remainder of unfetched payload. |
do_validate_payload_and_call_msg_handler | Validate payload and call handler. |
Definition at line 703 of file ws_connection.hpp.
|
inlineprivate |
Start waiting for close-frame.
Definition at line 405 of file ws_connection.hpp.
|
inlineprivatenoexcept |
Trigger an error.
Writes error message to log, closes socket, and sends close frame to user if necessary.
Definition at line 464 of file ws_connection.hpp.
|
inlineprivate |
Validates a part of received payload.
Definition at line 840 of file ws_connection.hpp.
|
inlineoverridevirtual |
Write pieces of outgoing data.
Run write message on io_context loop if possible.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 321 of file ws_connection.hpp.
|
inlineprivate |
Implementation of writing data performed on the asio_ns::io_context.
Definition at line 1017 of file ws_connection.hpp.
|
private |
Definition at line 1301 of file ws_connection.hpp.
|
private |
Definition at line 1434 of file ws_connection.hpp.
|
private |
Definition at line 1433 of file ws_connection.hpp.
|
private |
Definition at line 1435 of file ws_connection.hpp.
|
private |
Input routine.
Definition at line 1360 of file ws_connection.hpp.
|
private |
Monitor of the connection lifetime.
Definition at line 1260 of file ws_connection.hpp.
|
private |
Logger for operation.
Definition at line 1369 of file ws_connection.hpp.
|
private |
Websocket message handler provided by user.
Definition at line 1366 of file ws_connection.hpp.
|
private |
Output buffers queue.
Definition at line 1375 of file ws_connection.hpp.
|
private |
Definition at line 1303 of file ws_connection.hpp.
|
private |
Helper for validating protocol.
Definition at line 1363 of file ws_connection.hpp.
|
private |
A state of a websocket input.
Definition at line 1404 of file ws_connection.hpp.
|
private |
Common paramaters of a connection.
Definition at line 1250 of file ws_connection.hpp.
|
private |
Connection.
Definition at line 1253 of file ws_connection.hpp.
|
private |
Definition at line 1304 of file ws_connection.hpp.
|
private |
A waek handler for owning ws_t to use it when call message handler.
Definition at line 1378 of file ws_connection.hpp.
|
private |
Definition at line 1300 of file ws_connection.hpp.
|
private |
Write to socket operation context.
Definition at line 1372 of file ws_connection.hpp.
|
private |
A state of a websocket output.
Definition at line 1390 of file ws_connection.hpp.