summaryrefslogtreecommitdiffstats
path: root/src/org/apache/http/impl/io/SocketInputBuffer.java
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2010-12-20 11:59:44 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-12-20 11:59:44 -0800
commit15921ecc8d2446dd23f49190d0b06b31f752de9b (patch)
treeb2ac1bf1db89300636c7d0457464abf95c087037 /src/org/apache/http/impl/io/SocketInputBuffer.java
parent645db2f0647b88f06059eb29a7c7455feda3e119 (diff)
parent091f7ca4958c6f41c79808913c84ceea56d73b12 (diff)
downloadexternal_apache-http-15921ecc8d2446dd23f49190d0b06b31f752de9b.zip
external_apache-http-15921ecc8d2446dd23f49190d0b06b31f752de9b.tar.gz
external_apache-http-15921ecc8d2446dd23f49190d0b06b31f752de9b.tar.bz2
am 091f7ca4: Fix Apache HTTP client to recover from half-closed connections.
* commit '091f7ca4958c6f41c79808913c84ceea56d73b12': Fix Apache HTTP client to recover from half-closed connections.
Diffstat (limited to 'src/org/apache/http/impl/io/SocketInputBuffer.java')
-rw-r--r--src/org/apache/http/impl/io/SocketInputBuffer.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/org/apache/http/impl/io/SocketInputBuffer.java b/src/org/apache/http/impl/io/SocketInputBuffer.java
index 925e80a..9e09436 100644
--- a/src/org/apache/http/impl/io/SocketInputBuffer.java
+++ b/src/org/apache/http/impl/io/SocketInputBuffer.java
@@ -35,6 +35,7 @@ import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.Socket;
+import java.net.SocketTimeoutException;
import org.apache.http.params.HttpParams;
@@ -112,4 +113,30 @@ public class SocketInputBuffer extends AbstractSessionInputBuffer {
return result;
}
+ // BEGIN android-added
+ /**
+ * Returns true if the connection is probably functional. It's insufficient
+ * to rely on isDataAvailable() returning normally; that approach cannot
+ * distinguish between an exhausted stream and a stream with zero bytes
+ * buffered.
+ *
+ * @hide
+ */
+ public boolean isStale() throws IOException {
+ if (hasBufferedData()) {
+ return false;
+ }
+ int oldTimeout = this.socket.getSoTimeout();
+ try {
+ this.socket.setSoTimeout(1);
+ return fillBuffer() == -1;
+ } catch (SocketTimeoutException e) {
+ return false; // the connection is not stale; hooray
+ } catch (IOException e) {
+ return true; // the connection is stale, the read or soTimeout failed.
+ } finally {
+ this.socket.setSoTimeout(oldTimeout);
+ }
+ }
+ // END android-added
}