Skip to content
Snippets Groups Projects
Commit 151c4d4d authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

fix: add zero counter threshold

parent 34f61ade
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,10 @@ class MidlewareTunnel implements Closeable { ...@@ -34,6 +34,10 @@ class MidlewareTunnel implements Closeable {
private static final int DEFAULT_BACKLOG = 50; private static final int DEFAULT_BACKLOG = 50;
private static final int ZERO_COUNT_THRESHOLD = 10;
private static final long ZERO_COUNT_PAUSE = 500;
private final long jobId; private final long jobId;
private ServerSocket ss; private ServerSocket ss;
...@@ -150,7 +154,7 @@ class MidlewareTunnel implements Closeable { ...@@ -150,7 +154,7 @@ class MidlewareTunnel implements Closeable {
continue; continue;
} }
if (!sendToMiddleware(buffer, len, connection)) { if (!sendToMiddleware(buffer, len, connection)) {
return; break;
} }
} }
connection.clientClosed(); connection.clientClosed();
...@@ -172,6 +176,7 @@ class MidlewareTunnel implements Closeable { ...@@ -172,6 +176,7 @@ class MidlewareTunnel implements Closeable {
byte[] sending; byte[] sending;
int toSend = len; int toSend = len;
int offset = 0; int offset = 0;
int zeroCounter = 0;
do { do {
if (toSend != buffer.length || offset != 0) { if (toSend != buffer.length || offset != 0) {
sending = new byte[toSend]; sending = new byte[toSend];
...@@ -184,7 +189,19 @@ class MidlewareTunnel implements Closeable { ...@@ -184,7 +189,19 @@ class MidlewareTunnel implements Closeable {
return false; return false;
} }
toSend -= reallySend; toSend -= reallySend;
offset += reallySend; offset += reallySend;
if(reallySend == 0) {
zeroCounter++;
if(zeroCounter >= ZERO_COUNT_THRESHOLD) {
return false;
}
try {
Thread.sleep(ZERO_COUNT_PAUSE);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
}
} while(toSend != 0 && !connection.isServerClosed()); } while(toSend != 0 && !connection.isServerClosed());
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment