@@ -3323,11 +3323,7 @@ Response sendRequest(Request req, int con_timeout)
3323
3323
Log .write (Log .CONN , "Conn: Retrying request" );
3324
3324
continue ;
3325
3325
}
3326
- finally
3327
- {
3328
- if (sock != null ) sock .close ();
3329
- }
3330
-
3326
+
3331
3327
break ;
3332
3328
}
3333
3329
@@ -3407,39 +3403,38 @@ Response sendRequest(Request req, int con_timeout)
3407
3403
private Socket getSocket (int con_timeout ) throws IOException
3408
3404
{
3409
3405
Socket sock = null ;
3410
- try {
3411
3406
3412
- String actual_host ;
3413
- int actual_port ;
3407
+ String actual_host ;
3408
+ int actual_port ;
3414
3409
3415
- if (Proxy_Host != null )
3416
- {
3417
- actual_host = Proxy_Host ;
3418
- actual_port = Proxy_Port ;
3419
- }
3420
- else
3421
- {
3422
- actual_host = Host ;
3423
- actual_port = Port ;
3424
- }
3410
+ if (Proxy_Host != null )
3411
+ {
3412
+ actual_host = Proxy_Host ;
3413
+ actual_port = Proxy_Port ;
3414
+ }
3415
+ else
3416
+ {
3417
+ actual_host = Host ;
3418
+ actual_port = Port ;
3419
+ }
3425
3420
3426
- Log .write (Log .CONN , "Conn: Creating Socket: " + actual_host + ":" +
3421
+ Log .write (Log .CONN , "Conn: Creating Socket: " + actual_host + ":" +
3427
3422
actual_port );
3428
3423
3429
- if (con_timeout == 0 ) // normal connection establishment
3424
+ if (con_timeout == 0 ) // normal connection establishment
3425
+ {
3426
+ if (Socks_client != null )
3427
+ sock = Socks_client .getSocket (actual_host , actual_port );
3428
+ else
3430
3429
{
3431
- if ( Socks_client != null )
3432
- sock = Socks_client . getSocket (actual_host , actual_port );
3433
- else
3430
+ // try all A records
3431
+ InetAddress [] addr_list = InetAddress . getAllByName (actual_host );
3432
+ for ( int idx = 0 ; idx < addr_list . length ; idx ++)
3434
3433
{
3435
- // try all A records
3436
- InetAddress [] addr_list = InetAddress .getAllByName (actual_host );
3437
- for (int idx =0 ; idx <addr_list .length ; idx ++)
3434
+ try
3438
3435
{
3439
- try
3436
+ if ( Protocol == HTTPS )
3440
3437
{
3441
- if (Protocol == HTTPS )
3442
- {
3443
3438
//@gusbro
3444
3439
/* if (LocalAddr == null)
3445
3440
sock = new SSLSocket(addr_list[idx], actual_port,
@@ -3450,63 +3445,57 @@ private Socket getSocket(int con_timeout) throws IOException
3450
3445
ssl_ctxt);
3451
3446
((SSLSocket) sock).setAutoHandshake(false);
3452
3447
*/
3453
- if (LocalAddr == null )
3454
- sock = sslConnection .getSSLSocket (addr_list [idx ], actual_port );
3455
- else sock = sslConnection .getSSLSocket (addr_list [idx ], actual_port , LocalAddr , LocalPort );
3448
+ if (LocalAddr == null )
3449
+ sock = sslConnection .getSSLSocket (addr_list [idx ], actual_port );
3450
+ else sock = sslConnection .getSSLSocket (addr_list [idx ], actual_port , LocalAddr , LocalPort );
3456
3451
3457
- //@iroqueta
3458
- sock .setTcpNoDelay (tcpNoDelay );
3452
+ //@iroqueta
3453
+ sock .setTcpNoDelay (tcpNoDelay );
3459
3454
//@gusbro\
3460
- }
3461
- else
3462
- {
3463
- if (LocalAddr == null )
3464
- sock = new Socket (addr_list [idx ], actual_port );
3465
- else
3466
- sock = new Socket (addr_list [idx ], actual_port ,
3467
- LocalAddr , LocalPort );
3468
- //@iroqueta
3469
- sock .setTcpNoDelay (tcpNoDelay );
3470
- }
3471
- break ; // success
3472
3455
}
3473
- catch ( SocketException se )
3456
+ else
3474
3457
{
3475
- if (idx == addr_list .length -1 )
3476
- throw se ; // we tried them all
3458
+ if (LocalAddr == null )
3459
+ sock = new Socket (addr_list [idx ], actual_port );
3460
+ else
3461
+ sock = new Socket (addr_list [idx ], actual_port ,
3462
+ LocalAddr , LocalPort );
3463
+ //@iroqueta
3464
+ sock .setTcpNoDelay (tcpNoDelay );
3477
3465
}
3466
+ break ; // success
3467
+ }
3468
+ catch (SocketException se )
3469
+ {
3470
+ if (idx == addr_list .length -1 )
3471
+ throw se ; // we tried them all
3478
3472
}
3479
3473
}
3480
3474
}
3481
- else
3482
- {
3483
- EstablishConnection con =
3475
+ }
3476
+ else
3477
+ {
3478
+ EstablishConnection con =
3484
3479
new EstablishConnection (actual_host , actual_port , Socks_client );
3485
- //@iroqueta
3486
- con .setTcpNoDelay (tcpNoDelay );
3480
+ //@iroqueta
3481
+ con .setTcpNoDelay (tcpNoDelay );
3487
3482
3488
- con .start ();
3489
- try
3490
- { con .join ((long ) con_timeout ); }
3491
- catch (InterruptedException ie )
3492
- { }
3483
+ con .start ();
3484
+ try
3485
+ { con .join ((long ) con_timeout ); }
3486
+ catch (InterruptedException ie )
3487
+ { }
3493
3488
3494
- if (con .getException () != null )
3495
- throw con .getException ();
3489
+ if (con .getException () != null )
3490
+ throw con .getException ();
3491
+ if ((sock = con .getSocket ()) == null )
3492
+ {
3493
+ con .forget ();
3496
3494
if ((sock = con .getSocket ()) == null )
3497
- {
3498
- con .forget ();
3499
- if ((sock = con .getSocket ()) == null )
3500
- throw new InterruptedIOException ("Connection establishment timed out" );
3501
- }
3495
+ throw new InterruptedIOException ("Connection establishment timed out" );
3502
3496
}
3503
-
3504
- return sock ;
3505
- }
3506
- finally
3507
- {
3508
- if (sock != null ) sock .close ();
3509
3497
}
3498
+ return sock ;
3510
3499
}
3511
3500
3512
3501
0 commit comments