summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/util/SocketServer.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-02-01 08:27:18 +0000
committerPaul Phillips <paulp@improving.org>2011-02-01 08:27:18 +0000
commitee4e09235afa578a7a33267061179ca338e396c0 (patch)
tree52ff21a786e84f0a3c47ef5666746591301cc47c /src/compiler/scala/tools/util/SocketServer.scala
parentd59d7f928d8a71d73d198690ab5816af3be90d6b (diff)
downloadscala-ee4e09235afa578a7a33267061179ca338e396c0.tar.gz
scala-ee4e09235afa578a7a33267061179ca338e396c0.tar.bz2
scala-ee4e09235afa578a7a33267061179ca338e396c0.zip
Eliminating duplication and trying to outrun ob...
Eliminating duplication and trying to outrun obsolescence in the exciting world of fsc. No review.
Diffstat (limited to 'src/compiler/scala/tools/util/SocketServer.scala')
-rw-r--r--src/compiler/scala/tools/util/SocketServer.scala31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/util/SocketServer.scala b/src/compiler/scala/tools/util/SocketServer.scala
index e9a837fb04..5f5cb28c4c 100644
--- a/src/compiler/scala/tools/util/SocketServer.scala
+++ b/src/compiler/scala/tools/util/SocketServer.scala
@@ -12,13 +12,7 @@ package scala.tools.util
import java.io.{ PrintWriter, BufferedOutputStream, BufferedReader, InputStreamReader, IOException }
import java.net.{ Socket, ServerSocket, SocketException, SocketTimeoutException }
-object SocketServer
-{
- // After 30 idle minutes, politely exit.
- // Should the port file disappear, and the clients
- // therefore unable to contact this server instance,
- // the process will just eventually terminate by itself.
- val IdleTimeout = 1800000
+object SocketServer {
val BufferSize = 10240
def bufferedReader(s: Socket) = new BufferedReader(new InputStreamReader(s.getInputStream()))
@@ -32,8 +26,19 @@ import SocketServer._
* @author Martin Odersky
* @version 1.0
*/
-abstract class SocketServer
-{
+abstract class SocketServer {
+ // After some number of idle minutes, politely exit.
+ // Should the port file disappear, and the clients
+ // therefore unable to contact this server instance,
+ // the process will just eventually terminate by itself.
+ def fscIdleMinutes = {
+ sys.props("scala.fsc.idle.minutes") match {
+ case null => 30
+ case str => try str.toInt catch { case _: Exception => 30 }
+ }
+ }
+ def fscIdleMillis = fscIdleMinutes * 60 * 1000
+
def shutDown: Boolean
def session()
@@ -75,9 +80,9 @@ abstract class SocketServer
def run() {
def fail(s: String) = fatal(s format port)
-
- try serverSocket setSoTimeout IdleTimeout catch {
- case e: SocketException => fail("Could not set timeout on port: %d; exiting.")
+ Console.println("Setting timeout to " + fscIdleMillis)
+ try serverSocket setSoTimeout fscIdleMillis catch {
+ case e: SocketException => fatal("Could not set timeout on server socket; exiting.")
}
try {
@@ -94,6 +99,6 @@ abstract class SocketServer
warn("Timeout elapsed with no requests from clients on port %d; exiting" format port)
timeout()
}
- serverSocket.close()
+ finally serverSocket.close()
}
}