-- Socket.Mesa (last edited by: BLyon on: January 27, 1981  5:10 PM)

DIRECTORY
  BufferDefs USING [OisBuffer],
  OISCPTypes USING [WaitTime],
  NSAddress USING [NetworkAddress];

Socket: DEFINITIONS =
  BEGIN

  -- definitions

  -- various types used by socket channels.
  ChannelHandle: TYPE = REF ChannelObject;
  ChannelObject: TYPE;

  TransferStatus: TYPE = {
    pending, goodCompletion, aborted, noRouteToNetwork, hardwareProblem,
    invalidDestAddr,
    -- the following apply to circuit-like media only and mostly to the first packet sent
    noAnswerOrBusy, -- auto-dial case only
    noTranslationForDestination, -- no phone number for this destination
    circuitInUse, -- being used to talk to another destination
    circuitNotReady, -- dial the phone or connect modems (non-auto-dial case)
    noDialingHardware, dialerHardwareProblem};
  SocketStatus: TYPE = RECORD [
    localAddr: NSAddress.NetworkAddress, state: State, incompleteGets: CARDINAL];
  State: TYPE = {active, aborted};

  WaitTime: TYPE = OISCPTypes.WaitTime; -- msecs

  -- constants used by the client.
  uniqueNetworkAddr: READONLY NSAddress.NetworkAddress;
  defaultWaitTime: WaitTime = 60000; -- msecs
  maxInternetOISPktLength: CARDINAL = 576; -- in bytes and includes header

  -- interface

  -- exported by SocketImpl.
  -- procedures
  AssignNetworkAddress: PROCEDURE RETURNS [NSAddress.NetworkAddress];
  Create: PROCEDURE [
    local: NSAddress.NetworkAddress, send: CARDINAL ← 1,
    -- maximum no. of send buffers used at one time
    receive: CARDINAL ← 2, -- maximum no. of receive buffers used at one time
    reserve: CARDINAL ← 0, -- more buffers can be allocated but not used
    privateBuffers: BOOLEAN ← TRUE]
    -- True => the buffers will be ALLOCATED for this channel;  False => buffers will be shared will the system's buffers (and no new buffers will be allocated; examples of these are the EchoServer and NetworkStream Listeners).  Be careful - False values can deadlock the system;  users should only use one buffer at a time and return it asap without trying to grab other resources (or other buffers).
     RETURNS [ChannelHandle];
  Delete: PROCEDURE [cH: ChannelHandle];
  Abort: PROCEDURE [cH: ChannelHandle];
  Reset: PROCEDURE [cH: ChannelHandle];
  GetStatus: PROCEDURE [cH: ChannelHandle] RETURNS [SocketStatus];
  SetWaitTime: PROCEDURE [cH: ChannelHandle, time: WaitTime];
  -- sending and receiving packets - they are in real buffers  
  PutPacket: PROCEDURE [cH: ChannelHandle, b: BufferDefs.OisBuffer];
  -- asynchronous, return is immediate;  when the buffer is finally sent the dispatcher calls b.requeueProcedure[b] to relinquish system ownership of the buffer.  If the error ChannelAborted ocurs then the caller still own the buffer, b.  This procedure does not attemp to broadcast a packets to ALL nets; use PutPacketToAllConnectedNets for that.
  PutPacketToAllConnectedNets: PROCEDURE [cH: ChannelHandle, b: BufferDefs.OisBuffer];  -- this procedure broadcast a packet to all hosts on all locally connected nets. The user only need supply the destination socket number of the packet.
  GetPacket: PROCEDURE [cH: ChannelHandle] RETURNS [b: BufferDefs.OisBuffer];
  -- this waits - for a packet to arrive or a TimeOut or an ChannelAborted.
  -- errors
  TimeOut: ERROR; -- error when timeout ocurrs on blocked call like TransferWait
  ChannelAborted: ERROR; -- error when state is aborted
  ChannelError: ERROR;
  -- error when bad software structuring, or bad parameter to calls

  END.

LOG

(trimmed to Teak)
Time: January 22, 1980  8:57 PM  By: Dalal  Action: modified SocketStatus.
Time: January 26, 1980  10:12 AM  By: Dalal  Action: made ChannelHandle LONG.
Time: March 11, 1980  3:21 PM  By: BLyon  Action: Put, Get use PhysicalRecordHandles instead of CrateHandles. Added  Reset.
Time: June 18, 1980  2:23 PM  By: BLyon  Action: use NSAddress instead of NSAddress;
uniqueNetworkAddr from CONSTANT to READONLY, ChannelHandle & GetHandle are opaque types.
Time: August 6, 1980  10:17 AM  By: Garlick  Action: Added several TransferStatus's for circuit-oriented network errors.
Time: October 10, 1980  4:50 PM  By: Garlick  Action: Added TransferStatus noAnswerOrBusy 
Time: January 6, 1981  2:21 PM  By: BLyon  Action: Post Mokelumne rework.