public NioSslEngine handshakeSSLSocketChannel(SocketChannel socketChannel,
      SSLEngine engine,
      int timeout,
      ByteBuffer peerNetBuffer,
      BufferPool bufferPool)
      throws IOException {
    while (!socketChannel.finishConnect()) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        if (!socketChannel.socket().isClosed()) {
          socketChannel.close();
        }
        throw new IOException("Interrupted while performing handshake", e);
      }
    }

    NioSslEngine nioSslEngine = new NioSslEngine(engine, bufferPool);

    boolean blocking = socketChannel.isBlocking();
    if (blocking) {
      socketChannel.configureBlocking(false);
    }

    try {
      nioSslEngine.handshake(socketChannel, timeout, peerNetBuffer);
    } catch (SSLException e) {
      if (!socketChannel.socket().isClosed()) {
        socketChannel.close();
      }
      logger.warn("SSL handshake exception", e);
      throw e;
    } finally {
      if (blocking) {
        try {
          socketChannel.configureBlocking(true);
        } catch (IOException ignored) {
          // problem setting the socket back to blocking mode but the socket's going to be closed
        }
      }
    }
    return nioSslEngine;
  }
@see <a href=
     "https://docs.oracle.com/javase/8/docs/technotes/guides/security/jsse/JSSERefGuide.html#SSLENG">JSSE
     Reference Guide</a>

@param socketChannel the socket's NIO channel
@param engine the sslEngine (see createSSLEngine)
@param timeout handshake timeout in milliseconds. No timeout if <= 0
@param peerNetBuffer the buffer to use in reading data from socketChannel. This should also be
       used in subsequent I/O operations
@return The SSLEngine to be used in processing data for sending/receiving from the channel
geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java