Вторая часть - база для сессии
Для асинхронного запуска сессии добавьте метод SessionBase::Run
This commit is contained in:
parent
67e5fd080b
commit
97e6e358ef
@ -19,6 +19,10 @@ namespace http = beast::http;
|
|||||||
|
|
||||||
template <typename RequestHandler>
|
template <typename RequestHandler>
|
||||||
class Session : public SessionBase, public std::enable_shared_from_this<Session<RequestHandler>> {
|
class Session : public SessionBase, public std::enable_shared_from_this<Session<RequestHandler>> {
|
||||||
// Напишите недостающий код, используя информацию из урока
|
RequestHandler request_handler_;
|
||||||
|
template<class Handler>
|
||||||
|
Session(tcp::socket&& socket, Handler&& request_handler)
|
||||||
|
: SessionBase(std::move(socket)), request_handler_(request_handler)
|
||||||
|
{}
|
||||||
};
|
};
|
||||||
} // namespace http_server
|
} // namespace http_server
|
@ -8,5 +8,10 @@ namespace http_server
|
|||||||
{
|
{
|
||||||
void ReportError(beast::error_code ec, std::string_view what) {
|
void ReportError(beast::error_code ec, std::string_view what) {
|
||||||
std::cerr << what << ": "sv << ec.message() << std::endl;
|
std::cerr << what << ": "sv << ec.message() << std::endl;
|
||||||
|
}
|
||||||
|
SessionBase::SessionBase(tcp::socket&& socket)
|
||||||
|
: stream_(std::move(socket))
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
} // namespace http_server
|
} // namespace http_server
|
||||||
|
@ -23,6 +23,21 @@ using namespace std::literals;
|
|||||||
void ReportError(beast::error_code ec, std::string_view what);
|
void ReportError(beast::error_code ec, std::string_view what);
|
||||||
|
|
||||||
class SessionBase {
|
class SessionBase {
|
||||||
// Напишите недостающий код, используя информацию из урока
|
protected:
|
||||||
|
using HttpRequest = http::request<http::string_body>;
|
||||||
|
|
||||||
|
~SessionBase() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SessionBase(const SessionBase&) = delete;
|
||||||
|
SessionBase& operator =(const SessionBase&) = delete;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit SessionBase(tcp::socket&& socket);
|
||||||
|
|
||||||
|
private:
|
||||||
|
beast::tcp_stream stream_;
|
||||||
|
beast::flat_buffer buffer_;
|
||||||
|
HttpRequest request_;
|
||||||
};
|
};
|
||||||
} // namespace http_server
|
} // namespace http_server
|
Loading…
x
Reference in New Issue
Block a user