Use an unlimited read timeout for TCP sockets.

This commit is contained in:
akwizgran
2012-11-15 00:09:05 +00:00
parent e8a4d77864
commit 3e8c6081ef
2 changed files with 7 additions and 10 deletions

View File

@@ -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());
}
}
}

View File

@@ -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) {