LwHttp: increase timeouts

- wip: HttpEngine docs
This commit is contained in:
Hannes Janetzek 2014-09-29 18:09:59 +02:00
parent 5109eda6da
commit 41085f915e
2 changed files with 16 additions and 12 deletions

View File

@ -32,6 +32,12 @@ public interface HttpEngine {
void setCache(OutputStream os); 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); boolean requestCompleted(boolean success);
public interface Factory { public interface Factory {

View File

@ -49,6 +49,9 @@ public class LwHttp implements HttpEngine {
private final static int RESPONSE_EXPECTED_LIVES = 100; private final static int RESPONSE_EXPECTED_LIVES = 100;
private final static long RESPONSE_TIMEOUT = (long) 10E9; // 10 second in nanosecond 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 static int BUFFER_SIZE = 8192;
private final byte[] buffer = new byte[BUFFER_SIZE]; private final byte[] buffer = new byte[BUFFER_SIZE];
@ -387,8 +390,8 @@ public class LwHttp implements HttpEngine {
try { try {
mSocket = new Socket(); mSocket = new Socket();
mSocket.setTcpNoDelay(true); mSocket.setTcpNoDelay(true);
mSocket.setSoTimeout(5000); mSocket.setSoTimeout(SOCKET_TIMEOUT);
mSocket.connect(mSockAddr, 10000); mSocket.connect(mSockAddr, CONNECT_TIMEOUT);
mCommandStream = mSocket.getOutputStream(); mCommandStream = mSocket.getOutputStream();
mResponseStream = new Buffer(mSocket.getInputStream()); mResponseStream = new Buffer(mSocket.getInputStream());
@ -429,21 +432,16 @@ public class LwHttp implements HttpEngine {
if (!mResponseStream.finishedReading()) { if (!mResponseStream.finishedReading()) {
if (dbg) if (dbg)
log.debug("invalid buffer position"); log.debug("invalid buffer position");
/* hmmm, some bitmaps seems to not be decoded to the
* end but still working */
close(); close();
return true;
} }
if (!success) { if (!success || mMustCloseConnection)
close(); close();
return false;
}
if (mMustCloseConnection) { return success;
close();
return true;
}
return true;
} }
/** write (positive) integer to byte array */ /** write (positive) integer to byte array */