Added setting for connection/read/write timeout

This commit is contained in:
M66B
2020-03-08 19:11:39 +01:00
parent 91899a11ec
commit 85c155267c
4 changed files with 84 additions and 15 deletions

View File

@@ -97,11 +97,9 @@ public class EmailService implements AutoCloseable {
static final int PURPOSE_USE = 2;
static final int PURPOSE_SEARCH = 3;
final static int DEFAULT_CONNECT_TIMEOUT = 20; // seconds
private final static int SEARCH_TIMEOUT = 2 * 60 * 1000; // milliseconds
private final static int CONNECT_TIMEOUT = 20 * 1000; // milliseconds
private final static int CONNECT_TIMEOUT_CHECK = 20 * 1000; // milliseconds
private final static int WRITE_TIMEOUT = 60 * 1000; // milliseconds
private final static int READ_TIMEOUT = 60 * 1000; // milliseconds
private final static int FETCH_SIZE = 1024 * 1024; // bytes, default 16K
private final static int POOL_TIMEOUT = 45 * 1000; // milliseconds, default 45 sec
@@ -155,20 +153,17 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".sasl.realm", realm == null ? "" : realm);
properties.put("mail." + protocol + ".auth.ntlm.domain", realm == null ? "" : realm);
// TODO: make timeouts configurable?
// writetimeout: one thread overhead
int timeout = prefs.getInt("timeout", DEFAULT_CONNECT_TIMEOUT) * 1000;
Log.i("Timeout=" + timeout);
if (purpose == PURPOSE_SEARCH) {
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(timeout));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(SEARCH_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(SEARCH_TIMEOUT));
} else if (purpose == PURPOSE_CHECK) {
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT_CHECK));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
} else {
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(CONNECT_TIMEOUT));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(WRITE_TIMEOUT));
properties.put("mail." + protocol + ".timeout", Integer.toString(READ_TIMEOUT));
properties.put("mail." + protocol + ".connectiontimeout", Integer.toString(timeout));
properties.put("mail." + protocol + ".writetimeout", Integer.toString(timeout * 2));
properties.put("mail." + protocol + ".timeout", Integer.toString(timeout * 2));
}
if (debug && BuildConfig.DEBUG)