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 |
using | ws_weak_handle_t = std::weak_ptr< ws_t > |
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. | |
void | start_waiting_close_frame_only () |
Start waiting for close-frame. | |
void | graceful_close () |
Close WebSocket connection in a graceful manner. | |
void | send_close_frame_to_peer (std::string payload) |
Send close frame to peer. | |
void | send_close_frame_to_peer (status_code_t code, std::string desc=std::string{}) |
Send close frame to peer. | |
template<typename MSG_BUILDER > | |
void | trigger_error_and_close (status_code_t status, MSG_BUILDER msg_builder) noexcept |
Trigger an error. | |
void | start_read_header () |
Start the process of reading ws messages from socket. | |
void | consume_header_from_socket () |
Initiate read operation on socket to receive bytes for header. | |
void | handle_read_error (const char *desc, const asio_ns::error_code &ec) |
Handle read error (reading header or payload) | |
void | after_read_header (const asio_ns::error_code &ec, std::size_t length) |
Handle read operation result, when reading header. | |
void | consume_header_from_buffer (const char *data, std::size_t length) |
Parse header from internal buffer. | |
void | handle_parsed_header (const message_details_t &md) |
Handle parsed header. | |
void | handle_parsed_and_valid_header (const message_details_t &md) |
Handle parsed and valid header. | |
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. | |
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. | |
void | call_message_handler (message_handle_t close_frame) |
Call user message handler with current message. | |
bool | validate_payload_part (char *payload_data, std::size_t length, std::size_t next_length_remaining) |
Validates a part of received payload. | |
void | handle_invalid_payload (validation_state_t validation_result) |
Handle payload errors. | |
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. | |
void | init_write_if_necessary () |
Checks if there is something to write, and if so starts write operation. | |
void | init_write () |
Initiate write operation. | |
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. | |
void | after_write (const asio_ns::error_code &ec) |
Handle write response finished. | |
Additional Inherited Members | |
![]() | |
template<typename Derived > | |
std::shared_ptr< Derived > | shared_from_concrete () |
Cast self to derived class. | |
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 1133 of file ws_connection.hpp.
using restinio::websocket::basic::impl::ws_connection_t< Traits, WS_Message_Handler >::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 1131 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 1132 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.
Websocket input states.
Definition at line 1437 of file ws_connection.hpp.
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 1425 of file ws_connection.hpp.
|
delete |
|
delete |
|
inlineoverride |
Definition at line 194 of file ws_connection.hpp.
|
inlineprivate |
Handle read operation result, when reading header.
Definition at line 577 of file ws_connection.hpp.
|
inlineprivate |
Handle read operation result, when reading payload.
Definition at line 768 of file ws_connection.hpp.
|
inlineprivate |
Handle write response finished.
Definition at line 1253 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1029 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 958 of file ws_connection.hpp.
|
inlineprivate |
Call user message handler with current message.
Definition at line 837 of file ws_connection.hpp.
|
inlinestaticprivate |
Timers.
Definition at line 1304 of file ws_connection.hpp.
|
inlineoverrideprivatevirtual |
Definition at line 1310 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1348 of file ws_connection.hpp.
|
inlineprivatenoexcept |
Standard close routine.
Definition at line 381 of file ws_connection.hpp.
|
inlineprivate |
Parse header from internal buffer.
Definition at line 602 of file ws_connection.hpp.
|
inlineprivate |
Initiate read operation on socket to receive bytes for header.
Definition at line 522 of file ws_connection.hpp.
|
inlineprivate |
Do post write actions for current write group.
Definition at line 1233 of file ws_connection.hpp.
|
inlineprivate |
Close WebSocket connection in a graceful manner.
Definition at line 424 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1396 of file ws_connection.hpp.
|
inlineprivate |
Start guard write operation if necessary.
Definition at line 1389 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1136 of file ws_connection.hpp.
|
inlineprivate |
Handle payload errors.
Definition at line 905 of file ws_connection.hpp.
|
inlineprivate |
Handle parsed and valid header.
Definition at line 669 of file ws_connection.hpp.
|
inlineprivate |
Handle parsed header.
Definition at line 621 of file ws_connection.hpp.
|
inlineprivate |
Handle read error (reading header or payload)
Definition at line 561 of file ws_connection.hpp.
|
inlineprivate |
Definition at line 1171 of file ws_connection.hpp.
|
inlineprivate |
schedule next timeout checking.
Definition at line 1382 of file ws_connection.hpp.
|
inlineoverridevirtual |
Start reading ws-messages.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 291 of file ws_connection.hpp.
|
inlineprivate |
Initiate write operation.
Definition at line 1104 of file ws_connection.hpp.
|
inlineprivate |
Checks if there is something to write, and if so starts write operation.
Definition at line 1094 of file ws_connection.hpp.
|
inlineoverridevirtual |
Kill websocket.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 250 of file ws_connection.hpp.
|
delete |
|
delete |
|
inlineprivate |
Send close frame to peer.
Definition at line 457 of file ws_connection.hpp.
|
inlineprivate |
Send close frame to peer.
Definition at line 435 of file ws_connection.hpp.
|
inlineoverridevirtual |
Shutdown websocket.
Implements restinio::websocket::basic::impl::ws_connection_base_t.
Definition at line 212 of file ws_connection.hpp.
|
inlineprivate |
Start the process of reading ws messages from socket.
Definition at line 496 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 721 of file ws_connection.hpp.
|
inlineprivate |
Start waiting for close-frame.
Definition at line 416 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 475 of file ws_connection.hpp.
|
inlineprivate |
Validates a part of received payload.
Definition at line 862 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 329 of file ws_connection.hpp.
|
inlineprivate |
Implementation of writing data performed on the asio_ns::io_context.
Definition at line 1043 of file ws_connection.hpp.
|
private |
Definition at line 1342 of file ws_connection.hpp.
|
private |
Definition at line 1478 of file ws_connection.hpp.
|
private |
Definition at line 1477 of file ws_connection.hpp.
|
private |
Definition at line 1479 of file ws_connection.hpp.
|
private |
Input routine.
Definition at line 1404 of file ws_connection.hpp.
|
private |
Monitor of the connection lifetime.
Definition at line 1299 of file ws_connection.hpp.
|
private |
Logger for operation.
Definition at line 1413 of file ws_connection.hpp.
|
private |
Websocket message handler provided by user.
Definition at line 1410 of file ws_connection.hpp.
|
private |
Output buffers queue.
Definition at line 1419 of file ws_connection.hpp.
|
private |
Definition at line 1344 of file ws_connection.hpp.
|
private |
Helper for validating protocol.
Definition at line 1407 of file ws_connection.hpp.
|
private |
A state of a websocket input.
Definition at line 1448 of file ws_connection.hpp.
|
private |
Common paramaters of a connection.
Definition at line 1289 of file ws_connection.hpp.
|
private |
Connection.
Definition at line 1292 of file ws_connection.hpp.
|
private |
Definition at line 1345 of file ws_connection.hpp.
|
private |
A waek handler for owning ws_t to use it when call message handler.
Definition at line 1422 of file ws_connection.hpp.
|
private |
Definition at line 1341 of file ws_connection.hpp.
|
private |
Write to socket operation context.
Definition at line 1416 of file ws_connection.hpp.
|
private |
A state of a websocket output.
Definition at line 1434 of file ws_connection.hpp.