}
SocketFactory sf = null;
LayeredSocketFactory layeredsf = null;
Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
sf = schm.getSocketFactory();
if (sf instanceof LayeredSocketFactory) {
layeredsf = (LayeredSocketFactory) sf;
sf = PlainSocketFactory.getSocketFactory();
}
InetAddress[] addresses = InetAddress.getAllByName(target.getHostName());
for (int i = 0; i < addresses.length; i++) {
InetAddress address = addresses[i];
boolean last = i == addresses.length - 1;
Socket sock = sf.createSocket();
conn.opening(sock, target);
try {
Socket connsock = sf.connectSocket(
sock,
address.getHostAddress(),
schm.resolvePort(target.getPort()),
local, 0, params);
if (sock != connsock) {
sock = connsock;
conn.opening(sock, target);
}
if (layeredsf != null) {
connsock = layeredsf.createSocket(
sock,
address.getHostAddress(),
schm.resolvePort(target.getPort()),
true);
if (sock != connsock) {
sock = connsock;
conn.opening(sock, target);
}