Ignore socket timeout in read which occurs if we have set the timeout to > 0. We should continue reading from the stream unless the reader is interrupted. Note that with the default timeout set to 0, the reader thread will never return.

This commit is contained in:
David Kocher
2014-05-16 22:21:00 +02:00
parent 9297338195
commit f2ebbe288f

View File

@@ -40,6 +40,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.InputStream; import java.io.InputStream;
import java.net.SocketTimeoutException;
public final class Reader public final class Reader
extends Thread { extends Thread {
@@ -65,13 +66,21 @@ public final class Reader
int needed = 1; int needed = 1;
while (!isInterrupted()) { while (!isInterrupted()) {
int read = inp.read(recvbuf, 0, needed); int read;
try {
read = inp.read(recvbuf, 0, needed);
}
catch(SocketTimeoutException e) {
if (isInterrupted()) {
throw e;
}
continue;
}
if (read == -1) if (read == -1)
throw new TransportException("Broken transport; encountered EOF"); throw new TransportException("Broken transport; encountered EOF");
else else
needed = decoder.received(recvbuf, read); needed = decoder.received(recvbuf, read);
} }
} catch (Exception e) { } catch (Exception e) {
if (isInterrupted()) { if (isInterrupted()) {
// We are meant to shut up and draw to a close if interrupted // We are meant to shut up and draw to a close if interrupted