From 6f0128e165027a93505b04ea2e2ff55197c58cb4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Karpukhin Date: Tue, 5 Apr 2016 20:08:57 +0200 Subject: [PATCH] CPP-6325 Do not sleep in readAvailableBlocking() for pty, things won't become better anyway --- .../util/io/BaseInputStreamReader.java | 5 +++++ .../com/intellij/util/io/BaseOutputReader.java | 18 ++++++++++++------ platform/util/util.iml | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/BaseInputStreamReader.java b/platform/util/src/com/intellij/util/io/BaseInputStreamReader.java index c76316fc8b57..5755b59ef60f 100644 --- a/platform/util/src/com/intellij/util/io/BaseInputStreamReader.java +++ b/platform/util/src/com/intellij/util/io/BaseInputStreamReader.java @@ -15,6 +15,7 @@ */ package com.intellij.util.io; +import com.pty4j.unix.PTYInputStream; import org.jetbrains.annotations.NotNull; import java.io.IOException; @@ -42,4 +43,8 @@ public class BaseInputStreamReader extends InputStreamReader { public void close() throws IOException { myInputStream.close(); // close underlying input stream without locking in StreamDecoder. } + + public boolean availableUnsupported() { + return myInputStream instanceof PTYInputStream; + } } diff --git a/platform/util/src/com/intellij/util/io/BaseOutputReader.java b/platform/util/src/com/intellij/util/io/BaseOutputReader.java index 9c810b674efa..2e73ddff7870 100644 --- a/platform/util/src/com/intellij/util/io/BaseOutputReader.java +++ b/platform/util/src/com/intellij/util/io/BaseOutputReader.java @@ -93,6 +93,7 @@ public abstract class BaseOutputReader extends BaseDataReader { * @throws IOException If an I/O error occurs */ protected final boolean readAvailableBlocking() throws IOException { + final boolean availableUnsupported = ((BaseInputStreamReader)myReader).availableUnsupported(); boolean read = false; int n; @@ -101,14 +102,19 @@ public abstract class BaseOutputReader extends BaseDataReader { read = true; processLine(myInputBuffer, myLineBuffer, n); } - if (!myReader.ready()) { + + boolean isReady = availableUnsupported || myReader.ready(); + + if (!isReady) { TimeoutUtil.sleep(mySleepingPolicy.getTimeToSleep(n > 0)); - if (!myReader.ready()) { - if (myLineBuffer.length() > 0) { - sendLine(myLineBuffer); - } - onBufferExhaustion(); + isReady = myReader.ready(); + } + + if (!isReady) { + if (myLineBuffer.length() > 0) { + sendLine(myLineBuffer); } + onBufferExhaustion(); } } diff --git a/platform/util/util.iml b/platform/util/util.iml index 8f5faea7dfc2..fe6437ebbc27 100644 --- a/platform/util/util.iml +++ b/platform/util/util.iml @@ -23,6 +23,7 @@ +