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 <variant>
class WsBase;
class SubscriptionManager;
class LoadBalancer;
class ETLService;

View File

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

View File

@@ -28,7 +28,7 @@ namespace Server {
* class.
*/
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_;
@@ -40,7 +40,7 @@ public:
std::reference_wrapper<clio::DOSGuard> dosGuard,
std::shared_ptr<Handler> const& handler,
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.
*/
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_;
std::reference_wrapper<clio::DOSGuard> dosGuard_;
@@ -70,7 +70,7 @@ protected:
}
public:
explicit WsSession(
explicit WsBase(
std::string ip,
std::reference_wrapper<util::TagDecoratorFactory const> tagFactory,
std::reference_wrapper<clio::DOSGuard> dosGuard,
@@ -82,7 +82,7 @@ public:
perfLog_.debug() << tag() << "session created";
}
virtual ~WsSession()
virtual ~WsBase()
{
perfLog_.debug() << tag() << "session closed";
dosGuard_.get().decrement(clientIp);
@@ -100,7 +100,7 @@ public:
sending_ = true;
derived().ws().async_write(
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
@@ -184,7 +184,7 @@ public:
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
@@ -207,8 +207,7 @@ public:
// Clear the buffer
buffer_.consume(buffer_.size());
derived().ws().async_read(
buffer_, boost::beast::bind_front_handler(&WsSession::onRead, this->shared_from_this()));
derived().ws().async_read(buffer_, boost::beast::bind_front_handler(&WsBase::onRead, this->shared_from_this()));
}
void