szaszm commented on code in PR #1457:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1457#discussion_r1067173950


##########
libminifi/test/Utils.h:
##########
@@ -183,33 +188,57 @@ bool sendMessagesViaSSL(const 
std::vector<std::string_view>& contents,
   asio::error_code err;
   socket.lowest_layer().connect(remote_endpoint, err);
   if (err) {
-    return false;
+    return err;
   }
   socket.handshake(asio::ssl::stream_base::client, err);
   if (err) {
-    return false;
+    return 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;
+      return err;
     }
   }
-  return true;
+  return std::error_code();
 }
 
 #ifdef WIN32
 inline std::error_code hide_file(const std::filesystem::path& file_name) {
-    const bool success = SetFileAttributesA(file_name.string().c_str(), 
FILE_ATTRIBUTE_HIDDEN);
-    if (!success) {
-      // note: All possible documented error codes from GetLastError are in 
[0;15999] at the time of writing.
-      // The below casting is safe in [0;std::numeric_limits<int>::max()], int 
max is guaranteed to be at least 32767
-      return { static_cast<int>(GetLastError()), std::system_category() };
-    }
-    return {};
+  const bool success = SetFileAttributesA(file_name.string().c_str(), 
FILE_ATTRIBUTE_HIDDEN);
+  if (!success) {
+    // note: All possible documented error codes from GetLastError are in 
[0;15999] at the time of writing.
+    // The below casting is safe in [0;std::numeric_limits<int>::max()], int 
max is guaranteed to be at least 32767
+    return { static_cast<int>(GetLastError()), std::system_category() };
   }
+  return {};
+}
 #endif /* WIN32 */
 
+template<typename T>
+concept DerivedFromProcessor = std::derived_from<T, minifi::core::Processor>;  
// NOLINT(readability/braces)
+
+template<typename T>
+concept HasPortProperty = requires(T x) { {T::Port} -> 
std::convertible_to<core::Property>; };  // NOLINT(readability/braces)
+
+template<typename T>
+concept HasGetPortFn = requires(T x) { {x.getPort()} -> 
std::convertible_to<uint16_t>; };  // NOLINT(readability/braces)
+
+template<class T>
+requires DerivedFromProcessor<T> && HasPortProperty<T> && HasGetPortFn<T>
+uint16_t scheduleProcessorOnRandomPort(const std::shared_ptr<TestPlan>& 
test_plan, const std::shared_ptr<T>& processor) {

Review Comment:
   I wouldn't extract DerivedFromProcessor, since it's not much shorter and 
saying the same thing. The other two are fine as implementation details, but I 
would hide them in a detail namespace.
   
   One useful concept could be the combination of these, as a way to describe 
networking processors.
   ```suggestion
   // NOLINTBEGIN(readability/braces): clang-tidy doesn't play well with 
concepts
   template<typename T>
   concept NetworkingProcessor = std::derived_from<T, minifi::core::Processor>
       && requires(T x) {
         {T::Port} -> std::convertible_to<core::Property>;
         {x.getPort()} -> std::convertible_to<uint16_t>;
       };
   // NOLINTEND(readability/braces)
   
   template<NetworkingProcessor T>
   uint16_t scheduleProcessorOnRandomPort(const std::shared_ptr<TestPlan>& 
test_plan, const std::shared_ptr<T>& processor) {
   ```



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

Reply via email to