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


##########
libminifi/include/core/state/nodes/DeviceInformation.h:
##########


Review Comment:
   It would be nice to move the logic to the .cpp file, and avoid polluting 
other translation units with windows and other heavyweight headers.



##########
libminifi/include/utils/net/AsioSocketUtils.h:
##########
@@ -61,6 +62,64 @@ asio::awaitable<std::tuple<std::error_code>> 
handshake(SslSocket& socket, asio::
 
 
 asio::ssl::context getSslContext(const controllers::SSLContextService& 
ssl_context_service, asio::ssl::context::method ssl_context_method = 
asio::ssl::context::tls_client);
+
+struct SocketData {
+  std::string host = "localhost";
+  int port = -1;
+  std::shared_ptr<minifi::controllers::SSLContextService> ssl_context_service;
+};
+
+class AsioSocketConnection : public io::BaseStream {
+ public:
+  explicit AsioSocketConnection(SocketData socket_data);
+  int initialize() override;
+  size_t read(gsl::span<std::byte> out_buffer) override {
+    gsl_Expects(stream_);
+    return stream_->read(out_buffer);
+  }
+  size_t write(const uint8_t *value, size_t len) override {
+    gsl_Expects(stream_);
+    return stream_->write(value, len);
+  }
+
+  void setInterface(const std::string& local_network_interface) {
+    local_network_interface_ = local_network_interface;
+  }
+
+ private:
+  template<typename SocketType>
+  bool bindToLocalInterface(SocketType& socket) {
+    if (local_network_interface_.empty()) {
+      return true;
+    }
+
+    asio::ip::tcp::endpoint 
local_endpoint(asio::ip::address::from_string(local_network_interface_), 0);
+    asio::error_code err;
+    socket.open(local_endpoint.protocol(), err);
+    if (err) {
+      logger_->log_error("Failed to open socket on network interface '%s' with 
the following message: '%s'", local_network_interface_, err.message());
+      return false;
+    }
+    socket.set_option(asio::ip::tcp::socket::reuse_address(true));
+    socket.bind(local_endpoint, err);
+    if (err) {
+      logger_->log_error("Failed to bind to network interface '%s' with the 
following message: '%s'", local_network_interface_, err.message());
+      return false;
+    }
+
+    return true;
+  }
+
+  bool connectTcpSocketOverSsl();
+  bool connectTcpSocket();
+
+  asio::io_context io_context_;

Review Comment:
   The old stream factory could maybe be used to inject a common `io_context`, 
instead of spawning up unique threads for every single connection.



##########
libminifi/src/utils/net/DNS.cpp:
##########
@@ -15,85 +15,20 @@
  * limitations under the License.
  */
 #include "utils/net/DNS.h"
+
+#ifndef WIN32
+#include <cstring>
+#endif /* WIN32 */
+

Review Comment:
   What is this used for?



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