martinzink commented on code in PR #1412: URL: https://github.com/apache/nifi-minifi-cpp/pull/1412#discussion_r980883175
########## libminifi/test/Utils.h: ########## @@ -111,24 +111,42 @@ bool countLogOccurrencesUntil(const std::string& pattern, return false; } -bool sendMessagesViaTCP(const std::vector<std::string_view>& contents, uint64_t port) { +bool sendMessagesViaTCP(const std::vector<std::string_view>& contents, const asio::ip::tcp::endpoint& remote_endpoint) { asio::io_context io_context; asio::ip::tcp::socket socket(io_context); - asio::ip::tcp::endpoint remote_endpoint(asio::ip::address::from_string("127.0.0.1"), port); socket.connect(remote_endpoint); std::error_code err; for (auto& content : contents) { std::string tcp_message(content); tcp_message += '\n'; asio::write(socket, asio::buffer(tcp_message, tcp_message.size()), err); } - if (err) { + if (err) + return false; + socket.close(); + return true; Review Comment: Just checked and fortunetly RAII will take of everything so we dont need to manually close it anywhere. I moved the error checking inside the loop in https://github.com/apache/nifi-minifi-cpp/pull/1412/commits/3caa5a47fc16dc44dddc298c7f3d20b33fefe6f7 ########## libminifi/test/Utils.h: ########## @@ -111,24 +111,42 @@ bool countLogOccurrencesUntil(const std::string& pattern, return false; } -bool sendMessagesViaTCP(const std::vector<std::string_view>& contents, uint64_t port) { +bool sendMessagesViaTCP(const std::vector<std::string_view>& contents, const asio::ip::tcp::endpoint& remote_endpoint) { asio::io_context io_context; asio::ip::tcp::socket socket(io_context); - asio::ip::tcp::endpoint remote_endpoint(asio::ip::address::from_string("127.0.0.1"), port); socket.connect(remote_endpoint); std::error_code err; for (auto& content : contents) { std::string tcp_message(content); tcp_message += '\n'; asio::write(socket, asio::buffer(tcp_message, tcp_message.size()), err); Review Comment: You are right :+1: I moved the error checking inside the loop in https://github.com/apache/nifi-minifi-cpp/pull/1412/commits/3caa5a47fc16dc44dddc298c7f3d20b33fefe6f7 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org