1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-18 20:40:58 +03:00

Don't do I/O if the thread is interrupted.

(cherry picked from commit 664b65d18e)
This commit is contained in:
Jesse Wilson
2014-03-29 13:06:49 -04:00
parent 8ec7fa8cb5
commit 2133d31a5d

View File

@@ -16,6 +16,7 @@
package com.squareup.okhttp.internal.okio;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.TimeUnit;
/**
@@ -47,8 +48,11 @@ public class Deadline {
return System.nanoTime() - deadlineNanos >= 0; // Subtract to avoid overflow!
}
public void throwIfReached() throws IOException {
public final void throwIfReached() throws IOException {
// TODO: a more catchable exception type?
if (reached()) throw new IOException("Deadline reached");
// If the thread is interrupted, do not proceed with further I/O.
if (Thread.interrupted()) throw new InterruptedIOException();
}
}