Skip to content

Commit 2599e46

Browse files
committed
step1 for fixing tcp connections delays, based on the discussion #3338
1 parent 6ad3f81 commit 2599e46

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

core/pva/src/main/java/org/epics/pva/common/SecureSockets.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,18 @@ public static ServerSocket createServerSocket(final InetSocketAddress address, f
160160
public static Socket createClientSocket(final InetSocketAddress address, final boolean tls) throws Exception
161161
{
162162
initialize();
163-
if (! tls)
164-
return new Socket(address.getAddress(), address.getPort());
163+
int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_CONN_TMO) * 1000; // Use EPICS_PVA_CONN_TMO for socket connection timeout, but at least 1 second
164+
165+
if (!tls) {
166+
Socket socket = new Socket();
167+
socket.connect(address, connection_timeout);
168+
return socket;
169+
}
165170

166171
if (tls_client_sockets == null)
167172
throw new Exception("TLS is not supported. Configure EPICS_PVA_TLS_KEYCHAIN");
168-
final SSLSocket socket = (SSLSocket) tls_client_sockets.createSocket(address.getAddress(), address.getPort());
173+
final SSLSocket socket = (SSLSocket) tls_client_sockets.createSocket();
174+
socket.connect(address, connection_timeout);
169175
socket.setEnabledProtocols(PROTOCOLS);
170176
// Handshake starts when first writing, but that might delay SSL errors, so force handshake before we use the socket
171177
socket.startHandshake();

0 commit comments

Comments
 (0)