#ifndef SESSION_H #define SESSION_H #include #include #include class session : public std::enable_shared_from_this { public: session(boost::asio::ip::tcp::socket socket, boost::asio::io_service &io_service, std::string hostname, std::string port); void start(void); ~session(); void parse_auth(void); void on_connect(const boost::system::error_code error); void server_read(void); void on_resolve(const boost::system::error_code error, const boost::asio::ip::tcp::resolver::results_type results); void do_read(void); void do_write(std::string message); void server_write(std::string message); void on_shutdown(boost::system::error_code ec); private: boost::asio::ip::tcp::socket socket_; boost::asio::io_service &io_service_; boost::asio::ip::tcp::resolver resolver_; boost::asio::ip::tcp::socket server_; boost::asio::high_resolution_timer timer_; // std::string read_buffer; char read_buffer[257]; char server_buffer[257]; std::string rlogin_auth; std::string rlogin_name; std::string host; std::string port; bool connected = false; }; /* maybe move the resolver part to the server, so I don't need io_service? I'm not sure what the socket connection part is going to need just yet, so I probably won't move that just yet. [NNY!] */ class server { public: server(boost::asio::io_service &io_service, const boost::asio::ip::tcp::endpoint &endpoint, std::string host, std::string port) : io_service_{io_service}, acceptor_{io_service_, endpoint}, host_{host}, port_{port} { do_accept(); } private: void do_accept() { acceptor_.async_accept([this](boost::system::error_code ec, boost::asio::ip::tcp::socket socket) { if (!ec) { std::make_shared(std::move(socket), io_service_, host_, port_) ->start(); } do_accept(); }); } boost::asio::io_service &io_service_; boost::asio::ip::tcp::acceptor acceptor_; std::string host_; std::string port_; }; #endif