szaszm commented on a change in pull request #713: MINIFICPP-1119 
MINIFICPP-1154 unify win/posix sockets + fix bugs
URL: https://github.com/apache/nifi-minifi-cpp/pull/713#discussion_r377283086
 
 

 ##########
 File path: libminifi/src/io/ClientSocket.cpp
 ##########
 @@ -207,10 +206,30 @@ int8_t Socket::createConnection(const addrinfo *p, 
in_addr_t &addr) {
         } else {
           logger_->log_error("Unknown error");
         }
-#endif
         closeStream();
         return -1;
       }
+#else
+      auto *sa_loc = (struct sockaddr_in*) p->ai_addr;
+      sa_loc->sin_family = AF_INET;
+      sa_loc->sin_port = htons(port_);
+      // use any address if you are connecting to the local machine for testing
+      // otherwise we must use the requested hostname
+      if (IsNullOrEmpty(requested_hostname_) || requested_hostname_ == 
"localhost") {
+        if (is_loopback_only_) {
+          sa_loc->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+        } else {
+          sa_loc->sin_addr.s_addr = htonl(INADDR_ANY);
+        }
+      } else {
+        sa_loc->sin_addr.s_addr = addr;
+      }
+      if (connect(socket_file_descriptor_, p->ai_addr, p->ai_addrlen) < 0) {
+        close(socket_file_descriptor_);
+        socket_file_descriptor_ = -1;
 
 Review comment:
   Fixed by calling `closeStream()`, like in the windows version, instead of 
close + reassign.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to