mirror of https://github.com/sbt/sbt.git
Fix canonical input for network client
It is valid for the thin client input stream to return -1 as an EOF when the user inputs ctrl+d in canonical mode.
This commit is contained in:
parent
50f649c3c9
commit
a0db985c36
|
|
@ -934,12 +934,9 @@ class NetworkClient(
|
||||||
val stopped = new AtomicBoolean(false)
|
val stopped = new AtomicBoolean(false)
|
||||||
override final def run(): Unit = {
|
override final def run(): Unit = {
|
||||||
def read(): Unit = {
|
def read(): Unit = {
|
||||||
inputStream.read match {
|
val b = inputStream.read
|
||||||
case -1 =>
|
inLock.synchronized(stdinBytes.offer(b))
|
||||||
case b =>
|
if (attached.get()) drain()
|
||||||
inLock.synchronized(stdinBytes.offer(b))
|
|
||||||
if (attached.get()) drain()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
try read()
|
try read()
|
||||||
catch { case _: InterruptedException | NonFatal(_) => stopped.set(true) } finally {
|
catch { case _: InterruptedException | NonFatal(_) => stopped.set(true) } finally {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ package server
|
||||||
|
|
||||||
import java.io.{ IOException, InputStream, OutputStream }
|
import java.io.{ IOException, InputStream, OutputStream }
|
||||||
import java.net.{ Socket, SocketTimeoutException }
|
import java.net.{ Socket, SocketTimeoutException }
|
||||||
import java.nio.channels.ClosedChannelException
|
|
||||||
import java.util.concurrent.{
|
import java.util.concurrent.{
|
||||||
ConcurrentHashMap,
|
ConcurrentHashMap,
|
||||||
Executors,
|
Executors,
|
||||||
|
|
@ -85,7 +84,7 @@ final class NetworkChannel(
|
||||||
private var initialized = false
|
private var initialized = false
|
||||||
private val pendingRequests: mutable.Map[String, JsonRpcRequestMessage] = mutable.Map()
|
private val pendingRequests: mutable.Map[String, JsonRpcRequestMessage] = mutable.Map()
|
||||||
|
|
||||||
private[this] val inputBuffer = new LinkedBlockingQueue[Byte]()
|
private[this] val inputBuffer = new LinkedBlockingQueue[Int]()
|
||||||
private[this] val pendingWrites = new LinkedBlockingQueue[(Array[Byte], Boolean)]()
|
private[this] val pendingWrites = new LinkedBlockingQueue[(Array[Byte], Boolean)]()
|
||||||
private[this] val attached = new AtomicBoolean(false)
|
private[this] val attached = new AtomicBoolean(false)
|
||||||
private[this] val alive = new AtomicBoolean(true)
|
private[this] val alive = new AtomicBoolean(true)
|
||||||
|
|
@ -107,7 +106,7 @@ final class NetworkChannel(
|
||||||
interactive.set(true)
|
interactive.set(true)
|
||||||
jsonRpcNotify(promptChannel, "")
|
jsonRpcNotify(promptChannel, "")
|
||||||
}
|
}
|
||||||
private[sbt] def write(byte: Byte) = inputBuffer.add(byte)
|
private[sbt] def write(byte: Byte) = inputBuffer.add(byte.toInt)
|
||||||
|
|
||||||
private[this] val terminalHolder = new AtomicReference[Terminal](Terminal.NullTerminal)
|
private[this] val terminalHolder = new AtomicReference[Terminal](Terminal.NullTerminal)
|
||||||
override private[sbt] def terminal: Terminal = terminalHolder.get
|
override private[sbt] def terminal: Terminal = terminalHolder.get
|
||||||
|
|
@ -634,15 +633,12 @@ final class NetworkChannel(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] lazy val inputStream: InputStream = new InputStream {
|
private[this] lazy val inputStream: InputStream = new Terminal.SimpleInputStream {
|
||||||
override def read(): Int = {
|
override def read(): Int = {
|
||||||
import sjsonnew.BasicJsonProtocol._
|
import sjsonnew.BasicJsonProtocol._
|
||||||
try {
|
try {
|
||||||
jsonRpcNotify(readSystemIn, "")
|
jsonRpcNotify(readSystemIn, "")
|
||||||
inputBuffer.take & 0xFF match {
|
inputBuffer.take
|
||||||
case -1 => throw new ClosedChannelException()
|
|
||||||
case b => b
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
case e: IOException =>
|
case e: IOException =>
|
||||||
try jsonRpcNotify(cancelReadSystemIn, "")
|
try jsonRpcNotify(cancelReadSystemIn, "")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue