-- Copyright (C) 1981, 1982, 1984  by Xerox Corporation. All rights reserved. 
-- File: SequinPrivate.mesa

-- HGM: 10-Dec-84 21:25:54
-- Hankins:   24-Jul-84 14:45:27     Klamath update (pup and closure changes)
-- MJohnson:  7-Jan-82 16:50:19
-- Levin:   6-Jul-81 16:16:17

DIRECTORY
  Buffer USING [AccessHandle, Buffer, QueueObject],
  Environment USING [Byte],
  PupDefs USING [PupBuffer, PupSocket],
  PupTypes USING [PupType];

SequinPrivate: DEFINITIONS =

  BEGIN

  -- Types --

  Handle: TYPE = POINTER TO SequinObject;
  LongHandle: TYPE = MACHINE DEPENDENT RECORD [
    shortHandle: Handle, fill: CARDINAL ← 0];

  SequinObject: TYPE = MONITORED RECORD [
    id: SequinID ← [inOut[0, 0]],
    allocate: Byte ← 1,
    retransmitSequence: SequenceNumber ← 0,
    retransmitQueue: Buffer.QueueObject ← NULL,
    getQueue: Buffer.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];

  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 = Environment.Byte;
  Seconds: TYPE = LONG CARDINAL;
  maxPings: CARDINAL = 10;
  PingCount: TYPE = [0..maxPings];

  -- Variables --

  maxBytes: CARDINAL;
  maxAllocate: CARDINAL;
  bufferPool: Buffer.AccessHandle;

  -- Procedures --

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

  SocketWarmer: PROCEDURE [sequin: Handle];

  END.