Older/Server/Listener.h
2023-07-21 16:17:01 +08:00

34 lines
954 B
C++

#ifndef LISTENER_H
#define LISTENER_H
#include <boost/asio.hpp>
#include <boost/beast.hpp>
#include <memory>
#include <string>
class SharedState;
// Accepts incoming connections and launches the sessions
class Listener : public std::enable_shared_from_this<Listener> {
public:
Listener(boost::asio::io_context &ioc, boost::asio::ip::tcp::endpoint endpoint,
std::shared_ptr<SharedState> const &state);
// Start accepting incoming connections
void startAccept();
inline std::shared_ptr<SharedState> state() const {
return m_state;
}
protected:
void fail(boost::beast::error_code ec, char const *what);
void onAccept(boost::beast::error_code ec, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
private:
boost::asio::io_context &m_ioContext;
boost::asio::ip::tcp::acceptor m_acceptor;
std::shared_ptr<SharedState> m_state;
};
#endif // LISTENER_H