src/Pure/System/system_channel.ML
changeset 69441 0bd51c6aaa8b
parent 69440 eaf66384cfe8
child 69448 51e696887b81
equal deleted inserted replaced
69440:eaf66384cfe8 69441:0bd51c6aaa8b
    17 structure System_Channel: SYSTEM_CHANNEL =
    17 structure System_Channel: SYSTEM_CHANNEL =
    18 struct
    18 struct
    19 
    19 
    20 datatype T = System_Channel of BinIO.instream * BinIO.outstream;
    20 datatype T = System_Channel of BinIO.instream * BinIO.outstream;
    21 
    21 
    22 fun input_line (System_Channel (in_stream, _)) =
    22 fun input_line (System_Channel (stream, _)) = Bytes.read_line stream;
    23   let
    23 fun inputN (System_Channel (stream, _)) n = Bytes.read_block stream n;
    24     val result = trim_line o String.implode o rev;
       
    25     fun read cs =
       
    26       (case BinIO.input1 in_stream of
       
    27         NONE => if null cs then NONE else SOME (result cs)
       
    28       | SOME b =>
       
    29           (case Byte.byteToChar b of
       
    30             #"\n" => SOME (result cs)
       
    31           | c => read (c :: cs)));
       
    32   in read [] end;
       
    33 
    24 
    34 fun inputN (System_Channel (in_stream, _)) n =
    25 fun output (System_Channel (_, stream)) s = File.output stream s;
    35   Byte.bytesToString (BinIO.inputN (in_stream, n));
    26 fun flush (System_Channel (_, stream)) = BinIO.flushOut stream;
    36 
       
    37 fun output (System_Channel (_, out_stream)) s =
       
    38   File.output out_stream s;
       
    39 
       
    40 fun flush (System_Channel (_, out_stream)) =
       
    41   BinIO.flushOut out_stream;
       
    42 
    27 
    43 fun rendezvous name =
    28 fun rendezvous name =
    44   let
    29   let
    45     val (in_stream, out_stream) = Socket_IO.open_streams name;
    30     val (in_stream, out_stream) = Socket_IO.open_streams name;
    46     val _ = BinIO.StreamIO.setBufferMode (BinIO.getOutstream out_stream, IO.BLOCK_BUF);
    31     val _ = BinIO.StreamIO.setBufferMode (BinIO.getOutstream out_stream, IO.BLOCK_BUF);