private HttpClientConnection createConnection()

in httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java [242:293]


    private HttpClientConnection createConnection(final Socket sock, final HttpHost targetHost) throws IOException {
        sock.setSoTimeout(socketConfig.getSoTimeout().toMillisecondsIntBound());
        sock.setReuseAddress(socketConfig.isSoReuseAddress());
        sock.setTcpNoDelay(socketConfig.isTcpNoDelay());
        sock.setKeepAlive(socketConfig.isSoKeepAlive());
        if (socketConfig.getRcvBufSize() > 0) {
            sock.setReceiveBufferSize(socketConfig.getRcvBufSize());
        }
        if (socketConfig.getSndBufSize() > 0) {
            sock.setSendBufferSize(socketConfig.getSndBufSize());
        }
        if (this.socketConfig.getTcpKeepIdle() > 0) {
            SocketSupport.setOption(sock, SocketSupport.TCP_KEEPIDLE, this.socketConfig.getTcpKeepIdle());
        }
        if (this.socketConfig.getTcpKeepInterval() > 0) {
            SocketSupport.setOption(sock, SocketSupport.TCP_KEEPINTERVAL, this.socketConfig.getTcpKeepInterval());
        }
        if (this.socketConfig.getTcpKeepCount() > 0) {
            SocketSupport.setOption(sock, SocketSupport.TCP_KEEPCOUNT, this.socketConfig.getTcpKeepCount());
        }
        final int linger = socketConfig.getSoLinger().toMillisecondsIntBound();
        if (linger >= 0) {
            sock.setSoLinger(true, linger);
        }

        final InetSocketAddress targetAddress = addressResolver.resolve(targetHost);
        sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisecondsIntBound());
        if (URIScheme.HTTPS.same(targetHost.getSchemeName())) {
            final SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
                    sock, targetHost.getHostName(), targetAddress.getPort(), false);
            if (this.sslSetupHandler != null) {
                final SSLParameters sslParameters = sslSocket.getSSLParameters();
                this.sslSetupHandler.execute(sslParameters);
                sslSocket.setSSLParameters(sslParameters);
            }
            try {
                sslSocket.startHandshake();
                final SSLSession session = sslSocket.getSession();
                if (session == null) {
                    throw new SSLHandshakeException("SSL session not available");
                }
                if (sslSessionVerifier != null) {
                    sslSessionVerifier.verify(targetHost, session);
                }
                return connectFactory.createConnection(sslSocket, sock);
            } catch (final IOException ex) {
                Closer.closeQuietly(sslSocket);
                throw ex;
            }
        }
        return connectFactory.createConnection(sock);
    }