Вторая часть - база для сессии

Так как метод SessionBase::Run мы вызвали внутри strand, связанного с акцептором,
This commit is contained in:
Sithas777 2023-09-13 18:13:28 +03:00
parent 97e6e358ef
commit 51beb16ed9
4 changed files with 24 additions and 1 deletions

View File

@ -66,6 +66,9 @@ class Listener : public std::enable_shared_from_this<Listener<RequestHandler>>
}
void AsyncRunSession(tcp::socket&& socket)
{}
{
std::make_shared<Session<RequestHandler>>(std::move(socket),
request_handler_)->Run();
}
};
} // namespace http_server

View File

@ -20,9 +20,16 @@ namespace http = beast::http;
template <typename RequestHandler>
class Session : public SessionBase, public std::enable_shared_from_this<Session<RequestHandler>> {
RequestHandler request_handler_;
public:
template<class Handler>
Session(tcp::socket&& socket, Handler&& request_handler)
: SessionBase(std::move(socket)), request_handler_(request_handler)
{}
std::shared_ptr<SessionBase> GetSharedThis() override
{
return this->shared_from_this();
}
};
} // namespace http_server

View File

@ -13,5 +13,13 @@ SessionBase::SessionBase(tcp::socket&& socket)
: stream_(std::move(socket))
{
}
void SessionBase::Run()
{
}
void SessionBase::Read()
{
}
} // namespace http_server

View File

@ -32,6 +32,11 @@ class SessionBase {
SessionBase(const SessionBase&) = delete;
SessionBase& operator =(const SessionBase&) = delete;
void Run();
void Read();
virtual std::shared_ptr<SessionBase> GetSharedThis() = 0;
protected:
explicit SessionBase(tcp::socket&& socket);