Rename WsSession to WsBase (#770)

This commit is contained in:
cyan317
2023-07-14 13:28:15 +01:00
committed by GitHub
parent d195bdb66d
commit 4fd6d51d21
4 changed files with 11 additions and 14 deletions

View File

@@ -43,7 +43,6 @@
#include <unordered_map> #include <unordered_map>
#include <variant> #include <variant>
class WsBase;
class SubscriptionManager; class SubscriptionManager;
class LoadBalancer; class LoadBalancer;
class ETLService; class ETLService;

View File

@@ -28,7 +28,7 @@ namespace Server {
* class * class
*/ */
template <ServerHandler Handler> template <ServerHandler Handler>
class PlainWsSession : public WsSession<PlainWsSession, Handler> class PlainWsSession : public WsBase<PlainWsSession, Handler>
{ {
boost::beast::websocket::stream<boost::beast::tcp_stream> ws_; boost::beast::websocket::stream<boost::beast::tcp_stream> ws_;
@@ -40,8 +40,7 @@ public:
std::reference_wrapper<clio::DOSGuard> dosGuard, std::reference_wrapper<clio::DOSGuard> dosGuard,
std::shared_ptr<Handler> const& callback, std::shared_ptr<Handler> const& callback,
boost::beast::flat_buffer&& buffer) boost::beast::flat_buffer&& buffer)
: WsSession<PlainWsSession, Handler>(ip, tagFactory, dosGuard, callback, std::move(buffer)) : WsBase<PlainWsSession, Handler>(ip, tagFactory, dosGuard, callback, std::move(buffer)), ws_(std::move(socket))
, ws_(std::move(socket))
{ {
} }

View File

@@ -28,7 +28,7 @@ namespace Server {
* class. * class.
*/ */
template <ServerHandler Handler> template <ServerHandler Handler>
class SslWsSession : public WsSession<SslWsSession, Handler> class SslWsSession : public WsBase<SslWsSession, Handler>
{ {
boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>> ws_; boost::beast::websocket::stream<boost::beast::ssl_stream<boost::beast::tcp_stream>> ws_;
@@ -40,7 +40,7 @@ public:
std::reference_wrapper<clio::DOSGuard> dosGuard, std::reference_wrapper<clio::DOSGuard> dosGuard,
std::shared_ptr<Handler> const& handler, std::shared_ptr<Handler> const& handler,
boost::beast::flat_buffer&& b) boost::beast::flat_buffer&& b)
: WsSession<SslWsSession, Handler>(ip, tagFactory, dosGuard, handler, std::move(b)), ws_(std::move(stream)) : WsBase<SslWsSession, Handler>(ip, tagFactory, dosGuard, handler, std::move(b)), ws_(std::move(stream))
{ {
} }

View File

@@ -43,9 +43,9 @@ namespace Server {
* @tparam Handler The handler type, will be called when a request is received. * @tparam Handler The handler type, will be called when a request is received.
*/ */
template <template <class> class Derived, ServerHandler Handler> template <template <class> class Derived, ServerHandler Handler>
class WsSession : public ConnectionBase, public std::enable_shared_from_this<WsSession<Derived, Handler>> class WsBase : public ConnectionBase, public std::enable_shared_from_this<WsBase<Derived, Handler>>
{ {
using std::enable_shared_from_this<WsSession<Derived, Handler>>::shared_from_this; using std::enable_shared_from_this<WsBase<Derived, Handler>>::shared_from_this;
boost::beast::flat_buffer buffer_; boost::beast::flat_buffer buffer_;
std::reference_wrapper<clio::DOSGuard> dosGuard_; std::reference_wrapper<clio::DOSGuard> dosGuard_;
@@ -70,7 +70,7 @@ protected:
} }
public: public:
explicit WsSession( explicit WsBase(
std::string ip, std::string ip,
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory, std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
std::reference_wrapper<clio::DOSGuard> dosGuard, std::reference_wrapper<clio::DOSGuard> dosGuard,
@@ -82,7 +82,7 @@ public:
perfLog_.debug() << tag() << "session created"; perfLog_.debug() << tag() << "session created";
} }
virtual ~WsSession() virtual ~WsBase()
{ {
perfLog_.debug() << tag() << "session closed"; perfLog_.debug() << tag() << "session closed";
dosGuard_.get().decrement(clientIp); dosGuard_.get().decrement(clientIp);
@@ -100,7 +100,7 @@ public:
sending_ = true; sending_ = true;
derived().ws().async_write( derived().ws().async_write(
boost::asio::buffer(messages_.front()->data(), messages_.front()->size()), boost::asio::buffer(messages_.front()->data(), messages_.front()->size()),
boost::beast::bind_front_handler(&WsSession::onWrite, derived().shared_from_this())); boost::beast::bind_front_handler(&WsBase::onWrite, derived().shared_from_this()));
} }
void void
@@ -184,7 +184,7 @@ public:
res.set(http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-server-async"); res.set(http::field::server, std::string(BOOST_BEAST_VERSION_STRING) + " websocket-server-async");
})); }));
derived().ws().async_accept(req, bind_front_handler(&WsSession::onAccept, this->shared_from_this())); derived().ws().async_accept(req, bind_front_handler(&WsBase::onAccept, this->shared_from_this()));
} }
void void
@@ -207,8 +207,7 @@ public:
// Clear the buffer // Clear the buffer
buffer_.consume(buffer_.size()); buffer_.consume(buffer_.size());
derived().ws().async_read( derived().ws().async_read(buffer_, boost::beast::bind_front_handler(&WsBase::onRead, this->shared_from_this()));
buffer_, boost::beast::bind_front_handler(&WsSession::onRead, this->shared_from_this()));
} }
void void