OEP

117

Title

Recursive channel types

Summary

Allow channel types to include channels of their own type.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2002-09-03

Keywords

language channel-types patterns

Recursive channel-types add a useful feature to the existing mobile channel-types -- the ability for a channel within a mobile channel-type to transport ends of its own type. This is particularly useful in client-server networks that involve one-to-one connections between clients and servers, established over shared channels -- it provides a means for the client to say "I'm done" to the server. For example:

RECURSIVE CHAN TYPE BUF.MGR
  MOBILE RECORD
    CHAN INT req?:
    CHAN MOBILE []BYTE resp!, ret?:
    CHAN BUF.MGR! done?:
:

PROC server (SHARED CHAN BUF.MGR? clients?)
  BUF.MGR? link:
  WHILE TRUE
    SEQ
      CLAIM clients?
        clients ? link
      INITIAL BOOL ok IS TRUE:
      WHILE ok
        ALT
          INT size:
          link[req] ? size
            ...  allocate buffer, give to client, take back again
          BUF.MGR! cli:
          link[done] ? cli
            ok := FALSE
:

PROC client (SHARED CHAN BUF.MGR? to.servers!)
  SEQ
    ...  some initial local processing
    BUF.MGR? svr:
    BUF.MGR! cli:
    SEQ
      svr, cli := MOBILE BUF.MGR
      -- connect to a server
      CLAIM to.servers!
        to.servers ! svr
      ...  communicate with server using "cli"
      cli[done] ! cli
      -- "cli" and "svr" both undefined
:

The interesting bit is the last action performed by the client, "cli[done] ! cli", that returns the channel-end to the server, to which it is connected. One way to think of this is to imagine the two processes connected by a hose-pipe, where the returning action turns the hose-pipe in on itself at the client end, until it "pops out" at the server end.

For completeness, a network using the above "client" and "server" processes is easily constructed (using anonymous channel-types and forked processes):

PROC network (VAL INT n.cli, n.svr)
  SHARED CHAN BUF.MGR c:
  FORKING
        SEQ
      SEQ i = 0 FOR n.cli
        FORK client (c!)
      SEQ i = 0 FOR n.svr
        FORK server (c?)
:

OEP/117 (last edited 2007-09-27 00:25:31 by ats1)