mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Added GuacamoleReader.available(), using to determine appropriate times to flush tunnel servlet output.
This commit is contained in:
@@ -48,6 +48,19 @@ import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
|
|||||||
*/
|
*/
|
||||||
public interface GuacamoleReader {
|
public interface GuacamoleReader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether instruction data is available for reading. Note that
|
||||||
|
* this does not guarantee an entire instruction is available. If a full
|
||||||
|
* instruction is not available, this function can return true, and a call
|
||||||
|
* to read() will still block.
|
||||||
|
*
|
||||||
|
* @return true if instruction data is available for reading, false
|
||||||
|
* otherwise.
|
||||||
|
* @throws GuacamoleException If an error occurs while checking for
|
||||||
|
* available data.
|
||||||
|
*/
|
||||||
|
public boolean available() throws GuacamoleException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads at least one complete Guacamole instruction, returning a buffer
|
* Reads at least one complete Guacamole instruction, returning a buffer
|
||||||
* containing one or more complete Guacamole instructions and no
|
* containing one or more complete Guacamole instructions and no
|
||||||
|
@@ -70,6 +70,16 @@ public class ReaderGuacamoleReader implements GuacamoleReader {
|
|||||||
private char[] buffer = new char[20480];
|
private char[] buffer = new char[20480];
|
||||||
private int usedLength = 0;
|
private int usedLength = 0;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean available() throws GuacamoleException {
|
||||||
|
try {
|
||||||
|
return input.ready() || usedLength != 0;
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new GuacamoleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] read() throws GuacamoleException {
|
public char[] read() throws GuacamoleException {
|
||||||
|
|
||||||
|
@@ -224,8 +224,12 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
|
|||||||
|
|
||||||
// Get message output bytes
|
// Get message output bytes
|
||||||
out.write(message, 0, message.length);
|
out.write(message, 0, message.length);
|
||||||
|
|
||||||
|
// Flush if we expect to wait
|
||||||
|
if (!reader.available()) {
|
||||||
out.flush();
|
out.flush();
|
||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
// No more messages another stream can take over
|
// No more messages another stream can take over
|
||||||
if (tunnel.hasQueuedReaderThreads())
|
if (tunnel.hasQueuedReaderThreads())
|
||||||
|
Reference in New Issue
Block a user