summaryrefslogtreecommitdiff
path: root/server/connection.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@sakuya.local>2010-11-06 02:35:39 +0100
committerVegard Storheil Eriksen <zyp@sakuya.local>2010-11-06 02:35:39 +0100
commitcfef24ce8541ac3934ecfe7248a33d1099d94dfa (patch)
tree4335e25b6fd490fa8744fed82aa7273fc7a72395 /server/connection.h
parentdf5932614261a825fb5a9283c321f47f7a198b24 (diff)
First take on abstract ConnectionBase, ASIO listening and connection handling.
Diffstat (limited to 'server/connection.h')
-rw-r--r--server/connection.h38
1 files changed, 38 insertions, 0 deletions
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 <boost/asio.hpp>
+#include <boost/enable_shared_from_this.hpp>
+
+#include "../common/connectionbase.h"
+
+class Connection : public ConnectionBase, public boost::enable_shared_from_this<Connection> {
+ 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<Connection> p;
+
+ //! Constructs a new instance and returns a shared pointer.
+ static p create(boost::asio::io_service& io_service);
+};
+
+#endif