
#INCLUDE "course.module"
#INCLUDE "dynproc.module"


PROC do.network (VAL INT libhandle, CHAN OF BYTE out)
  VAL INT depth IS 10:
  CHAN OF INT rproc.in, rproc.out:
  PAR

    SEQ i = (depth - 1) FOR depth STEP (-1)
      rproc.in ! i

    INITIAL INT v IS (-1):
    WHILE v <> 0
      SEQ
        rproc.out ? v
        out.int (v, 0, out)
        out ! '*n'

    INT res:
    SEQ
      [1]CHAN OF ANY x.in RETYPES [rproc.in]:
      [1]CHAN OF ANY x.out RETYPES [rproc.out]:
      ccsp.run ("test.recursion", libhandle, x.in, x.out, res)
:

PROC testdyn3 (CHAN OF BYTE kyb, scr, err)
  INT handle:
  SEQ
    out.string ("about to start*n", 0, scr)
    ccsp.openlib ("./testlib.so", handle)
    IF
      handle = 0
        out.string ("unable to open testlib.so :(*n", 0, scr)
      TRUE
        SEQ
          do.network (handle, scr)
          ccsp.closelib (handle)
    out.string ("all done*n", 0, scr)
:


