ridljar/com/sun/star/lib/connections/websocket/WebsocketConnection.java | 35 +++------- 1 file changed, 11 insertions(+), 24 deletions(-)
New commits: commit 40103b60b494991da0f24b865582355e30dbba19 Author: Caolán McNamara <[email protected]> AuthorDate: Tue Sep 5 13:03:41 2023 +0100 Commit: Michael Meeks <[email protected]> CommitDate: Tue Sep 5 16:37:29 2023 +0200 websocket URP flush hangs with large buffer over 4k hits limit so flush waits until something reads, but the read is in the same thread after the flush. We are just using _outputStream to accumulate the bytes to be send so change this to use a ByteArrayOutputStream and take over its bytes and clear it when we flush. Change-Id: I17b90e1c7d4302f153b5832e60ac0e0f2b86ace9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156543 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Meeks <[email protected]> diff --git a/ridljar/com/sun/star/lib/connections/websocket/WebsocketConnection.java b/ridljar/com/sun/star/lib/connections/websocket/WebsocketConnection.java index 7f522df409d1..440151fc696c 100644 --- a/ridljar/com/sun/star/lib/connections/websocket/WebsocketConnection.java +++ b/ridljar/com/sun/star/lib/connections/websocket/WebsocketConnection.java @@ -20,7 +20,7 @@ package com.sun.star.lib.connections.websocket; import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -61,10 +61,8 @@ public class WebsocketConnection extends WebSocketClient implements XConnection, protected String _description; protected InputStream _inputStream; - protected OutputStream _outputStream; - - protected InputStream _outputStreamReader; protected OutputStream _inputStreamWriter; + protected ByteArrayOutputStream _outputStream; protected ArrayList<XStreamListener> _listeners; @@ -83,14 +81,10 @@ public class WebsocketConnection extends WebSocketClient implements XConnection, PipedOutputStream inputStreamWriter = new PipedOutputStream(); PipedInputStream inputPipe = new PipedInputStream(inputStreamWriter); - PipedOutputStream outputPipe = new PipedOutputStream(); - PipedInputStream outputStreamReader = new PipedInputStream(outputPipe); - _inputStream = new BufferedInputStream(inputPipe); _inputStreamWriter = inputStreamWriter; - _outputStream = new BufferedOutputStream(outputPipe); - _outputStreamReader = outputStreamReader; + _outputStream = new ByteArrayOutputStream(); _listeners = new ArrayList<XStreamListener>(); @@ -206,23 +200,16 @@ public class WebsocketConnection extends WebSocketClient implements XConnection, */ public void flush() throws com.sun.star.io.IOException, com.sun.star.uno.RuntimeException { - try { - _outputStream.flush(); - - Integer available = _outputStreamReader.available(); - - byte[] outputBytes = new byte[available + outgoingPrefix.length]; - System.arraycopy(outgoingPrefix, 0, outputBytes, 0, outgoingPrefix.length); - - _outputStreamReader.read(outputBytes, outgoingPrefix.length, available); - send(outputBytes); - } catch(IOException ioException) { - com.sun.star.io.IOException unoIOException = new com.sun.star.io.IOException(ioException); - notifyListeners_error(unoIOException); - - throw unoIOException; + byte[] accumulatedBytes; + synchronized (_outputStream) { + accumulatedBytes = _outputStream.toByteArray(); + _outputStream.reset(); } + byte[] outputBytes = new byte[accumulatedBytes.length + outgoingPrefix.length]; + System.arraycopy(outgoingPrefix, 0, outputBytes, 0, outgoingPrefix.length); + System.arraycopy(accumulatedBytes, 0, outputBytes, outgoingPrefix.length, accumulatedBytes.length); + send(outputBytes); if (DEBUG) System.err.println(String.format("##### %s - flushed", getClass().getName()));
