#ifndef CONNECTION_H #define CONNECTION_H #include #include #include #include "../common/connectionbase.h" class Connection : public ConnectionBase, public boost::enable_shared_from_this { private: friend class TCPServer; friend class Client; boost::asio::ip::tcp::socket socket; boost::function recv_callback; boost::function error_callback; Connection(boost::asio::io_service& io_service); //! Callback for when data is read. void handle_read(uint8_t* data, std::size_t bytes, const boost::system::error_code& error_code); //! Callback for when data is written. void handle_write(); protected: //! Implements request_data(). virtual void request_data(std::size_t bytes); //! Implements write_data(). virtual void write_data(uint8_t* data, std::size_t bytes); //! Implements got_message(). virtual void got_message(const Message::p& msg); //! Implements error(). virtual void error(const std::string& msg); public: typedef boost::shared_ptr p; //! Constructs a new instance and returns a shared pointer. static p create(boost::asio::io_service& io_service); //! Initiates an asynchronous message receive. //! \param callback Callback for received message. //! \param error Callback for error. void recv(boost::function callback, boost::function error = 0); }; #endif