http_session.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/vinniefalco/CppCon2018
  8. //
  9. #ifndef BOOST_BEAST_EXAMPLE_WEBSOCKET_CHAT_MULTI_HTTP_SESSION_HPP
  10. #define BOOST_BEAST_EXAMPLE_WEBSOCKET_CHAT_MULTI_HTTP_SESSION_HPP
  11. #include "net.hpp"
  12. #include "beast.hpp"
  13. #include "shared_state.hpp"
  14. #include <boost/optional.hpp>
  15. #include <boost/smart_ptr.hpp>
  16. #include <cstdlib>
  17. #include <memory>
  18. /** Represents an established HTTP connection
  19. */
  20. class http_session : public boost::enable_shared_from_this<http_session>
  21. {
  22. beast::tcp_stream stream_;
  23. beast::flat_buffer buffer_;
  24. boost::shared_ptr<shared_state> state_;
  25. // The parser is stored in an optional container so we can
  26. // construct it from scratch it at the beginning of each new message.
  27. boost::optional<http::request_parser<http::string_body>> parser_;
  28. struct send_lambda;
  29. void fail(beast::error_code ec, char const* what);
  30. void do_read();
  31. void on_read(beast::error_code ec, std::size_t);
  32. void on_write(beast::error_code ec, std::size_t, bool close);
  33. public:
  34. http_session(
  35. tcp::socket&& socket,
  36. boost::shared_ptr<shared_state> const& state);
  37. void run();
  38. };
  39. #endif