13 #include <restinio/websocket/message.hpp> 14 #include <restinio/websocket/impl/ws_connection_base.hpp> 15 #include <restinio/websocket/impl/ws_connection.hpp> 16 #include <restinio/utils/base64.hpp> 17 #include <restinio/utils/sha1.hpp> 49 ws.m_ws_connection_handle->init_read( ws.shared_from_this() );
58 impl::ws_connection_handle_t ws_connection_handle,
59 endpoint_t remote_endpoint )
82 return m_ws_connection_handle ? m_ws_connection_handle->connection_id() : 0;
90 if( m_ws_connection_handle )
92 auto con = std::move( m_ws_connection_handle );
102 if( m_ws_connection_handle )
104 auto con = std::move( m_ws_connection_handle );
112 final_frame_flag_t final_flag,
114 writable_item_t payload,
117 if( m_ws_connection_handle )
119 if( restinio::writable_item_type_t::trivial_write_operation ==
120 payload.write_type() )
122 writable_items_container_t bufs;
126 impl::message_details_t details{
127 final_flag, opcode, asio_ns::buffer_size( payload.buf() ) };
130 impl::write_message_details( details ) );
132 bufs.emplace_back( std::move( payload ) );
134 write_group_t wg{ std::move( bufs ) };
138 wg.after_write_notificator( std::move( wscb ) );
142 const bool is_close_frame =
143 opcode_t::connection_close_frame == opcode;
147 auto con = std::move( m_ws_connection_handle );
154 m_ws_connection_handle->write_data(
161 throw exception_t{
"ws doesn't support sendfile" };
166 throw exception_t{
"websocket is not available" };
176 writable_item_t{ std::move( msg.payload() ) },
233 "{} field is mandatory for upgrade response" ),
246 throw exception_t{
"no connection for upgrade: already moved" };
void shutdown()
Shutdown websocket: wait for all outgoing data to be sent, and close connection.
ws_t & operator=(const ws_t &)=delete
ws_t(const ws_t &)=delete
const endpoint_t & remote_endpoint() const noexcept
Get the remote endpoint of the underlying connection.
void send_message(message_t msg, write_status_cb_t wscb=write_status_cb_t{})
const endpoint_t m_remote_endpoint
Remote endpoint for this ws-connection.
void send_message(final_frame_flag_t final_flag, opcode_t opcode, writable_item_t payload, write_status_cb_t wscb=write_status_cb_t{})
Send_websocket message.
User will initiate activation later.
connection_id_t connection_id() const
Get connection id.
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, std::optional< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in std::optional<Value_Type> if parameter exis...
auto upgrade(generic_request_type_from_traits_t< Traits > &req, activation_t activation_flag, WS_Message_Handler ws_message_handler)
impl::ws_connection_handle_t m_ws_connection_handle
activation_t
Flags for websocket activation policies.
void kill()
Kill websocket: close underlying tcp socket. Do not tolerate unsent outgoing data.
ws_t & operator=(ws_t &&)=delete
friend void activate(ws_t &ws)
Activate websocket: start receiving messages.
Activate immediately after upgrade operation.
ws_t(impl::ws_connection_handle_t ws_connection_handle, endpoint_t remote_endpoint)