if (sf == null) {
sf = PlainSocketFactory.INSTANCE;
}
Asserts.check(sf instanceof LayeredConnectionSocketFactory,
"Socket factory must implement LayeredConnectionSocketFactory");
final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
Socket sock = conn.getSocket();
try {
final int port = this.schemePortResolver.resolve(host);
sock = lsf.createLayeredSocket(sock, host.getHostName(), port, context);
} catch (final ConnectException ex) {
throw new HttpHostConnectException(host, ex);
}
conn.bind(sock);
}