summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/CompileSocket.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-29 19:11:38 +0000
committerPaul Phillips <paulp@improving.org>2010-01-29 19:11:38 +0000
commitbb149d1b96015d83e58de5ea9b380550267c4f06 (patch)
treeef805e2c02a29e96f5703790c6f91b9cabb091ea /src/compiler/scala/tools/nsc/CompileSocket.scala
parentad0fd8bca3c41a15ff688a7ca5e3278fa2ce127b (diff)
downloadscala-bb149d1b96015d83e58de5ea9b380550267c4f06.tar.gz
scala-bb149d1b96015d83e58de5ea9b380550267c4f06.tar.bz2
scala-bb149d1b96015d83e58de5ea9b380550267c4f06.zip
A few compiler IO lib bits I have been needing:...
A few compiler IO lib bits I have been needing: some basic conveniences for directories and sockets, and some cleanups in CompileSocket. Review by community.
Diffstat (limited to 'src/compiler/scala/tools/nsc/CompileSocket.scala')
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala46
1 files changed, 16 insertions, 30 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index 9e626ead39..06f0f15d9d 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -12,11 +12,9 @@ import java.util.regex.Pattern
import java.net._
import java.security.SecureRandom
-import io.{ File, Path }
+import io.{ File, Path, Process, Socket }
import scala.util.control.Exception.catching
-// class CompileChannel { }
-
/** This class manages sockets for the fsc offline compiler. */
class CompileSocket {
protected def compileClient: StandardCompileClient = CompileClient //todo: lazy val
@@ -80,23 +78,16 @@ class CompileSocket {
/** The command which starts the compile server, given vm arguments.
*
* @param vmArgs the argument string to be passed to the java or scala command
- * the string must be either empty or start with a ' '.
*/
- private def serverCommand(vmArgs: String): String =
- vmCommand + vmArgs + " " + serverClass
+ private def serverCommand(vmArgs: Seq[String]): Seq[String] =
+ Seq(vmCommand) ++ vmArgs ++ Seq(serverClass) filterNot (_ == "")
/** Start a new server; returns true iff it succeeds */
private def startNewServer(vmArgs: String) {
- val cmd = serverCommand(vmArgs)
- info("[Executed command: " + cmd + "]")
- try {
- Runtime.getRuntime().exec(cmd)
-// val exitVal = proc.waitFor()
-// info("[Exit value: " + exitVal + "]")
- } catch {
- case ex: IOException =>
- fatal("Cannot start compilation daemon." +
- "\ntried command: " + cmd)
+ val cmd = serverCommand(vmArgs split " " toSeq)
+ info("[Executed command: %s]" format cmd)
+ try Process exec cmd catch {
+ case ex: IOException => fatal("Cannot start compilation daemon.\ntried command: %s" format cmd)
}
}
@@ -157,25 +148,23 @@ class CompileSocket {
if (attempts == 0) {
error("Unable to establish connection to compilation daemon")
null
- } else {
+ }
+ else {
val port = if(create) getPort(vmArgs) else pollPort()
if(port < 0) return null
val hostAdr = InetAddress.getLocalHost()
- try {
- val result = new Socket(hostAdr, port)
- info("[Connected to compilation daemon at port " + port + "]")
- result
- } catch {
- case e: /*IO+Security*/Exception =>
+ Socket(hostAdr, port).either match {
+ case Right(res) =>
+ info("[Connected to compilation daemon at port %d]" format port)
+ res
+ case Left(e) =>
info(e.toString)
- info("[Connecting to compilation daemon at port " +
- port + " failed; re-trying...]")
+ info("[Connecting to compilation daemon at port %d failed; re-trying...]" format port)
if (attempts % 2 == 0)
portFile(port).delete // 50% chance to stop trying on this port
Thread.sleep(100) // delay before retrying
-
getsock(attempts - 1)
}
}
@@ -201,10 +190,7 @@ class CompileSocket {
}
def getSocket(hostName: String, port: Int): Socket =
- try new Socket(hostName, port) catch {
- case e @ (_: IOException | _: SecurityException) =>
- fatal("Unable to establish connection to server %s:%d; exiting".format(hostName, port))
- }
+ Socket(hostName, port).opt getOrElse fatal("Unable to establish connection to server %s:%d; exiting".format(hostName, port))
def getPassword(port: Int): String = {
val ff = portFile(port)