From 7eb1191a1d9c14775b4c498cbc4c9eb5e9b98f37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sat, 3 Dec 2016 23:27:36 +0100 Subject: [PATCH] completed TODO: handshaking messages are now handled by receive policy --- chat_networking.hpp | 13 +++++++------ check_policy.hpp | 9 ++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/chat_networking.hpp b/chat_networking.hpp index 276255c..0751c25 100644 --- a/chat_networking.hpp +++ b/chat_networking.hpp @@ -22,7 +22,8 @@ namespace chat static void message_do_what(chat_message msg) { std::cout << msg << '\n'; } - // TODO: handshake_policy + static void handshake_do_what(chat_message msg) + { message_do_what(msg); } }; @@ -109,11 +110,11 @@ namespace chat _os << chat_message(message::PASSW, _login); asio::write(_socket, _osb); // handshake is handled synchronously - // TODO: do something with these couts (decide whether to display this or not) - std::cout << receive_message_sync() << '\n'; - std::cout << receive_message_sync() << '\n'; - std::cout << receive_message_sync() << '\n'; - std::cout << receive_message_sync() << '\n'; + std::string data; + for (int i = 0; i < 4; ++i) // hello + 3 responses for messages above + data += receive_message_sync() += '\n'; + + receive_policy::handshake_do_what(chat_message(message::SERVER_DIRECTION, data)); receive(); // then flow goes to receive-loop } diff --git a/check_policy.hpp b/check_policy.hpp index 201c2ad..cf112ac 100644 --- a/check_policy.hpp +++ b/check_policy.hpp @@ -6,7 +6,8 @@ /* SFINAE compile-type checker for receive policies (as defined in chat_networking.hpp) * it checks whether PolicyCandidate supplies all of the following methods: - * - void message_do_what(chat_message) */ + * - void message_do_what(chat_message) + * - void handshake_do_what(chat_message) */ template struct is_valid_policy : std::false_type {}; @@ -20,5 +21,11 @@ struct is_valid_policy< ::message_do_what(std::declval())), void >::value + && + std::is_same< + decltype(PolicyCandidate + ::handshake_do_what(std::declval())), + void + >::value >::type> : std::true_type {}; \ No newline at end of file