From 7c9300be5f62117ab048ce841cdadefe8e36e40d Mon Sep 17 00:00:00 2001 From: "lingming.yb" Date: Sat, 4 Jan 2014 15:20:58 +0800 Subject: [PATCH] timeout issue --- .../okhttp/internal/spdy/SpdyStream.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java index e55002203..a3ab3a446 100644 --- a/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java +++ b/okhttp-protocols/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java @@ -116,9 +116,23 @@ public final class SpdyStream { * have not been received yet. */ public synchronized List getResponseHeaders() throws IOException { + long remaining = 0; + long start = 0; + if (readTimeoutMillis != 0) { + start = (System.nanoTime() / 1000000); + remaining = readTimeoutMillis; + } try { while (responseHeaders == null && errorCode == null) { - wait(); + if (readTimeoutMillis == 0) { // No timeout configured. + wait(); + } else if (remaining > 0) { + wait(remaining); + remaining = start + readTimeoutMillis - (System.nanoTime() / 1000000); + } else { + throw new SocketTimeoutException("Read response header timeout. readTimeoutMillis: " + + readTimeoutMillis); + } } if (responseHeaders != null) { return responseHeaders;