@Override
    public Socket createLayeredSocket(
            final Socket socket,
            final String target,
            final int port,
            final Object attachment,
            final HttpContext context) throws IOException {
        final SSLSocket sslsock = (SSLSocket) this.socketFactory.createSocket(
                socket,
                target,
                port,
                true);
        executeHandshake(sslsock, target, attachment, context);
        return sslsock;
    }
Connects the socket to the target host with the given resolved remote address using
{@link Socket#connect(SocketAddress, int)}. This method may be overridden to customize
how precisely {@link Socket#connect(SocketAddress, int)} is handled without impacting
other connection establishment code within {@link #executeHandshake(SSLSocket, String, Object, HttpContext)},
for example.

@param sock the socket to connect.
@param remoteAddress the resolved remote address to connect to.
@param connectTimeout connect timeout.
@param context the actual HTTP context.
@throws IOException if an I/O error occurs
httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java