martinzink commented on code in PR #1412:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1412#discussion_r980883708


##########
extensions/standard-processors/processors/PutUDP.cpp:
##########
@@ -107,51 +98,53 @@ void PutUDP::onTrigger(core::ProcessContext* context, 
core::ProcessSession* cons
     return;
   }
 
-  const auto nonthrowing_sockaddr_ntop = [](const sockaddr* const sa) -> 
std::string {
-    return utils::try_expression([sa] { return utils::net::sockaddr_ntop(sa); 
}).value_or("(n/a)");
+  asio::io_context io_context;
+
+  const auto resolve_hostname = [&io_context, &hostname, &port]() -> 
nonstd::expected<udp::resolver::results_type, std::error_code> {
+    udp::resolver resolver(io_context);
+    std::error_code error_code;
+    auto resolved_query = resolver.resolve(hostname, port, error_code);
+    if (error_code)
+      return nonstd::make_unexpected(error_code);
+    return resolved_query;
   };
 
-  const auto debug_log_resolved_names = [&, this](const addrinfo& names) -> 
decltype(auto) {
-    if (logger_->should_log(core::logging::LOG_LEVEL::debug)) {
-      std::vector<std::string> names_vector;
-      for (const addrinfo* it = &names; it; it = it->ai_next) {
-        names_vector.push_back(nonthrowing_sockaddr_ntop(it->ai_addr));
+  const auto send_data_to_endpoint = [&io_context, &data, &logger = 
this->logger_](const udp::resolver::results_type& resolved_query) -> 
nonstd::expected<void, std::error_code> {
+    std::error_code error;
+    for (const auto& resolver_entry : resolved_query) {
+      error.clear();
+      udp::socket socket(io_context);
+      socket.open(resolver_entry.endpoint().protocol(), error);
+      if (error) {
+        logger->log_debug("opening %s socket failed due to %s ", 
resolver_entry.endpoint().protocol() == udp::v4() ? "IPv4" : "IPv6", 
error.message());
+        continue;
       }
-      logger_->log_debug("resolved \'%s\' to: %s",
-          hostname,
-          names_vector | ranges::views::join(',') | ranges::to<std::string>());
+      socket.send_to(asio::buffer(data.buffer), resolver_entry.endpoint(), 
udp::socket::message_flags{}, error);
+      if (error) {
+        core::logging::LOG_DEBUG(logger) << "sending to endpoint " << 
resolver_entry.endpoint() << " failed due to " << error.message();

Review Comment:
   As long as we succeed to send to one resolved endpoint, I don't think we 
need to handle these as warnings or errors, since this can happen during normal 
operation. (and the last error will be logged as error)
   
   I've added the success logging in 
https://github.com/apache/nifi-minifi-cpp/pull/1412/commits/3caa5a47fc16dc44dddc298c7f3d20b33fefe6f7
 and 
https://github.com/apache/nifi-minifi-cpp/pull/1412/commits/64dfce35ea2b477ecd8695bd868b184da9696512



-- 
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

Reply via email to