diff --git a/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 18ff1ffd2b6..b4db0421536 100644 --- a/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -26,6 +26,7 @@ * Martin Oberhuber (Wind River) - [240745] Pressing Ctrl+F1 in the Terminal should bring up context help * Michael Scharf (Wind River) - [240098] The cursor should not blink when the terminal is disconnected * Anton Leherbauer (Wind River) - [335021] Middle mouse button copy/paste does not work with the terminal + * Pawel Piech (Wind River) - [333613] Avoid "Job still found running" error after shutdown *******************************************************************************/ package org.eclipse.tm.internal.terminal.emulator; @@ -345,27 +346,35 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC public void disconnectTerminal() { Logger.log("entered."); //$NON-NLS-1$ + //Ensure that a new Job can be started; then clean up old Job. + //TODO not sure whether the fInputStream needs to be cleaned too, + //or whether the Job could actually cancel in case the fInputStream is closed. + Job job; + synchronized(this) { + job = fJob; + fJob = null; + } + if (job!=null) { + job.cancel(); + // Join job to avoid leaving job running after workbench shutdown (333613). + try { + fInputStream.close(); + //There's not really a need to interrupt, since the job will + //check its cancel status after 500 msec latest anyways... + //Thread t = job.getThread(); + //if(t!=null) t.interrupt(); + job.join(); + } catch (IOException e1) { + } catch (InterruptedException e) { + } + } + if (getState()==TerminalState.CLOSED) { return; } if(getTerminalConnector()!=null) { getTerminalConnector().disconnect(); } - //Ensure that a new Job can be started; then clean up old Job. - //TODO not sure whether the fInputStream needs to be cleaned too, - //or whether the Job could actually cancel in case the fInputStream is closed. - Job job; - synchronized(this) { - job = fJob; - fJob = null; - } - if (job!=null) { - job.cancel(); - //There's not really a need to interrupt, since the job will - //check its cancel status after 500 msec latest anyways... - //Thread t = job.getThread(); - //if(t!=null) t.interrupt(); - } } // TODO diff --git a/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java b/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java index 5b36e5a9bb4..d15a47b5fed 100644 --- a/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java +++ b/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/PipedInputStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1996, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 1996, 2011 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Douglas Lea (Addison Wesley) - [cq:1552] BoundedBufferWithStateTracking adapted to BoundedByteBuffer * Martin Oberhuber (Wind River) - the waitForAvailable method * Martin Oberhuber (Wind River) - [208166] Avoid unnecessary arraycopy in BoundedByteBuffer + * Pawel Piech (Wind River) - [333613] Avoid "Job still found running" error after shutdown *******************************************************************************/ package org.eclipse.tm.internal.terminal.textcanvas; @@ -72,7 +73,12 @@ public class PipedInputStream extends InputStream { * Must be called with a lock on this! */ public int available() { - return fUsedSlots; + if (fUsedSlots > 0) { + return fUsedSlots; + } else if (fClosed) { + return -1; + } + return 0; } /** * Writes a single byte to the buffer. Blocks if the buffer is full. @@ -237,7 +243,8 @@ public class PipedInputStream extends InputStream { } /** * Must be called in the Display Thread! - * @return true if a character is available for the terminal to show. + * @return number of characters available for reading. Returns -1 if + * stream is closed and no characters are left in pipe. */ public int available() { synchronized(fQueue) { @@ -259,12 +266,14 @@ public class PipedInputStream extends InputStream { } } /** - * Closing a PipedInputStream has no effect. The methods in - * this class can be called after the stream has been closed without - * generating an IOException. - *

+ * Closing a PipedInputStream is the same as closing the output stream. + * The stream will allow reading data that's still in the pipe after which it will + * throw an IOException. */ public void close() throws IOException { + synchronized(fQueue) { + fQueue.close(); + } } public int read(byte[] cbuf, int off, int len) throws IOException {