-- File: PupStream.Mesa,  Last Edit: HGM  January 15, 1981  6:36 PM

DIRECTORY
  Stream USING [Handle],
  PupTypes USING [Pair, PupAddress, PupHostID, PupNetID, PupSocketID];

PupStream: DEFINITIONS =
  BEGIN

  -- Copied things from PupTypes
  PupAddress: TYPE = PupTypes.PupAddress;
  PupNetID: TYPE = PupTypes.PupNetID;
  PupHostID: TYPE = PupTypes.PupHostID;
  PupSocketID: TYPE = PupTypes.PupSocketID;

  --  TYPEs
  Tocks: TYPE = RECORD [CARDINAL];
  veryLongWait: Tocks = [LAST[CARDINAL]];
  veryShortWait: Tocks = [0];
  PupOpenMode: TYPE = {alreadyOpened, sendRfc, wait};
  CloseReason: TYPE = {
    localClose, localAbort, remoteClose, noRouteToNetwork, transmissionTimeout, remoteReject};

  -- Byte Stream Interface
  PupByteStreamCreate: PROCEDURE [remote: PupAddress, ticks: Tocks]
    RETURNS [Stream.Handle];
  PupByteStreamAbort: PROCEDURE [Stream.Handle, STRING];

  -- Listeners
  PupListener: TYPE = POINTER TO PupListenerObject;
  PupListenerObject: TYPE = RECORD [PROCEDURE];
  CreatePupByteStreamListener: PROCEDURE [
    local: PupSocketID, proc: PROCEDURE [Stream.Handle, PupAddress],
    ticks: Tocks, filter: PROCEDURE [PupAddress] ← DontReject]
    RETURNS [PupListener];
  DestroyPupListener: PROCEDURE [PupListener];
  DontReject: PROCEDURE [PupAddress];
  RejectThisRequest: ERROR [error: STRING];

  -- Used only by Listeners+Debugging
  PupByteStreamMake: PROCEDURE [
    local: PupSocketID, remote: PupAddress, ticks: Tocks,
    mode: PupOpenMode, id: PupTypes.Pair] RETURNS [Stream.Handle];

  -- ERRORs
  StreamClosing: ERROR [why: CloseReason, text: STRING];


  -- Performance tuning and debugging
  -- Call these before creating the connection
  SetMaxAllocation: PROCEDURE [CARDINAL];
  SetMaxBufferSize: PROCEDURE [CARDINAL];
  SetPinging: PROCEDURE [BOOLEAN];

  -- Tocks
  SecondsToTocks: PROCEDURE [CARDINAL] RETURNS [Tocks];
  MsToTocks: PROCEDURE [CARDINAL] RETURNS [Tocks];

  -- On/Off
  PupPackageMake: PROCEDURE;
  PupPackageDestroy: PROCEDURE;

  -- NameConversion
  GetPupAddress: PROCEDURE [POINTER TO PupAddress, STRING];
  PupNameLookup: PROCEDURE [POINTER TO PupAddress, STRING];
  NameLookupErrorCode: TYPE = {noRoute, noResponse, errorFromServer}; -- if error

  -- ERRORs
  PupNameTrouble: ERROR [e: STRING, code: NameLookupErrorCode];
  TockConversionTroubles: ERROR;

  END.