Commit 2d188c9f authored by Roumen Petrov's avatar Roumen Petrov
Browse files

emulatorview: do not write if consumer is finished

parent dba1acae
......@@ -101,6 +101,7 @@ public void run() {
}
};
private UpdateCallback mTitleChangedListener;
public TermSession() {
this(false);
}
......@@ -140,6 +141,13 @@ public void run() {
} catch (InterruptedException e) {
}
{ // stop producer as well
Handler writer = mWriterHandler;
mWriterHandler = null;
if (writer != null)
writer.sendEmptyMessage(FINISH);
}
if (exitOnEOF) mMsgHandler.sendMessage(mMsgHandler.obtainMessage(EOF));
}
};
......@@ -243,6 +251,10 @@ public void initializeEmulator(int columns, int rows) {
public void write(byte[] data, int offset, int count) {
try {
while (count > 0) {
// do not write if consumer is finished
if (mReaderThread.getState() == Thread.State.TERMINATED)
break;
int written = mWriteQueue.write(data, offset, count);
offset += written;
count -= written;
......@@ -595,9 +607,12 @@ public void finish() {
}
// Stop the reader and writer threads, and close the I/O streams
if (mWriterHandler != null) {
mWriterHandler.sendEmptyMessage(FINISH);
}
// Reader thread, if running, will be terminated indirectly by closed
// input stream.
// Remarks:
// - when reader finish it closes writer thread.
// - flag IsRunning blocks recursive call:
// -> mMsgHandler on EOF -> onProcessExit() -> finish()
try {
mTermIn.close();
mTermOut.close();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment