|
28 | 28 | import java.net.SocketOption;
|
29 | 29 |
|
30 | 30 | import static com.mongodb.internal.connection.SslHelper.configureSslSocket;
|
31 |
| -import static java.util.concurrent.TimeUnit.MILLISECONDS; |
32 | 31 |
|
33 | 32 | @SuppressWarnings({"unchecked", "rawtypes"})
|
34 | 33 | final class SocketStreamHelper {
|
@@ -72,15 +71,18 @@ final class SocketStreamHelper {
|
72 | 71 | static void initialize(final OperationContext operationContext, final Socket socket,
|
73 | 72 | final InetSocketAddress inetSocketAddress, final SocketSettings settings,
|
74 | 73 | final SslSettings sslSettings) throws IOException {
|
75 |
| - configureSocket(socket, settings); |
| 74 | + configureSocket(socket, operationContext, settings); |
76 | 75 | configureSslSocket(socket, sslSettings, inetSocketAddress);
|
77 | 76 | socket.connect(inetSocketAddress, operationContext.getTimeoutContext().getConnectTimeoutMs());
|
78 | 77 | }
|
79 | 78 |
|
80 |
| - static void configureSocket(final Socket socket, final SocketSettings settings) throws SocketException { |
| 79 | + static void configureSocket(final Socket socket, final OperationContext operationContext, final SocketSettings settings) throws SocketException { |
81 | 80 | socket.setTcpNoDelay(true);
|
82 |
| - socket.setSoTimeout(settings.getReadTimeout(MILLISECONDS)); |
83 | 81 | socket.setKeepAlive(true);
|
| 82 | + int readTimeoutMS = (int) operationContext.getTimeoutContext().getReadTimeoutMS(); |
| 83 | + if (readTimeoutMS > 0) { |
| 84 | + socket.setSoTimeout(readTimeoutMS); |
| 85 | + } |
84 | 86 |
|
85 | 87 | // Adding keep alive options for users of Java 11+. These options will be ignored for older Java versions.
|
86 | 88 | setExtendedSocketOptions(socket);
|
|
0 commit comments