mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Add close() to tunnel, properly detach and close tunnel on error.
This commit is contained in:
@@ -21,6 +21,7 @@ package net.sourceforge.guacamole.net;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
import net.sourceforge.guacamole.GuacamoleException;
|
||||||
import net.sourceforge.guacamole.io.GuacamoleReader;
|
import net.sourceforge.guacamole.io.GuacamoleReader;
|
||||||
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
import net.sourceforge.guacamole.io.GuacamoleWriter;
|
||||||
|
|
||||||
@@ -127,4 +128,14 @@ public class GuacamoleTunnel {
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release all resources allocated to this GuacamoleTunnel.
|
||||||
|
*
|
||||||
|
* @throws GuacamoleException if an error occurs while releasing
|
||||||
|
* resources.
|
||||||
|
*/
|
||||||
|
public void close() throws GuacamoleException {
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -190,10 +190,8 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
|
|||||||
// Detach tunnel and throw error if EOF (and we haven't sent any
|
// Detach tunnel and throw error if EOF (and we haven't sent any
|
||||||
// data yet.
|
// data yet.
|
||||||
char[] message = reader.read();
|
char[] message = reader.read();
|
||||||
if (message == null) {
|
if (message == null)
|
||||||
session.detachTunnel(tunnel);
|
|
||||||
throw new GuacamoleException("Disconnected.");
|
throw new GuacamoleException("Disconnected.");
|
||||||
}
|
|
||||||
|
|
||||||
// For all messages, until another stream is ready (we send at least one message)
|
// For all messages, until another stream is ready (we send at least one message)
|
||||||
do {
|
do {
|
||||||
@@ -215,10 +213,28 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
|
|||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
catch (GuacamoleException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
catch (UnsupportedEncodingException e) {
|
catch (UnsupportedEncodingException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
throw new GuacamoleException("UTF-8 not supported by Java.", e);
|
throw new GuacamoleException("UTF-8 not supported by Java.", e);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
throw new GuacamoleException("I/O error writing to servlet output stream.", e);
|
throw new GuacamoleException("I/O error writing to servlet output stream.", e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -273,6 +289,11 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
|
||||||
|
// Detach and close
|
||||||
|
session.detachTunnel(tunnel);
|
||||||
|
tunnel.close();
|
||||||
|
|
||||||
throw new GuacamoleException("I/O Error sending data to server: " + e.getMessage(), e);
|
throw new GuacamoleException("I/O Error sending data to server: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
Reference in New Issue
Block a user