aboutsummaryrefslogtreecommitdiff
path: root/node/node.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-08-31 11:57:15 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-08-31 11:57:15 +0200
commit2f1c3293d2c5776c4ecd9b2f1dce66492b15dbdd (patch)
tree1c582e4c5715a93c493582b1e01e51bc960d56c0 /node/node.cpp
parent1525c5defe3db08c765477003be73c68bb2c3cb7 (diff)
downloadcmix-2f1c3293d2c5776c4ecd9b2f1dce66492b15dbdd.tar.gz
cmix-2f1c3293d2c5776c4ecd9b2f1dce66492b15dbdd.tar.bz2
cmix-2f1c3293d2c5776c4ecd9b2f1dce66492b15dbdd.zip
Split up the client and server parts in a separate network library
Diffstat (limited to 'node/node.cpp')
-rw-r--r--node/node.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/node/node.cpp b/node/node.cpp
new file mode 100644
index 0000000..497a920
--- /dev/null
+++ b/node/node.cpp
@@ -0,0 +1,21 @@
+#include "node.hpp"
+
+Node::Node(ListenSettings const& listen_settings)
+: io_service()
+, server(io_service, listen_settings, [this](boost::asio::ip::tcp::socket&& socket){accept_handler(std::move(socket));})
+, clients()
+{}
+
+void Node::accept_handler(boost::asio::ip::tcp::socket&& socket)
+{
+ clients.emplace_back(std::move(socket));
+
+ auto it = --clients.end();
+ clients.back().on_done(
+ [this, it]() {
+ clients.erase(it);
+ }
+ );
+
+ clients.back().receive();
+}