martinzink commented on a change in pull request #978:
URL: https://github.com/apache/nifi-minifi-cpp/pull/978#discussion_r564586153



##########
File path: 
extensions/standard-processors/tests/integration/TLSServerSocketSupportedProtocolsTest.cpp
##########
@@ -0,0 +1,233 @@
+/**
+ *
+ * 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.
+ */
+#include <signal.h>
+#include <sys/stat.h>
+#include <chrono>
+#include <thread>
+#undef NDEBUG
+#include <cassert>
+#include <utility>
+#include <memory>
+#include <string>
+#ifdef WIN32
+#include <ws2tcpip.h>
+#include <winsock2.h>
+#endif
+#include "properties/Configure.h"
+#include "io/tls/TLSSocket.h"
+#include "io/tls/TLSServerSocket.h"
+
+#ifdef WIN32
+using SocketDescriptor = SOCKET;
+#else
+using SocketDescriptor = int;
+static constexpr SocketDescriptor INVALID_SOCKET = -1;
+#endif /* WIN32 */
+
+class SimpleSSLTestClient  {
+ public:
+  SimpleSSLTestClient(const SSL_METHOD* method, const std::string& host, const 
std::string& port) :
+    host_(host),
+    port_(port) {
+      ctx_ = SSL_CTX_new(method);
+      sfd_ = openConnection(host_.c_str(), port_.c_str());
+      if (ctx_ != nullptr)
+        ssl_ = SSL_new(ctx_);
+      if (ssl_ != nullptr)
+        SSL_set_fd(ssl_, sfd_);
+  }
+
+  ~SimpleSSLTestClient() {
+    SSL_free(ssl_);
+#ifdef WIN32
+    closesocket(sfd_);
+#else
+    close(sfd_);
+#endif
+    SSL_CTX_free(ctx_);
+  }
+
+  bool canConnect() {
+    const int status = SSL_connect(ssl_);
+    const bool successful_connection = (status == 1);
+    return successful_connection;
+  }
+
+ private:
+  SSL_CTX *ctx_;
+  SSL* ssl_;
+  SocketDescriptor sfd_;
+  std::string host_;
+  std::string port_;
+
+  static SocketDescriptor openConnection(const char *host_name, const char 
*port) {
+    struct hostent *host;
+    assert((host = gethostbyname(host_name)) != nullptr);
+    struct addrinfo hints = {0}, *addrs;
+    hints.ai_family = AF_UNSPEC;
+    hints.ai_socktype = SOCK_STREAM;
+    hints.ai_protocol = IPPROTO_TCP;
+    const int status = getaddrinfo(host_name, port, &hints, &addrs);
+    assert(status == 0);
+    SocketDescriptor sfd = INVALID_SOCKET;
+    for (struct addrinfo *addr = addrs; addr != nullptr; addr = addr->ai_next) 
{
+        sfd = socket(addrs->ai_family, addrs->ai_socktype, addrs->ai_protocol);
+        if (sfd == INVALID_SOCKET) {
+            continue;
+        }
+        if (connect(sfd, addr->ai_addr, addr->ai_addrlen) == 0) {
+            break;
+        }
+        sfd = INVALID_SOCKET;
+#ifdef WIN32
+        closesocket(sfd);
+#else
+        close(sfd);
+#endif

Review comment:
       Fixed the indentations, thanks for the review




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


Reply via email to