mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-31 20:25:38 +00:00
Experiment: wait for input
This commit is contained in:
parent
d7173a2f75
commit
ca2d0f7d60
1 changed files with 32 additions and 7 deletions
|
@ -75,8 +75,23 @@ public class ResponseInputStream {
|
|||
boolean gotCRLF=false;
|
||||
|
||||
// Read a CRLF terminated line from the InputStream
|
||||
while (!gotCRLF &&
|
||||
((b = bin.read()) != -1)) {
|
||||
int wait = 1;
|
||||
while (!gotCRLF) {
|
||||
b = bin.read();
|
||||
if (b == -1) {
|
||||
wait *= 10;
|
||||
if (wait > 1000)
|
||||
throw new IOException("Connection dropped by server?" ,
|
||||
new Throwable(new String(buffer, 0, idx)));
|
||||
else
|
||||
try {
|
||||
Thread.sleep(wait);
|
||||
continue;
|
||||
} catch (InterruptedException ex) {
|
||||
eu.faircode.email.Log.w(ex);
|
||||
}
|
||||
} else
|
||||
wait = 1;
|
||||
if (b == '\n') {
|
||||
if ((idx > 0) && buffer[idx-1] == '\r')
|
||||
gotCRLF = true;
|
||||
|
@ -91,9 +106,6 @@ public class ResponseInputStream {
|
|||
buffer[idx++] = (byte)b;
|
||||
}
|
||||
|
||||
if (b == -1)
|
||||
throw new IOException("Connection dropped by server?");
|
||||
|
||||
// Now lets check for literals : {<digits>}CRLF
|
||||
// Note: index needs to >= 5 for the above sequence to occur
|
||||
if (idx < 5 || buffer[idx-3] != '}')
|
||||
|
@ -131,10 +143,23 @@ public class ResponseInputStream {
|
|||
* so call repeatedly till we are done
|
||||
*/
|
||||
int actual;
|
||||
wait = 1;
|
||||
while (count > 0) {
|
||||
actual = bin.read(buffer, idx, count);
|
||||
if (actual == -1)
|
||||
throw new IOException("Connection dropped by server?");
|
||||
if (actual == -1) {
|
||||
wait *= 10;
|
||||
if (wait > 1000)
|
||||
throw new IOException("Connection dropped by server?" ,
|
||||
new Throwable(new String(buffer, 0, idx)));
|
||||
else
|
||||
try {
|
||||
Thread.sleep(wait);
|
||||
continue;
|
||||
} catch (InterruptedException ex) {
|
||||
eu.faircode.email.Log.w(ex);
|
||||
}
|
||||
} else
|
||||
wait = 1;
|
||||
count -= actual;
|
||||
idx += actual;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue