mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-11-04 11:03:21 +00:00 
			
		
		
		
	Add isOpen() to socket and tunnel. Add getSocket() to tunnel.
This commit is contained in:
		@@ -76,4 +76,12 @@ public interface GuacamoleSocket {
 | 
			
		||||
     */
 | 
			
		||||
    public void close() throws GuacamoleException;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns whether this GuacamoleSocket is open and can be used for reading
 | 
			
		||||
     * and writing.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if this GuacamoleSocket is open, false otherwise.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isOpen();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,8 @@ public class GuacamoleTunnel {
 | 
			
		||||
    private ReentrantLock readerLock;
 | 
			
		||||
    private ReentrantLock writerLock;
 | 
			
		||||
 | 
			
		||||
    private boolean open = true;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Creates a new GuacamoleTunnel which synchronizes access to the
 | 
			
		||||
     * Guacamole instruction stream associated with the given GuacamoleSocket.
 | 
			
		||||
@@ -146,6 +148,16 @@ public class GuacamoleTunnel {
 | 
			
		||||
        return uuid;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the GuacamoleSocket used by this GuacamoleTunnel for reading
 | 
			
		||||
     * and writing.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return The GuacamoleSocket used by this GuacamoleTunnel.
 | 
			
		||||
     */
 | 
			
		||||
    public GuacamoleSocket getSocket() {
 | 
			
		||||
        return socket;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Release all resources allocated to this GuacamoleTunnel.
 | 
			
		||||
     * 
 | 
			
		||||
@@ -156,4 +168,13 @@ public class GuacamoleTunnel {
 | 
			
		||||
        socket.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns whether this GuacamoleTunnel is open, or has been closed.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return true if this GuacamoleTunnel is open, false if it is closed.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isOpen() {
 | 
			
		||||
        return socket.isOpen();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -132,5 +132,10 @@ public class InetGuacamoleSocket implements GuacamoleSocket {
 | 
			
		||||
        return writer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isOpen() {
 | 
			
		||||
        return !sock.isClosed();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -121,4 +121,9 @@ public class ConfiguredGuacamoleSocket implements GuacamoleSocket {
 | 
			
		||||
        socket.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isOpen() {
 | 
			
		||||
        return socket.isOpen();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -227,10 +227,15 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
 | 
			
		||||
        HttpSession httpSession = request.getSession(false);
 | 
			
		||||
        GuacamoleSession session = new GuacamoleSession(httpSession);
 | 
			
		||||
 | 
			
		||||
        // Get tunnel, ensure tunnel exists
 | 
			
		||||
        GuacamoleTunnel tunnel = session.getTunnel(tunnelUUID);
 | 
			
		||||
        if (tunnel == null)
 | 
			
		||||
            throw new GuacamoleResourceNotFoundException("No such tunnel.");
 | 
			
		||||
 | 
			
		||||
        // Ensure tunnel is open
 | 
			
		||||
        if (!tunnel.isOpen())
 | 
			
		||||
            throw new GuacamoleResourceNotFoundException("Tunnel is closed.");
 | 
			
		||||
        
 | 
			
		||||
        // Obtain exclusive read access
 | 
			
		||||
        GuacamoleReader reader = tunnel.acquireReader();
 | 
			
		||||
 | 
			
		||||
@@ -265,7 +270,7 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
 | 
			
		||||
                if (tunnel.hasQueuedReaderThreads())
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
            } while ((message = reader.read()) != null);
 | 
			
		||||
            } while (tunnel.isOpen() && (message = reader.read()) != null);
 | 
			
		||||
 | 
			
		||||
            // Close tunnel immediately upon EOF
 | 
			
		||||
            if (message == null)
 | 
			
		||||
@@ -340,7 +345,8 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
 | 
			
		||||
            char[] buffer = new char[8192];
 | 
			
		||||
 | 
			
		||||
            int length;
 | 
			
		||||
            while ((length = input.read(buffer, 0, buffer.length)) != -1)
 | 
			
		||||
            while (tunnel.isOpen() && 
 | 
			
		||||
                    (length = input.read(buffer, 0, buffer.length)) != -1)
 | 
			
		||||
                writer.write(buffer, 0, length);
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user