diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-05 12:56:52 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-05 14:12:28 +0200 |
| commit | 88c5130eccd06e63ffca732626c0fb59426743a7 (patch) | |
| tree | f9c7c4536bfa50057269c3636baedea3cb859ac1 /libcmix-network | |
| parent | edc3690d62890449df3ae4c14636019bce4833f1 (diff) | |
| download | cmix-88c5130eccd06e63ffca732626c0fb59426743a7.tar.gz cmix-88c5130eccd06e63ffca732626c0fb59426743a7.tar.bz2 cmix-88c5130eccd06e63ffca732626c0fb59426743a7.zip | |
Seperates Nodes and Clients for incoming connections.
Created a PrevNode class to reflect the seperation.
Made Client movable.
Added 2 empty protobuf message that declare what each connecting client
is, sent when connected to a node.
Diffstat (limited to 'libcmix-network')
| -rw-r--r-- | libcmix-network/client.cpp | 10 | ||||
| -rw-r--r-- | libcmix-network/client.hpp | 12 |
2 files changed, 16 insertions, 6 deletions
diff --git a/libcmix-network/client.cpp b/libcmix-network/client.cpp index 7c95234..9293bd1 100644 --- a/libcmix-network/client.cpp +++ b/libcmix-network/client.cpp @@ -16,7 +16,7 @@ using namespace boost::system; Client::Client(tcp::socket &&socket) : socket(std::move(socket)) -, buffer() +, buffer(new boost::asio::streambuf()) , done() {} @@ -61,8 +61,8 @@ void Client::send(std::string message) { std::vector<uint8_t> Client::received_bytes_to_vector(size_t read_bytes) { - buffer.commit(read_bytes); - std::istream is(&buffer); + buffer->commit(read_bytes); + std::istream is(buffer.get()); is.unsetf(std::ios::skipws); return std::vector<uint8_t>(std::istream_iterator<uint8_t>(is), {}); @@ -92,7 +92,7 @@ void Client::handle_receive_size(Client::MessageHandler message_handler, const e size = ntohl(size); socket.async_receive( - buffer.prepare(size), + buffer->prepare(size), boost::bind(&Client::handle_receive_message, this, message_handler, error(), bytes_transferred()) ); } else { @@ -107,7 +107,7 @@ void Client::receive(MessageHandler message_handler) { using namespace boost::asio::placeholders; socket.async_receive( - buffer.prepare(4), + buffer->prepare(4), boost::bind(&Client::handle_receive_size, this, message_handler, error(), bytes_transferred()) ); } diff --git a/libcmix-network/client.hpp b/libcmix-network/client.hpp index 51dfa6f..dc3787d 100644 --- a/libcmix-network/client.hpp +++ b/libcmix-network/client.hpp @@ -31,7 +31,7 @@ protected: boost::asio::ip::tcp::socket socket; private: - boost::asio::streambuf buffer; + std::unique_ptr<boost::asio::streambuf> buffer; OnDoneFT done; @@ -52,6 +52,16 @@ public: ~Client(); /*! + * \brief Move constructor for Client. + */ + Client(Client&&) = default; + + /*! + * \brief Move assignment for Client. + */ + Client& operator=(Client&&) = default; + + /*! * \brief async_connect Asynchronously connects to next_host:port and calls on_connect * \param next_host The host to connect to * \param next_port The port to connect to |
