Patch title: Release 87 bulk changes
Abstract:
File: /pliant/util/network/tcp_debug.pli
Key:
    Removed line
    Added line
   
module "/pliant/language/stream.pli"
module "/pliant/language/unsafe.pli"
module "/pliant/language/stream/pipe.pli"


function tcp_debug src_port dest_ip dest_port log_file
  arg Int src_port ; arg Str dest_ip ; arg Int dest_port ; arg Str log_file
  (var Stream log) open (shunt log_file<>"" log_file "handle:1") out+safe+linecache ; var Sem sem
  var Int count := 0
  while true
    count += 1 
    part session "wait for TCP connection on port "+string:src_port
      var Link:Stream s :> new Stream
      s open "tcp:/server/"+string:src_port in+out+noautopost+safe
      sem request
      log writeline string:count+" == "+string:datetime+" =="
      sem release
      thread
        share sem
        var Link:Stream d :> new Stream
        d open "tcp://"+dest_ip+"/client/"+string:dest_port in+out+noautopost+safe
        thread
          part "forward TCP port "+string:src_port+" to "+dest_ip+":"+string:dest_port
            share sem
            while { d read_available (var Address adr2) (var Int size2) ; size2<>0 }
              sem request
              log writechars string:count+" -> "
              (var Str line) set adr2 size2 false
              for (var Int i) 0 line:len-1
                if line:i="[lf]"
                  log writechars "[lf]"+string:count+" -> "
                eif line:i:number>=32 and line:i:number<128
                  log writechars line:i
                else
                  log writechars "?"
              log writeline ""
              sem release
              s raw_write adr2 size2
              s flush anytime
            s safe_configure "shutdown"
        part "backward from "+dest_ip+":"+string:dest_port+" to TCP port "+string:src_port
          while { s read_available (var Address adr1) (var Int size1) ; size1<>0 }
            sem request
            log writechars string:count+" <- "
            (var Str line) set adr1 size1 false
            for (var Int i) 0 line:len-1
              if line:i="[lf]"
                log writechars "[lf]"+string:count+" <- "
              eif line:i:number>=32 and line:i:number<128
                log writechars line:i
              else
                log writechars "?"
            log writeline ""
            sem release
            d raw_write adr1 size1
            d flush anytime
          d safe_configure "shutdown"
  

export tcp_debug