arpadboda commented on a change in pull request #713: MINIFICPP-1119 unify 
win/posix sockets + clean up issues
URL: https://github.com/apache/nifi-minifi-cpp/pull/713#discussion_r374190470
 
 

 ##########
 File path: libminifi/src/io/ClientSocket.cpp
 ##########
 @@ -207,12 +209,31 @@ int8_t Socket::createConnection(const addrinfo *p, 
in_addr_t &addr) {
         } else {
           logger_->log_error("Unknown error");
         }
-
-#endif
         closeStream();
         socket_file_descriptor_ = -1;
         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) == -1) {
 
 Review comment:
   I would prefer <= 0 or != 0 checks. In case someone changes the code by 
introducing a new error this silently gets broken. 
   
   I know it's not completely new code, more like a wish to do it nicely as we 
touch. 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to