diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-08-31 11:57:15 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-08-31 11:57:15 +0200 |
| commit | 2f1c3293d2c5776c4ecd9b2f1dce66492b15dbdd (patch) | |
| tree | 1c582e4c5715a93c493582b1e01e51bc960d56c0 /node | |
| parent | 1525c5defe3db08c765477003be73c68bb2c3cb7 (diff) | |
| download | cmix-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')
| -rw-r--r-- | node/CMakeLists.txt | 18 | ||||
| -rw-r--r-- | node/main.cpp | 4 | ||||
| -rw-r--r-- | node/node.cpp | 21 | ||||
| -rw-r--r-- | node/node.hpp | 21 |
4 files changed, 64 insertions, 0 deletions
diff --git a/node/CMakeLists.txt b/node/CMakeLists.txt new file mode 100644 index 0000000..895cfb2 --- /dev/null +++ b/node/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package(Boost COMPONENTS system program_options REQUIRED) + +add_executable(node + main.cpp + node.hpp node.cpp +) + +target_compile_options(node + PRIVATE "-std=c++11" +) + +target_link_libraries(node + PRIVATE Boost::boost + PRIVATE Boost::program_options + PRIVATE Boost::system + PRIVATE cmix + PRIVATE cmix-network +) diff --git a/node/main.cpp b/node/main.cpp new file mode 100644 index 0000000..970e150 --- /dev/null +++ b/node/main.cpp @@ -0,0 +1,4 @@ + +int main() { + +} 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(); +} diff --git a/node/node.hpp b/node/node.hpp new file mode 100644 index 0000000..7d30188 --- /dev/null +++ b/node/node.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "server.hpp" +#include "nodeclient.hpp" + +#include <boost/asio/io_service.hpp> + +#include <list> + +class Node +{ + boost::asio::io_service io_service; + Server server; + std::list<NodeClient> clients; + + void accept_handler(boost::asio::ip::tcp::socket&& socket); + +public: + Node(ListenSettings const& listen_settings); +}; + |
