From 004d962d7181f658044aca4712f687cae0b25546 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 14 Oct 2014 12:26:29 +0000 Subject: [PATCH] Fixes a failure to detect end-of-stream/socket closed condition. De-registers channels from the selector when they time-out. --- .../harvest/MultiplexingTcpHostHarvester.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java b/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java index 59bdfa9..0c1aa39 100644 --- a/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java +++ b/src/org/ice4j/ice/harvest/MultiplexingTcpHostHarvester.java @@ -966,7 +966,16 @@ public class MultiplexingTcpHostHarvester { i.remove(); logger.info("Read timeout for socket: " - + channelDesc.channel); + + channelDesc.channel.socket()); + + // De-register from the selector + for (SelectionKey key : readSelector.keys()) + { + if (key.channel().equals(channelDesc.channel)) + { + key.cancel(); + } + } try { @@ -1156,7 +1165,10 @@ public class MultiplexingTcpHostHarvester try { - channel.channel.read(channel.buffer); + if (channel.channel.read(channel.buffer) == -1) + { + throw new IOException("Socket closed."); + } if (!channel.buffer.hasRemaining()) {