34 lines
954 B
C++
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
|