code: public Socket connectSocket(
          final Socket sock,
          final String host,
          final int port,
          final InetAddress localAddress,
          int localPort,
          final HttpParams params
      ) throws IOException {
  
          if (host == null) {
              throw new IllegalArgumentException("Target host may not be null.");
          }
          if (params == null) {
              throw new IllegalArgumentException("Parameters may not be null.");
          }
  
          SSLSocket sslsock = (SSLSocket)
              ((sock != null) ? sock : createSocket());
  
          if ((localAddress != null) || (localPort > 0)) {
  
              // we need to bind explicitly
              if (localPort < 0)
                  localPort = 0; // indicates "any"
  
              InetSocketAddress isa =
                  new InetSocketAddress(localAddress, localPort);
              sslsock.bind(isa);
          }
  
          int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
          int soTimeout = HttpConnectionParams.getSoTimeout(params);
  
          InetSocketAddress remoteAddress;
          if (this.nameResolver != null) {
              remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); 
          } else {
              remoteAddress = new InetSocketAddress(host, port);            
          }
          
          sslsock.connect(remoteAddress, connTimeout);
  
          sslsock.setSoTimeout(soTimeout);
          try {
              hostnameVerifier.verify(host, sslsock);
              // verifyHostName() didn't blowup - good!
          } catch (IOException iox) {
              // close the socket before re-throwing the exception
              try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
              throw iox;
          }
  
          return sslsock;
      }
docs: non-javadoc, see interface org.apache.http.conn.SocketFactory