diff options
author | Vegard Storheil Eriksen <zyp@sakuya.local> | 2010-11-06 02:35:39 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@sakuya.local> | 2010-11-06 02:35:39 +0100 |
commit | cfef24ce8541ac3934ecfe7248a33d1099d94dfa (patch) | |
tree | 4335e25b6fd490fa8744fed82aa7273fc7a72395 /server/connection.cpp | |
parent | df5932614261a825fb5a9283c321f47f7a198b24 (diff) |
First take on abstract ConnectionBase, ASIO listening and connection handling.
Diffstat (limited to 'server/connection.cpp')
-rw-r--r-- | server/connection.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/server/connection.cpp b/server/connection.cpp new file mode 100644 index 0000000..f846d3b --- /dev/null +++ b/server/connection.cpp @@ -0,0 +1,35 @@ +#include "connection.h" + +#include <boost/bind.hpp> + +Connection::Connection(boost::asio::io_service& io_service) : socket(io_service) { + +} + +void Connection::handle_read(uint8_t* data, std::size_t bytes) { + got_data(data, bytes); + + delete[] data; +} + +void Connection::handle_write() { + +} + +void Connection::request_data(std::size_t bytes) { + uint8_t* buf = new uint8_t[bytes]; + + boost::asio::async_read(socket, boost::asio::buffer(buf, bytes), + boost::bind(&Connection::handle_read, shared_from_this(), buf, bytes)); + + // boost::asio::placeholders::error +} + +void Connection::write_data(uint8_t* data, std::size_t bytes) { + boost::asio::async_write(socket, boost::asio::buffer(data, bytes), + boost::bind(&Connection::handle_write, shared_from_this())); +} + +Connection::p Connection::create(boost::asio::io_service& io_service) { + return Connection::p(new Connection(io_service)); +} |