Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2014-08-27 11:21:29 -0400
committerAnton Leherbauer2014-08-27 11:30:39 -0400
commita99ce260718f005b741863ddaded4626ca472be8 (patch)
tree93cb09be37dc044b71ed5c2cbdbe6b31983fdd8a
parent260bce2243120e040e761ce40981f028cdd06c10 (diff)
downloadorg.eclipse.tcf-a99ce260718f005b741863ddaded4626ca472be8.tar.gz
org.eclipse.tcf-a99ce260718f005b741863ddaded4626ca472be8.tar.xz
org.eclipse.tcf-a99ce260718f005b741863ddaded4626ca472be8.zip
Workaround for console input buffer overflow on windows
Pasting text with 2000+ chars failed because of a buffer overflow writing to the console input buffer. The workaround is to split data into smaller junks and wait a little between writes.
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java22
1 files changed, 18 insertions, 4 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
index 5ebeeb633..ce9a6260e 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.terminals/src/org/eclipse/tcf/te/ui/terminals/streams/InputStreamMonitor.java
@@ -236,10 +236,21 @@ public class InputStreamMonitor extends OutputStream implements IDisposable {
}
if (data != null) {
try {
- // Write the data to the stream
- stream.write(data);
- // Flush the stream immediately
- stream.flush();
+ // Break up writes into max 1000 byte junks to avoid console input buffer overflows on Windows
+ int written = 0;
+ byte[] buf = new byte[1000];
+ while (written < data.length) {
+ int len = Math.min(buf.length, data.length - written);
+ System.arraycopy(data, written, buf, 0, len);
+ // Write the data to the stream
+ stream.write(buf, 0, len);
+ written += len;
+ // Flush the stream immediately
+ stream.flush();
+ // Wait a little between writes to allow input being processed
+ if (written < data.length)
+ Thread.sleep(100);
+ }
} catch (IOException e) {
// IOException received. If this is happening when already disposed -> ignore
if (!disposed) {
@@ -248,6 +259,9 @@ public class InputStreamMonitor extends OutputStream implements IDisposable {
UIPlugin.getDefault().getLog().log(status);
}
}
+ catch (InterruptedException e) {
+ break;
+ }
}
}

Back to the top