#pragma once #include #include #include /*! * \file */ /*! * \brief The Client class */ class Client { public: /*! * \brief OnDoneFT Function type of the function being called when this instance is done operating. */ typedef std::function OnDoneFT; /*! * \brief MessageHandler Function type of the function handling incoming messages. */ typedef std::function)> MessageHandler; protected: /*! * \brief socket The socket connection this instance handles. */ boost::asio::ip::tcp::socket socket; private: /*! * \brief buffer Internal private buffer used to receive messages. */ boost::asio::streambuf buffer; /*! * \brief done The done function being called when this is done operating. */ OnDoneFT done; /*! * \brief handle_receive * \param message_handler The function to call when a message has been received. * \param ec A possible error that occured during receiving. * \param read_bytes The number of bytes read. */ void handle_receive(MessageHandler message_handler, boost::system::error_code const& ec, size_t read_bytes); public: /*! * \brief Client * \param socket An rvalue reference to a socket it will now own and receive from. */ Client(boost::asio::ip::tcp::socket&& socket); /*! * \brief receive * \param message_handler The function to call when a message has been received. */ void receive(MessageHandler message_handler); /*! * \brief on_done sets the done callback. * \param f The new done callback function. */ void on_done(OnDoneFT f); };