32
32
import java .net .Proxy ;
33
33
import java .net .Socket ;
34
34
import java .net .SocketAddress ;
35
- import java .net .SocketException ;
36
35
import java .nio .file .Path ;
37
36
import java .util .Collections ;
38
37
import java .util .List ;
59
58
import org .apache .hc .core5 .http .io .SocketConfig ;
60
59
import org .apache .hc .core5 .http .protocol .HttpContext ;
61
60
import org .apache .hc .core5 .io .Closer ;
61
+ import org .apache .hc .core5 .io .SocketSupport ;
62
62
import org .apache .hc .core5 .net .NamedEndpoint ;
63
63
import org .apache .hc .core5 .util .Args ;
64
64
import org .apache .hc .core5 .util .TimeValue ;
@@ -299,7 +299,7 @@ private void connectToUnixDomainSocket(
299
299
}
300
300
301
301
private static void configureSocket (final Socket socket , final SocketConfig socketConfig ,
302
- final Timeout soTimeout ) throws SocketException {
302
+ final Timeout soTimeout ) throws IOException {
303
303
if (soTimeout != null ) {
304
304
socket .setSoTimeout (soTimeout .toMillisecondsIntBound ());
305
305
}
@@ -317,6 +317,15 @@ private static void configureSocket(final Socket socket, final SocketConfig sock
317
317
if (linger >= 0 ) {
318
318
socket .setSoLinger (true , linger );
319
319
}
320
+ if (socketConfig .getTcpKeepIdle () > 0 ) {
321
+ SocketSupport .setOption (socket , SocketSupport .TCP_KEEPIDLE , socketConfig .getTcpKeepIdle ());
322
+ }
323
+ if (socketConfig .getTcpKeepInterval () > 0 ) {
324
+ SocketSupport .setOption (socket , SocketSupport .TCP_KEEPINTERVAL , socketConfig .getTcpKeepInterval ());
325
+ }
326
+ if (socketConfig .getTcpKeepCount () > 0 ) {
327
+ SocketSupport .setOption (socket , SocketSupport .TCP_KEEPCOUNT , socketConfig .getTcpKeepCount ());
328
+ }
320
329
}
321
330
322
331
@ Override
0 commit comments