src/Pure/System/system_channel.scala
changeset 45028 d608dd8cd409
parent 45027 f459e93a038e
child 45055 55274f7e306b
     1.1 --- a/src/Pure/System/system_channel.scala	Wed Sep 21 20:35:50 2011 +0200
     1.2 +++ b/src/Pure/System/system_channel.scala	Wed Sep 21 22:18:17 2011 +0200
     1.3 @@ -1,13 +1,15 @@
     1.4  /*  Title:      Pure/System/system_channel.scala
     1.5      Author:     Makarius
     1.6  
     1.7 -Portable system channel for inter-process communication.
     1.8 +Portable system channel for inter-process communication, based on
     1.9 +named pipes or sockets.
    1.10  */
    1.11  
    1.12  package isabelle
    1.13  
    1.14  
    1.15  import java.io.{InputStream, OutputStream, File, FileInputStream, FileOutputStream, IOException}
    1.16 +import java.net.{ServerSocket, InetAddress}
    1.17  
    1.18  
    1.19  object System_Channel
    1.20 @@ -23,6 +25,8 @@
    1.21  }
    1.22  
    1.23  
    1.24 +/** named pipes **/
    1.25 +
    1.26  object Fifo_Channel
    1.27  {
    1.28    private val next_fifo = new Counter
    1.29 @@ -30,8 +34,6 @@
    1.30  
    1.31  class Fifo_Channel extends System_Channel
    1.32  {
    1.33 -  /* operations on named pipes */
    1.34 -
    1.35    private def mk_fifo(): String =
    1.36    {
    1.37      val i = Fifo_Channel.next_fifo()
    1.38 @@ -81,8 +83,6 @@
    1.39    }
    1.40  
    1.41  
    1.42 -  /* initialization */
    1.43 -
    1.44    private val fifo1 = mk_fifo()
    1.45    private val fifo2 = mk_fifo()
    1.46  
    1.47 @@ -90,7 +90,6 @@
    1.48  
    1.49    def rendezvous(): (OutputStream, InputStream) =
    1.50    {
    1.51 -    /*rendezvous*/
    1.52      val output_stream = fifo_output_stream(fifo1)
    1.53      val input_stream = fifo_input_stream(fifo2)
    1.54      (output_stream, input_stream)
    1.55 @@ -98,3 +97,21 @@
    1.56  
    1.57    def accepted() { rm_fifo(fifo1); rm_fifo(fifo2) }
    1.58  }
    1.59 +
    1.60 +
    1.61 +/** sockets **/
    1.62 +
    1.63 +class Socket_Channel extends System_Channel
    1.64 +{
    1.65 +  private val server = new ServerSocket(0, 2, InetAddress.getByName("127.0.0.1"))
    1.66 +
    1.67 +  def isabelle_args: List[String] = List("-T", "127.0.0.1:" + server.getLocalPort)
    1.68 +
    1.69 +  def rendezvous(): (OutputStream, InputStream) =
    1.70 +  {
    1.71 +    val socket = server.accept
    1.72 +    (socket.getOutputStream, socket.getInputStream)
    1.73 +  }
    1.74 +
    1.75 +  def accepted() { server.close }
    1.76 +}