szaszm commented on code in PR #1412:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1412#discussion_r980099597
##########
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;
Review Comment:
Just a naming nitpick: a "resolved query" is not a query anymore, but a list
of names. They are called "results" in the return type, which is also valid.
##########
extensions/standard-processors/tests/unit/ListenSyslogTests.cpp:
##########
@@ -197,21 +197,10 @@ constexpr std::string_view rfc5424_logger_example_1 =
R"(<13>1 2022-03-17T10:10:
constexpr std::string_view invalid_syslog = "not syslog";
-void sendUDPPacket(const std::string_view content, uint64_t port) {
- asio::io_context io_context;
- asio::ip::udp::socket socket(io_context);
- asio::ip::udp::endpoint
remote_endpoint(asio::ip::address::from_string("127.0.0.1"), port);
- socket.open(asio::ip::udp::v4());
- std::error_code err;
- socket.send_to(asio::buffer(content, content.size()), remote_endpoint, 0,
err);
- REQUIRE(!err);
- socket.close();
-}
-
void check_for_only_basic_attributes(core::FlowFile& flow_file, uint16_t port,
std::string_view protocol) {
CHECK(std::to_string(port) == flow_file.getAttribute("syslog.port"));
CHECK(protocol == flow_file.getAttribute("syslog.protocol"));
- CHECK("127.0.0.1" == flow_file.getAttribute("syslog.sender"));
+ CHECK(("::ffff:127.0.0.1" == flow_file.getAttribute("syslog.sender") ||
"::1" == flow_file.getAttribute("syslog.sender")));
Review Comment:
I would add back the IPv4 non-mapped address as well, so that the test can
run on boxes with IPv6 disabled as well.
```suggestion
const auto local_addresses = {"127.0.0.1", "::ffff:127.0.0.1", "::1"};
CHECK(std::find(std::begin(local_addresses), std::end(local_addresses),
flow_file.getAttribute("syslog.sender") != std::end(local_addresses));
```
or
```suggestion
const auto local_addresses = {"127.0.0.1", "::ffff:127.0.0.1", "::1"};
CHECK(ranges::contains(local_addresses,
flow_file.getAttribute("syslog.sender")));
```
##########
libminifi/test/Utils.h:
##########
@@ -111,24 +111,39 @@ 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) {
+ return false;
+ }
}
- if (err) {
- return false;
- }
- socket.close();
return true;
}
+bool sendUDPPacket(const std::string_view content, const
asio::ip::udp::endpoint& remote_endpoint) {
Review Comment:
I would rename this to `sendUdpDatagram`, since the PDU of UDP is called
datagram. Also, the content is perfect candidate for a byte span, since it
doesn't necessarily have to be text. I would add a delegating overload, but
keep the string_view version as well, for convenience when used with text.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]