From cfef24ce8541ac3934ecfe7248a33d1099d94dfa Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 6 Nov 2010 02:35:39 +0100 Subject: First take on abstract ConnectionBase, ASIO listening and connection handling. --- server/connection.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/connection.h (limited to 'server/connection.h') diff --git a/server/connection.h b/server/connection.h new file mode 100644 index 0000000..aba7734 --- /dev/null +++ b/server/connection.h @@ -0,0 +1,38 @@ +#ifndef CONNECTION_H +#define CONNECTION_H + +#include +#include + +#include "../common/connectionbase.h" + +class Connection : public ConnectionBase, public boost::enable_shared_from_this { + private: + friend class TCPServer; + + boost::asio::ip::tcp::socket socket; + + Connection(boost::asio::io_service& io_service); + + private: + //! Callback for when data is read. + void handle_read(uint8_t* data, std::size_t bytes); + + //! 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); + + public: + typedef boost::shared_ptr p; + + //! Constructs a new instance and returns a shared pointer. + static p create(boost::asio::io_service& io_service); +}; + +#endif -- cgit v1.2.3