-- File: SequinPrivate.mesa
-- Last edited by Levin:   6-Jul-81 15:30:41

DIRECTORY
  AltoDefs USING [BYTE],
  BufferDefs USING [Buffer, QueueObject],
  ControlDefs USING [FrameHandle],
  PupDefs USING [PupBuffer, PupSocket],
  PupTypes USING [PupType];

SequinPrivate: DEFINITIONS =

  BEGIN


  -- Types --

  Handle: TYPE = POINTER TO SequinObject;

  SequinObject: TYPE = MONITORED RECORD [
    id: SequinID ← [inOut[0, 0]],
    allocate: Byte ← 1,
    retransmitSequence: SequenceNumber ← 0,
    retransmitQueue: BufferDefs.QueueObject ← NULL,
    getQueue: BufferDefs.QueueObject ← NULL,
    socket: PupDefs.PupSocket ← NULL,
    goAhead: CONDITION,
    buffersToRequeue: Byte ← 0,
    pupType: PupTypes.PupType,
    state: {init, open, destroyed} ← init,
    broken: BOOLEAN ← FALSE,
    recentRestart, restartRequested: BOOLEAN ← FALSE,
    pings: PingCount ← 0,
    lastPacketTime: Seconds ← NULL,
    requeuer: PROCEDURE [BufferDefs.Buffer] ← NULL,
    closure: RequeueClosure ← NULL];

  SequinID: TYPE = MACHINE DEPENDENT RECORD [
    SELECT OVERLAID * FROM
      inOut => [inPart: WORD, outPart: WORD],
      pieces => [allocate: Byte, receiveSequence: SequenceNumber,
		control: SequinControl, sendSequence: SequenceNumber],
      ENDCASE];

  SequinControl: TYPE = MACHINE DEPENDENT{
    data(0), ack(1), nop(2), restart(3), check(4), open(5), break(6), close(7),
    closed(8), destroy(9), dallying(10), quit(11), broken(12), retransmit(13),
    stifle(14), openclose(15), opendestroy(16), (255)};

  SequenceNumber: TYPE = Byte;

  Byte: TYPE = AltoDefs.BYTE;

  Seconds: TYPE = LONG CARDINAL;

  RequeueClosure: TYPE = ControlDefs.FrameHandle;

  maxPings: CARDINAL = 10;
  PingCount: TYPE = [0..maxPings];


  -- Variables --

  maxBytes: CARDINAL;

  maxAllocate: CARDINAL;


  -- Procedures --

  MakeRequeueClosure: PROCEDURE [sequin: Handle] RETURNS [RequeueClosure];

  Send: PROCEDURE [sequin: Handle, packet: PupDefs.PupBuffer, control: SequinControl];

  SocketWarmer: PROCEDURE [sequin: Handle];

  END.