listener.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_LISTENER_HPP
  10. #define BOOST_BEAST_EXAMPLE_WEBSOCKET_CHAT_MULTI_LISTENER_HPP
  11. #include "beast.hpp"
  12. #include "net.hpp"
  13. #include <boost/smart_ptr.hpp>
  14. #include <memory>
  15. #include <string>
  16. // Forward declaration
  17. class shared_state;
  18. // Accepts incoming connections and launches the sessions
  19. class listener : public boost::enable_shared_from_this<listener>
  20. {
  21. net::io_context& ioc_;
  22. tcp::acceptor acceptor_;
  23. boost::shared_ptr<shared_state> state_;
  24. void fail(beast::error_code ec, char const* what);
  25. void on_accept(beast::error_code ec, tcp::socket socket);
  26. public:
  27. listener(
  28. net::io_context& ioc,
  29. tcp::endpoint endpoint,
  30. boost::shared_ptr<shared_state> const& state);
  31. // Start accepting incoming connections
  32. void run();
  33. };
  34. #endif