From a7efcf6c729fc8be4904011355071a66c8f0a396 Mon Sep 17 00:00:00 2001 From: jhihn Date: Fri, 2 Oct 2020 13:24:01 -0400 Subject: [PATCH] Update AsyncNetworkSocket.java There i a problem when a large (>345 kB) message is being written to a websocket. The connection will actually time out, unless this while is in place. Unfortunately, this pretty much busy-waits. But whatever the queueing mechanism is is broken at least for websockets and large messages. My messages are ~2MB. .154 AndroidAsync: before:1926139 .154 AndroidAsync: remaining:1577171 .156 AndroidAsync: before:1926139 .156 AndroidAsync: remaining:1577171 AndroidAsync: before:1926139 ... .240 AndroidAsync: remaining:0 --- .../com/koushikdutta/async/AsyncNetworkSocket.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java b/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java index e13860aae..a0d8796af 100644 --- a/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java +++ b/AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java @@ -84,11 +84,16 @@ public void run() { } try { + int before = list.remaining(); - ByteBuffer[] arr = list.getAllArray(); - mChannel.write(arr); - list.addAll(arr); - handleRemaining(list.remaining()); + int remaining = before; + while (remaining > 0) { // busy wait or the socket will timeout with messages > 345kB + ByteBuffer[] arr = list.getAllArray(); + mChannel.write(arr); + list.addAll(arr); + handleRemaining(list.remaining()); + remaining = list.remaining(); + } mServer.onDataSent(before - list.remaining()); } catch (IOException e) {