Loading Client/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) { io_service.run(); } catch (std::exception &e) { std::cout << std::string() + "Build server exception: " + e.what() << std::endl; std::cout << std::string() + "Build exception: " + e.what() << std::endl; } std::cout << "Client shutting down\n"; Loading Common/include/Messenger.h +19 −21 Original line number Diff line number Diff line Loading @@ -18,9 +18,6 @@ namespace asio = boost::asio; using asio::ip::tcp; using receive_callback_t = std::function<void(const boost::system::error_code &ec, std::size_t size)>; using timer_callback_t = std::function<void(const boost::system::error_code &ec)>; // Enum to handle message type, used to ensure enum class MessageType : unsigned char { string, Loading Loading @@ -56,6 +53,22 @@ public: return body; } template <typename Handler> std::string async_receive(const Handler& handler, MessageType* type) { auto header = async_receive_header(handler); *type = header.type; // Read the message body asio::streambuf buffer; asio::async_read(socket, buffer, asio::transfer_exactly(header.size), handler); // Construct a string from the message body std::string body((std::istreambuf_iterator<char>(&buffer)), std::istreambuf_iterator<char>()); return body; } // TODO set chunk size to the size of the socket receive buffer? template <typename Handler> void async_receive_file(boost::filesystem::path file_path, const Handler& handler, const bool print_progress=false) { Loading Loading @@ -95,30 +108,15 @@ public: bytes_remaining -= bytes_received; if(print_progress) { ++(*progress_bar); } } while (bytes_remaining); file.close(); } // Receive a string message asynchronously template <typename Handler> std::string async_receive(const Handler& handler, MessageType* type) { auto header = async_receive_header(handler); *type = header.type; // Read the message body asio::streambuf buffer; asio::async_read(socket, buffer, asio::transfer_exactly(header.size), handler); // Construct a string from the message body std::string body((std::istreambuf_iterator<char>(&buffer)), std::istreambuf_iterator<char>()); return body; } // Send a string message asynchronously template <typename Handler> void async_send(const std::string &message, const Handler& handler, MessageType type=MessageType::string) { Loading Loading
Client/main.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) { io_service.run(); } catch (std::exception &e) { std::cout << std::string() + "Build server exception: " + e.what() << std::endl; std::cout << std::string() + "Build exception: " + e.what() << std::endl; } std::cout << "Client shutting down\n"; Loading
Common/include/Messenger.h +19 −21 Original line number Diff line number Diff line Loading @@ -18,9 +18,6 @@ namespace asio = boost::asio; using asio::ip::tcp; using receive_callback_t = std::function<void(const boost::system::error_code &ec, std::size_t size)>; using timer_callback_t = std::function<void(const boost::system::error_code &ec)>; // Enum to handle message type, used to ensure enum class MessageType : unsigned char { string, Loading Loading @@ -56,6 +53,22 @@ public: return body; } template <typename Handler> std::string async_receive(const Handler& handler, MessageType* type) { auto header = async_receive_header(handler); *type = header.type; // Read the message body asio::streambuf buffer; asio::async_read(socket, buffer, asio::transfer_exactly(header.size), handler); // Construct a string from the message body std::string body((std::istreambuf_iterator<char>(&buffer)), std::istreambuf_iterator<char>()); return body; } // TODO set chunk size to the size of the socket receive buffer? template <typename Handler> void async_receive_file(boost::filesystem::path file_path, const Handler& handler, const bool print_progress=false) { Loading Loading @@ -95,30 +108,15 @@ public: bytes_remaining -= bytes_received; if(print_progress) { ++(*progress_bar); } } while (bytes_remaining); file.close(); } // Receive a string message asynchronously template <typename Handler> std::string async_receive(const Handler& handler, MessageType* type) { auto header = async_receive_header(handler); *type = header.type; // Read the message body asio::streambuf buffer; asio::async_read(socket, buffer, asio::transfer_exactly(header.size), handler); // Construct a string from the message body std::string body((std::istreambuf_iterator<char>(&buffer)), std::istreambuf_iterator<char>()); return body; } // Send a string message asynchronously template <typename Handler> void async_send(const std::string &message, const Handler& handler, MessageType type=MessageType::string) { Loading