From 41085f915e0e5c93a534510db131135b6c7bac1c Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Mon, 29 Sep 2014 18:09:59 +0200 Subject: [PATCH] LwHttp: increase timeouts - wip: HttpEngine docs --- .../org/oscim/tiling/source/HttpEngine.java | 6 +++++ vtm/src/org/oscim/tiling/source/LwHttp.java | 22 +++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/vtm/src/org/oscim/tiling/source/HttpEngine.java b/vtm/src/org/oscim/tiling/source/HttpEngine.java index c5e9c715..7164eae0 100644 --- a/vtm/src/org/oscim/tiling/source/HttpEngine.java +++ b/vtm/src/org/oscim/tiling/source/HttpEngine.java @@ -32,6 +32,12 @@ public interface HttpEngine { void setCache(OutputStream os); + /** + * @param success maybe false when tile could not be decoded. + * Dont write cache in this case, close socket, etc + * at your option. + * @return true when everything went ok + */ boolean requestCompleted(boolean success); public interface Factory { diff --git a/vtm/src/org/oscim/tiling/source/LwHttp.java b/vtm/src/org/oscim/tiling/source/LwHttp.java index 905a7f27..02e05cd2 100644 --- a/vtm/src/org/oscim/tiling/source/LwHttp.java +++ b/vtm/src/org/oscim/tiling/source/LwHttp.java @@ -49,6 +49,9 @@ public class LwHttp implements HttpEngine { private final static int RESPONSE_EXPECTED_LIVES = 100; private final static long RESPONSE_TIMEOUT = (long) 10E9; // 10 second in nanosecond + private final static int CONNECT_TIMEOUT = 15000; // 15 seconds + private final static int SOCKET_TIMEOUT = 8000; // 8 seconds + private final static int BUFFER_SIZE = 8192; private final byte[] buffer = new byte[BUFFER_SIZE]; @@ -387,8 +390,8 @@ public class LwHttp implements HttpEngine { try { mSocket = new Socket(); mSocket.setTcpNoDelay(true); - mSocket.setSoTimeout(5000); - mSocket.connect(mSockAddr, 10000); + mSocket.setSoTimeout(SOCKET_TIMEOUT); + mSocket.connect(mSockAddr, CONNECT_TIMEOUT); mCommandStream = mSocket.getOutputStream(); mResponseStream = new Buffer(mSocket.getInputStream()); @@ -429,21 +432,16 @@ public class LwHttp implements HttpEngine { if (!mResponseStream.finishedReading()) { if (dbg) log.debug("invalid buffer position"); + + /* hmmm, some bitmaps seems to not be decoded to the + * end but still working */ close(); - return true; } - if (!success) { + if (!success || mMustCloseConnection) close(); - return false; - } - if (mMustCloseConnection) { - close(); - return true; - } - - return true; + return success; } /** write (positive) integer to byte array */