Added GuacamoleReader.available(), using to determine appropriate times to flush tunnel servlet output.

This commit is contained in:
Michael Jumper
2011-12-05 18:54:52 -08:00
parent e0b1427e59
commit f9bcd5f7cf
3 changed files with 29 additions and 2 deletions

View File

@@ -48,6 +48,19 @@ import net.sourceforge.guacamole.protocol.GuacamoleInstruction;
*/
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
* containing one or more complete Guacamole instructions and no

View File

@@ -70,6 +70,16 @@ public class ReaderGuacamoleReader implements GuacamoleReader {
private char[] buffer = new char[20480];
private int usedLength = 0;
@Override
public boolean available() throws GuacamoleException {
try {
return input.ready() || usedLength != 0;
}
catch (IOException e) {
throw new GuacamoleException(e);
}
}
@Override
public char[] read() throws GuacamoleException {

View File

@@ -224,8 +224,12 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
// Get message output bytes
out.write(message, 0, message.length);
out.flush();
response.flushBuffer();
// Flush if we expect to wait
if (!reader.available()) {
out.flush();
response.flushBuffer();
}
// No more messages another stream can take over
if (tunnel.hasQueuedReaderThreads())