Skip to content

Commit 99d4a5e

Browse files
committed
HTTPCLIENT-2384: Socket options related to TcpKeepAlive are ignored
1 parent dc9d968 commit 99d4a5e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.net.Proxy;
3333
import java.net.Socket;
3434
import java.net.SocketAddress;
35-
import java.net.SocketException;
3635
import java.nio.file.Path;
3736
import java.util.Collections;
3837
import java.util.List;
@@ -59,6 +58,7 @@
5958
import org.apache.hc.core5.http.io.SocketConfig;
6059
import org.apache.hc.core5.http.protocol.HttpContext;
6160
import org.apache.hc.core5.io.Closer;
61+
import org.apache.hc.core5.io.SocketSupport;
6262
import org.apache.hc.core5.net.NamedEndpoint;
6363
import org.apache.hc.core5.util.Args;
6464
import org.apache.hc.core5.util.TimeValue;
@@ -299,7 +299,7 @@ private void connectToUnixDomainSocket(
299299
}
300300

301301
private static void configureSocket(final Socket socket, final SocketConfig socketConfig,
302-
final Timeout soTimeout) throws SocketException {
302+
final Timeout soTimeout) throws IOException {
303303
if (soTimeout != null) {
304304
socket.setSoTimeout(soTimeout.toMillisecondsIntBound());
305305
}
@@ -317,6 +317,15 @@ private static void configureSocket(final Socket socket, final SocketConfig sock
317317
if (linger >= 0) {
318318
socket.setSoLinger(true, linger);
319319
}
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+
}
320329
}
321330

322331
@Override

0 commit comments

Comments
 (0)