lordgamez commented on code in PR #1595:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1595#discussion_r1271906190


##########
controller/MiNiFiController.cpp:
##########
@@ -104,19 +104,18 @@ int main(int argc, char **argv) {
   log_properties->loadConfigureFile(DEFAULT_LOG_PROPERTIES_FILE);
   
minifi::core::logging::LoggerConfiguration::getConfiguration().initialize(log_properties);
 
-  std::shared_ptr<minifi::controllers::SSLContextService> secure_context;
+  minifi::controller::ControllerSocketData socket_data;
   try {
-    secure_context = getSSLContextService(configuration);
+    socket_data.ssl_context_service = getSSLContextService(configuration);
   } catch(const minifi::Exception& ex) {
     logger->log_error(ex.what());
     exit(1);
   }
   auto stream_factory_ = minifi::io::StreamFactory::getInstance(configuration);
 
-  std::string host = "localhost";
+
   std::string port_str;
   std::string ca_cert;

Review Comment:
   Updated in 45c677990eeb0cb223814b3c55d37e84711a9b03



##########
controller/MiNiFiController.cpp:
##########
@@ -171,84 +168,72 @@ int main(int argc, char **argv) {
     if (result.count("stop") > 0) {
       auto& components = result["stop"].as<std::vector<std::string>>();
       for (const auto& component : components) {
-        auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
-        if (minifi::controller::stopComponent(std::move(socket), component))
+        if (minifi::controller::stopComponent(socket_data, component))
           std::cout << component << " requested to stop" << std::endl;
         else
-          std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
+          std::cout << "Could not connect to remote host " << socket_data.host 
<< ":" << socket_data.port << std::endl;
       }
     }
 
     if (result.count("start") > 0) {
       auto& components = result["start"].as<std::vector<std::string>>();
       for (const auto& component : components) {
-        auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context) : 
stream_factory_->createSocket(host, port);
-        if (minifi::controller::startComponent(std::move(socket), component))
+        if (minifi::controller::startComponent(socket_data, component))
           std::cout << component << " requested to start" << std::endl;
         else
-          std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
+          std::cout << "Could not connect to remote host " << socket_data.host 
<< ":" << socket_data.port << std::endl;
       }
     }
 
     if (result.count("c") > 0) {
       auto& components = result["c"].as<std::vector<std::string>>();
       for (const auto& connection : components) {
-        auto socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context)
-                                                : 
stream_factory_->createSocket(host, port);
-        if (minifi::controller::clearConnection(std::move(socket), 
connection)) {
+        if (minifi::controller::clearConnection(socket_data, connection)) {
           std::cout << "Sent clear command to " << connection << ". Size 
before clear operation sent: " << std::endl;
-          socket = secure_context != nullptr ? 
stream_factory_->createSecureSocket(host, port, secure_context)
-                                             : 
stream_factory_->createSocket(host, port);
-          if (minifi::controller::getConnectionSize(std::move(socket), 
std::cout, connection) < 0)
-            std::cout << "Could not connect to remote host " << host << ":" << 
port << std::endl;
+          if (!minifi::controller::getConnectionSize(socket_data, std::cout, 
connection))
+            std::cout << "Could not connect to remote host " << 
socket_data.host << ":" << socket_data.port << std::endl;

Review Comment:
   Good point, I think it was supposed to give information of the current 
connection size before clearing it, but it is done after the command is sent 
and processed so it will always show 0. I think it's unnecessary so I removed 
it in 45c677990eeb0cb223814b3c55d37e84711a9b03



##########
libminifi/include/io/AsioStream.h:
##########
@@ -0,0 +1,92 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "BaseStream.h"
+#include "core/logging/LoggerFactory.h"
+#include "asio/ts/internet.hpp"
+#include "asio/read.hpp"
+#include "asio/write.hpp"
+#include "io/validation.h"
+
+namespace org::apache::nifi::minifi::io {
+
+template<typename AsioSocketStreamType>
+class AsioStream : public io::BaseStream {
+ public:
+  explicit AsioStream(AsioSocketStreamType&& stream) : 
stream_(std::move(stream)) {}
+
+  /**
+   * Reads data and places it into buf
+   * @param buf buffer in which we extract data
+   * @param buflen
+   */

Review Comment:
   Removed comment in 45c677990eeb0cb223814b3c55d37e84711a9b03



##########
libminifi/include/io/AsioStream.h:
##########
@@ -0,0 +1,92 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+#include <memory>
+#include <utility>
+
+#include "BaseStream.h"
+#include "core/logging/LoggerFactory.h"
+#include "asio/ts/internet.hpp"
+#include "asio/read.hpp"
+#include "asio/write.hpp"
+#include "io/validation.h"
+
+namespace org::apache::nifi::minifi::io {
+
+template<typename AsioSocketStreamType>
+class AsioStream : public io::BaseStream {
+ public:
+  explicit AsioStream(AsioSocketStreamType&& stream) : 
stream_(std::move(stream)) {}
+
+  /**
+   * Reads data and places it into buf
+   * @param buf buffer in which we extract data
+   * @param buflen
+   */
+  size_t read(std::span<std::byte> buf) override;
+
+  /**
+   * writes value to stream
+   * @param value value to write
+   * @param size size of value
+   */

Review Comment:
   Updated parameter names in 45c677990eeb0cb223814b3c55d37e84711a9b03



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