From 3e8c6081ef30696f88ea5059418816d51e90b7f1 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Thu, 15 Nov 2012 00:09:05 +0000 Subject: [PATCH] Use an unlimited read timeout for TCP sockets. --- src/net/sf/briar/plugins/tcp/LanTcpPlugin.java | 13 ++++--------- src/net/sf/briar/plugins/tcp/TcpPlugin.java | 4 +++- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java b/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java index 358bb0782e..47bf16d7ec 100644 --- a/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java +++ b/src/net/sf/briar/plugins/tcp/LanTcpPlugin.java @@ -146,6 +146,7 @@ class LanTcpPlugin extends TcpPlugin { try { // Connect back on the advertised TCP port Socket s = new Socket(packet.getAddress(), port); + s.setSoTimeout(0); return new TcpTransportConnection(s); } catch(IOException e) { if(LOG.isLoggable(WARNING)) @@ -286,7 +287,9 @@ class LanTcpPlugin extends TcpPlugin { try { int wait = (int) (Math.min(end, nextPacket) - now); ss.setSoTimeout(wait < 1 ? 1 : wait); - return new TcpTransportConnection(ss.accept()); + Socket s = ss.accept(); + s.setSoTimeout(0); + return new TcpTransportConnection(s); } catch(SocketTimeoutException e) { now = System.currentTimeMillis(); if(now < end) { @@ -310,12 +313,4 @@ class LanTcpPlugin extends TcpPlugin { } return null; } - - private void tryToClose(ServerSocket ss) { - try { - ss.close(); - } catch(IOException e) { - if(LOG.isLoggable(WARNING)) LOG.warning(e.toString()); - } - } } diff --git a/src/net/sf/briar/plugins/tcp/TcpPlugin.java b/src/net/sf/briar/plugins/tcp/TcpPlugin.java index 10c704e9be..0ca380a010 100644 --- a/src/net/sf/briar/plugins/tcp/TcpPlugin.java +++ b/src/net/sf/briar/plugins/tcp/TcpPlugin.java @@ -99,7 +99,7 @@ abstract class TcpPlugin implements DuplexPlugin { acceptContactConnections(ss); } - private void tryToClose(ServerSocket ss) { + protected void tryToClose(ServerSocket ss) { try { ss.close(); } catch(IOException e) { @@ -120,6 +120,7 @@ abstract class TcpPlugin implements DuplexPlugin { Socket s; try { s = ss.accept(); + s.setSoTimeout(0); } catch(IOException e) { // This is expected when the socket is closed if(LOG.isLoggable(INFO)) LOG.info(e.toString()); @@ -179,6 +180,7 @@ abstract class TcpPlugin implements DuplexPlugin { Socket s = new Socket(); if(addr == null || s == null) return null; try { + s.setSoTimeout(0); s.connect(addr); return new TcpTransportConnection(s); } catch(IOException e) { -- GitLab