websocket.hpp (04e438cbad66838724d78ce12f28aff1fb892a63) | websocket.hpp (81ce609e30274435b4f8c3fc65340c6b6b153b0c) |
---|---|
1#pragma once 2#include "http_request.hpp" 3 4#include <async_resp.hpp> 5#include <boost/algorithm/string/predicate.hpp> 6#include <boost/asio/buffer.hpp> 7#include <boost/beast/websocket.hpp> 8 --- 52 unchanged lines hidden (view full) --- 61 62template <typename Adaptor> 63class ConnectionImpl : public Connection 64{ 65 public: 66 ConnectionImpl( 67 const crow::Request& reqIn, Adaptor adaptorIn, 68 std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)> | 1#pragma once 2#include "http_request.hpp" 3 4#include <async_resp.hpp> 5#include <boost/algorithm/string/predicate.hpp> 6#include <boost/asio/buffer.hpp> 7#include <boost/beast/websocket.hpp> 8 --- 52 unchanged lines hidden (view full) --- 61 62template <typename Adaptor> 63class ConnectionImpl : public Connection 64{ 65 public: 66 ConnectionImpl( 67 const crow::Request& reqIn, Adaptor adaptorIn, 68 std::function<void(Connection&, std::shared_ptr<bmcweb::AsyncResp>)> |
69 open_handler, | 69 openHandler, |
70 std::function<void(Connection&, const std::string&, bool)> | 70 std::function<void(Connection&, const std::string&, bool)> |
71 message_handler, 72 std::function<void(Connection&, const std::string&)> close_handler, 73 std::function<void(Connection&)> error_handler) : | 71 messageHandler, 72 std::function<void(Connection&, const std::string&)> closeHandler, 73 std::function<void(Connection&)> errorHandler) : |
74 Connection(reqIn, reqIn.session->username), 75 ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088), | 74 Connection(reqIn, reqIn.session->username), 75 ws(std::move(adaptorIn)), inString(), inBuffer(inString, 131088), |
76 openHandler(std::move(open_handler)), 77 messageHandler(std::move(message_handler)), 78 closeHandler(std::move(close_handler)), 79 errorHandler(std::move(error_handler)), session(reqIn.session) | 76 openHandler(std::move(openHandler)), 77 messageHandler(std::move(messageHandler)), 78 closeHandler(std::move(closeHandler)), 79 errorHandler(std::move(errorHandler)), session(reqIn.session) |
80 { 81 BMCWEB_LOG_DEBUG << "Creating new connection " << this; 82 } 83 84 boost::asio::io_context& getIoContext() override 85 { 86 return static_cast<boost::asio::io_context&>( 87 ws.get_executor().context()); --- 109 unchanged lines hidden (view full) --- 197 openHandler(*this, asyncResp); 198 } 199 } 200 201 void doRead() 202 { 203 ws.async_read(inBuffer, 204 [this, self(shared_from_this())]( | 80 { 81 BMCWEB_LOG_DEBUG << "Creating new connection " << this; 82 } 83 84 boost::asio::io_context& getIoContext() override 85 { 86 return static_cast<boost::asio::io_context&>( 87 ws.get_executor().context()); --- 109 unchanged lines hidden (view full) --- 197 openHandler(*this, asyncResp); 198 } 199 } 200 201 void doRead() 202 { 203 ws.async_read(inBuffer, 204 [this, self(shared_from_this())]( |
205 boost::beast::error_code ec, std::size_t bytes_read) { | 205 boost::beast::error_code ec, std::size_t bytesRead) { |
206 if (ec) 207 { 208 if (ec != boost::beast::websocket::error::closed) 209 { 210 BMCWEB_LOG_ERROR << "doRead error " << ec; 211 } 212 if (closeHandler) 213 { 214 std::string_view reason = ws.reason().reason; 215 closeHandler(*this, std::string(reason)); 216 } 217 return; 218 } 219 if (messageHandler) 220 { 221 messageHandler(*this, inString, ws.got_text()); 222 } | 206 if (ec) 207 { 208 if (ec != boost::beast::websocket::error::closed) 209 { 210 BMCWEB_LOG_ERROR << "doRead error " << ec; 211 } 212 if (closeHandler) 213 { 214 std::string_view reason = ws.reason().reason; 215 closeHandler(*this, std::string(reason)); 216 } 217 return; 218 } 219 if (messageHandler) 220 { 221 messageHandler(*this, inString, ws.got_text()); 222 } |
223 inBuffer.consume(bytes_read); | 223 inBuffer.consume(bytesRead); |
224 inString.clear(); 225 doRead(); 226 }); 227 } 228 229 void doWrite() 230 { 231 // If we're already doing a write, ignore the request, it will be picked --- 54 unchanged lines hidden --- | 224 inString.clear(); 225 doRead(); 226 }); 227 } 228 229 void doWrite() 230 { 231 // If we're already doing a write, ignore the request, it will be picked --- 54 unchanged lines hidden --- |