From 9ff710ddf5498139ffb2606e7ffa639046660dd2 Mon Sep 17 00:00:00 2001 From: Markus Kreusch Date: Thu, 16 Nov 2017 15:29:11 +0100 Subject: [PATCH] Forcing RMI to use sotimeout set by socket factory --- .gitignore | 2 +- .../launcher/InterProcessCommunicator.java | 20 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 6ff6c8689..7051b0cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ out/ *.iml # Temporary file created by test launcher -main/launcher/ipcPort.tmp +main/launcher/.ipcPort.tmp diff --git a/main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicator.java b/main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicator.java index 1c5770189..e9108cb75 100644 --- a/main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicator.java +++ b/main/launcher/src/main/java/org/cryptomator/launcher/InterProcessCommunicator.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; +import java.net.SocketException; +import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; @@ -250,9 +252,21 @@ abstract class InterProcessCommunicator implements InterProcessCommunicationProt @Override public Socket createSocket(String host, int port) throws IOException { - Socket socket = new Socket(host, port); - socket.setSoTimeout(1000); // 1s - return socket; + return new SocketWithFixedTimeout(host, port, 1000); + } + + } + + private static class SocketWithFixedTimeout extends Socket { + + public SocketWithFixedTimeout(String host, int port, int timeoutInMs) throws UnknownHostException, IOException { + super(host, port); + super.setSoTimeout(timeoutInMs); + } + + @Override + public synchronized void setSoTimeout(int timeout) throws SocketException { + // do nothing, timeout is fixed } }