summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-15 07:01:56 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-15 07:01:56 +0100
commit174ac25d9788e5604ae37cf9048e307a97bbdff8 (patch)
treee613eef3f9078964dd3918c2b5fd35e6b146efd0 /server
parent6c56cfd9d0954dde4fa13d2c81ef3eb6f1881156 (diff)
Connection API changes.
Diffstat (limited to 'server')
-rw-r--r--server/connection.cpp10
-rw-r--r--server/connection.h9
2 files changed, 19 insertions, 0 deletions
diff --git a/server/connection.cpp b/server/connection.cpp
index 32b24da..f7315b2 100644
--- a/server/connection.cpp
+++ b/server/connection.cpp
@@ -29,6 +29,10 @@ void Connection::request_data(std::size_t bytes) {
// boost::asio::placeholders::error
}
+void Connection::got_message(const Message::p& msg) {
+ recv_callback(msg);
+}
+
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()));
@@ -37,3 +41,9 @@ void Connection::write_data(uint8_t* data, std::size_t bytes) {
Connection::p Connection::create(boost::asio::io_service& io_service) {
return Connection::p(new Connection(io_service));
}
+
+void Connection::recv(boost::function<void (Message::p)> f) {
+ recv_callback = f;
+
+ start_recv();
+} \ No newline at end of file
diff --git a/server/connection.h b/server/connection.h
index b6a3cd3..3428b88 100644
--- a/server/connection.h
+++ b/server/connection.h
@@ -3,6 +3,7 @@
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
+#include <boost/function.hpp>
#include "../common/connectionbase.h"
@@ -12,6 +13,8 @@ class Connection : public ConnectionBase, public boost::enable_shared_from_this<
boost::asio::ip::tcp::socket socket;
+ boost::function<void (Message::p)> recv_callback;
+
Connection(boost::asio::io_service& io_service);
//! Callback for when data is read.
@@ -26,12 +29,18 @@ class Connection : public ConnectionBase, public boost::enable_shared_from_this<
//! 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);
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);
+
+ //! Initiates an asynchronous message receive.
+ void recv(boost::function<void (Message::p)> f);
};
#endif