protected void connectSocket(
            final Socket sock,
            final InetSocketAddress remoteAddress,
            final Timeout connectTimeout,
            final HttpContext context) throws IOException {
        Args.notNull(sock, "Socket");
        Args.notNull(remoteAddress, "Remote address");
        if (LOG.isDebugEnabled()) {
            LOG.debug("Connecting socket to {} with timeout {}", remoteAddress, connectTimeout);
        }
        // Run this under a doPrivileged to support lib users that run under a SecurityManager this allows granting connect permissions
        // only to this library
        try {
            AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
                sock.connect(remoteAddress, Timeout.defaultsToDisabled(connectTimeout).toMillisecondsIntBound());
                return null;
            });
        } catch (final PrivilegedActionException e) {
            Asserts.check(e.getCause() instanceof IOException,
                    "method contract violation only checked exceptions are wrapped: " + e.getCause());
            // only checked exceptions are wrapped - error and RTExceptions are rethrown by doPrivileged
            throw (IOException) e.getCause();
        }
    }
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