mirror of https://github.com/sbt/sbt.git
Fallback client
This commit is contained in:
parent
a4984c7042
commit
1f6d19258f
|
|
@ -337,6 +337,13 @@ class NetworkClient(
|
||||||
conn
|
conn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def bootSocketOpt(bootSocketName: String): Option[Socket] =
|
||||||
|
Try(ClientSocket.bootSocket(bootSocketName)).toOption match
|
||||||
|
case Some(x) => Some(x)
|
||||||
|
case None if Util.isWindows =>
|
||||||
|
Try(ClientSocket.localSocket(bootSocketName, useJNI)).toOption
|
||||||
|
case _ => None
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forks another instance of sbt in the background.
|
* Forks another instance of sbt in the background.
|
||||||
* This instance must be shutdown explicitly via `sbt -client shutdown`
|
* This instance must be shutdown explicitly via `sbt -client shutdown`
|
||||||
|
|
@ -351,9 +358,7 @@ class NetworkClient(
|
||||||
* For unknown reasons, linux sometimes struggles to connect to the socket in some
|
* For unknown reasons, linux sometimes struggles to connect to the socket in some
|
||||||
* scenarios.
|
* scenarios.
|
||||||
*/
|
*/
|
||||||
var socket: Option[Socket] =
|
var socket: Option[Socket] = bootSocketOpt(bootSocketName)
|
||||||
if (!Properties.isLinux) Try(ClientSocket.bootSocket(bootSocketName, useJNI)).toOption
|
|
||||||
else None
|
|
||||||
val term = Terminal.console
|
val term = Terminal.console
|
||||||
term.exitRawMode()
|
term.exitRawMode()
|
||||||
var serverStderrFile: Option[File] = None
|
var serverStderrFile: Option[File] = None
|
||||||
|
|
@ -436,7 +441,7 @@ class NetworkClient(
|
||||||
if (!startServer) {
|
if (!startServer) {
|
||||||
val deadline = 5.seconds.fromNow
|
val deadline = 5.seconds.fromNow
|
||||||
while (socket.isEmpty && !deadline.isOverdue()) {
|
while (socket.isEmpty && !deadline.isOverdue()) {
|
||||||
socket = Try(ClientSocket.bootSocket(bootSocketName, useJNI)).toOption
|
socket = bootSocketOpt(bootSocketName)
|
||||||
if (socket.isEmpty) Thread.sleep(20)
|
if (socket.isEmpty) Thread.sleep(20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -457,7 +462,7 @@ class NetworkClient(
|
||||||
val buffer = mutable.ArrayBuffer.empty[Byte]
|
val buffer = mutable.ArrayBuffer.empty[Byte]
|
||||||
while (readThreadAlive.get) {
|
while (readThreadAlive.get) {
|
||||||
if (socket.isEmpty) {
|
if (socket.isEmpty) {
|
||||||
socket = Try(ClientSocket.bootSocket(bootSocketName, useJNI)).toOption
|
socket = bootSocketOpt(bootSocketName)
|
||||||
}
|
}
|
||||||
socket.foreach { s =>
|
socket.foreach { s =>
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@
|
||||||
package sbt
|
package sbt
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import java.io.File
|
import java.io.{ File, InputStream, OutputStream }
|
||||||
import java.net.{ Socket, URI, InetAddress }
|
import java.net.{ InetAddress, Socket, StandardProtocolFamily, URI, UnixDomainSocketAddress }
|
||||||
|
import java.nio.channels.{ Channels, SocketChannel }
|
||||||
import sjsonnew.BasicJsonProtocol
|
import sjsonnew.BasicJsonProtocol
|
||||||
import sjsonnew.support.scalajson.unsafe.{ Parser, Converter }
|
import sjsonnew.support.scalajson.unsafe.{ Parser, Converter }
|
||||||
import sjsonnew.shaded.scalajson.ast.unsafe.JValue
|
import sjsonnew.shaded.scalajson.ast.unsafe.JValue
|
||||||
|
|
@ -46,6 +47,14 @@ object ClientSocket {
|
||||||
if (isWindows) new Win32NamedPipeSocket(s"\\\\.\\pipe\\$name", useJNI)
|
if (isWindows) new Win32NamedPipeSocket(s"\\\\.\\pipe\\$name", useJNI)
|
||||||
else new UnixDomainSocket(name, useJNI)
|
else new UnixDomainSocket(name, useJNI)
|
||||||
|
|
||||||
/** Connects to a Unix domain socket at the given path on all platforms (including Windows 10+). */
|
def bootSocket(path: String): Socket =
|
||||||
def bootSocket(path: String, useJNI: Boolean): Socket = new UnixDomainSocket(path, useJNI)
|
val ch = SocketChannel.open(StandardProtocolFamily.UNIX)
|
||||||
|
ch.connect(UnixDomainSocketAddress.of(path))
|
||||||
|
new Socket:
|
||||||
|
private val in = Channels.newInputStream(ch)
|
||||||
|
private val out = Channels.newOutputStream(ch)
|
||||||
|
override def getInputStream: InputStream = in
|
||||||
|
override def getOutputStream: OutputStream = out
|
||||||
|
override def close(): Unit = ch.close()
|
||||||
|
override def isClosed: Boolean = !ch.isOpen
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue