RPCPktIO.mesa - Reliable transmission and reception of packets
Copyright © 1984, 1986 by Xerox Corporation. All rights reserved.
Bob Hagmann, February 11, 1985 4:37:25 pm PST
Swinehart, August 1, 1985 10:37:08 am PDT
Polle Zellweger (PTZ) August 2, 1985 1:39:38 pm PDT
Russ Atkinson (RRA) April 25, 1986 10:08:11 am PST
DIRECTORY
BasicTime USING [GetClockPulses, MicrosecondsToPulses, Pulses],
Booting USING [CheckpointProc, RegisterProcs, RollbackProc],
BufferDefs USING [PupBuffer],
CommUtilDefs USING [AllocateIocb],
DriverDefs USING [ChangeNumberOfInputBuffers],
DriverTypes USING [Encapsulation, ethernetEncapsulationBytes, ethernetEncapsulationOffset],
EthernetOneFace USING [ControlBlock, ControlBlockRecord, controlBlockSize, DeviceHandle, GetNextDevice, GetStatus, hearSelf, nullDeviceHandle, QueueOutput],
PrincOpsUtils USING [IsBound, LongCopy, PsbHandleToIndex, ReadPSB],
Process USING [Detach, MsecToTicks, Pause, Yield],
PrincOps USING [PsbIndex, PsbNull],
PupDefs USING [AnyLocalPupAddress, GetFreePupBuffer, GetHopsToNetwork, PupAddress, PupPackageMake, PupRouterSendThis, PupSocket, PupSocketDestroy, PupSocketMake, ReturnFreePupBuffer, veryLongWait],
PupRouterDefs USING [maxHop],
PupTypes USING [PupAddress, PupHostID, PupNetID, PupSocketID],
RPC USING [CallFailed, unencrypted],
RPCInternal USING [DecryptPkt, DoSignal, EncryptPkt, ReplyToRFA, RPCBinding, RPCPktStreams, RPCSecurity, ServerMain],
RPCLupine USING [DataLength, Dispatcher, Header, RPCPkt],
RPCPkt USING [CallCount, Header, Machine, PktExchangeState, PktID, pktLengthOverhead],
RPCPrivate USING [GetRPCPackets, rpcSocket, ReturnBuffer],
RPCWatch USING [];
RPCPktIO: MONITOR
IMPORTS BasicTime, Booting, CommUtilDefs, DriverDefs, EthernetOneFace, PrincOpsUtils, Process, PupDefs, RPC, RPCInternal, RPCPrivate
EXPORTS RPCLupine--Encapsulation,Header--, RPCPkt--PktExchange,IdleReceive--, RPCWatch--SetSpyProc--
SHARES BufferDefs, RPCLupine = {
Encapsulation: PUBLIC TYPE = DriverTypes.Encapsulation;
Header: PUBLIC TYPE = RPCPkt.Header;
ConcreteHeader: PROC [abstract: LONG POINTER TO RPCLupine.Header] RETURNS [LONG POINTER TO Header] = INLINE {
RETURN [ abstract ];
};
callSequence: RPCPkt.CallCount ← 0; -- monotonic from this host --
******** IOCB management ********
IOCB's are kept on free chain. Allocation and freeing are imbedded in "PktExchange" procedure.
IOCB's are allocated in first 64K of memory, in resident memory.
Use "ControlBlock" proc to get pointer to give to EthernetFace.
IOCBrecord: TYPE = RECORD[next: IOCB];
IOCB: TYPE = LONG POINTER TO IOCBrecord;
iocbSize: CARDINAL = MAX[EthernetOneFace.controlBlockSize, SIZE[IOCBrecord]];
freeIOCBs: IOCBNIL;
******** sending and receiving packets ********
firstDevice: EthernetOneFace.DeviceHandle =
EthernetOneFace.GetNextDevice[EthernetOneFace.nullDeviceHandle];
myAddr: PupTypes.PupAddress;
myNet: PupTypes.PupNetID;
myDeviceHost: PupTypes.PupHostID;
myHost: RPCPkt.Machine;
sent: CARDINAL ← 0;
recvd: CARDINAL ← 0;
retransmitted: CARDINAL ← 0;
"PktExchange" implements a reliable packet exchange. There are five cases:
sending: transmit data, wait for ack
receiving: transmit ack, wait for data
call: transmit data, wait for data
endCall: transmit data, wait for ack or data (data => start of new call)
authReq: transmit RFA, wait for data (like "call", but no retransmissions)
Data and RFA packets are retransmitted until an ack is received. Ack packets are retransmitted only in response to "pleaseAck" requests. No acknowledgement after 14 transmissions is fatal (CallFailed[timeout]). When the transmitted packet has been acknowledged (if needed), a ping is sent periodically (ack packet saying pleaseAck). If necessary the ping is retransmitted until it has been acked. Failure to receive an ack for the ping is fatal (CallFailed[timeout]). Provided pings continue to be acknowledged, there is no limit on how long we will wait for the next data packet. If the client gets impatient, he can abort this process. (This corresponds to the local-machine semantics of a procedure call.)
minRetransmitMsecs: CARDINAL = 100; -- retransmit delay for local net --
msecsPerHop: CARDINAL = 500; -- approximate typical gateway hop delay? --
minPingMsecs: CARDINAL = 5000; -- initial interval between pings --
maxPingSecs: CARDINAL = 300; -- long-term ping interval --
maxTransmissions: CARDINAL ← 20; -- give up after too many transmissions --
signalTimeout: BOOLTRUE; -- debugging switch --
The retransmission delay is incremented by minPingMsecs each time we timeout, but is reset when we receive the desired packet. If n=maxTransmissions and i=minRetransmitMsecs and j=hops*msecsPerHop, we give up after i*(n*n+n)/2+n*j msecs. For the local network, that comes to 21 seconds. For a two-hop route, that comes to 41 seconds. The ping delay is doubled at each ping, up to maxPingSecs, which is 5 minutes. The maxPingSecs value is reached after about 5 minutes.
minRetransmitPulses: BasicTime.Pulses =
BasicTime.MicrosecondsToPulses[LONG[1000] * minRetransmitMsecs];
pulsesPerHop: BasicTime.Pulses =
BasicTime.MicrosecondsToPulses[LONG[1000] * msecsPerHop];
minPingPulses: BasicTime.Pulses =
BasicTime.MicrosecondsToPulses[LONG[1000] * minPingMsecs];
maxPingPulses: BasicTime.Pulses =
BasicTime.MicrosecondsToPulses[LONG[1000]*LONG[1000] * maxPingSecs];
transmitLocalPkts: BOOLTRUE;
Constants for WaitUntilSent (inside PktExchange)
shortWait: BasicTime.Pulses = -- 10 msecs --
BasicTime.MicrosecondsToPulses[LONG[1000] * 10];
longerWait: BasicTime.Pulses = -- 5 secs --
BasicTime.MicrosecondsToPulses[LONG[1000]*LONG[1000] * 5];
Waiting and wanting
idlerPkt: BufferDefs.PupBuffer ← NIL;
idlerCond: CONDITION ← [timeout:0];
waiterCond: CONDITION ← [timeout:Process.MsecToTicks[minRetransmitMsecs]];
waiterPkts: REF WaiterArray = NEW[WaiterArray ← ALL[NIL]];
WaiterArray: TYPE = ARRAY PrincOps.PsbIndex OF BufferDefs.PupBuffer;
wanting: REF WantingArray = NEW[WantingArray ← ALL[FALSE]];
WantingArray: TYPE = PACKED ARRAY PrincOps.PsbIndex OF BOOL;
Serving and idling
Number of server processes will never exceed "serversMax". If number of idle servers exceeds "idlersMax", one will abort. If number of idle servers drops below "idlersMin", one is forked.
RecvdPktTooLong: ERROR = CODE;
KillServer: ERROR = CODE;
servers: CARDINAL ← 0;
serversMax: CARDINAL ← 20;
idlers: CARDINAL ← 0;
idlersMax: NAT ← 4;
idlersMin: NAT ← 2;
PktExchange: PUBLIC PROC [inPkt: RPCLupine.RPCPkt, length: RPCLupine.DataLength, maxlength: RPCLupine.DataLength, state: RPCPkt.PktExchangeState, signalHandler: RPCLupine.Dispatcher ← NIL] RETURNS [newPkt: BOOL, newLength: RPCLupine.DataLength] = {
On exit if newPkt=TRUE, the packet has been decrypted if needed.
Normally, transmits inPkt and copies result into inPkt. If a signal occurs, calls DoSignal which handles the signal protocol up to the last resumption packet. DoSignal returns the last resume packet for us to transmit, which we do by assigning it to outPkt; that packet was allocated in DoSignal's local frame, which we must later deallocate.
outPkt: RPCLupine.RPCPkt ← inPkt; -- altered after a signal --
outPktFrame: POINTERNIL; -- DoSignal's local frame --
newLen: NAT ← 0;
We use this internally to represent newLength, since it is possible for a newLength calculation to exceed the bounds of RPCLupine.DataLength (for received packets that are encrypted, but not ours.)
DO -- loop for signal handlers --
sentTime: BasicTime.Pulses; -- initialized after sending any packet --
iocb: IOCBNIL;
IOCB management procs are imbedded for efficiency!
GetIOCB: ENTRY PROC = INLINE {
IF freeIOCBs # NIL
THEN { iocb ← freeIOCBs; freeIOCBs ← freeIOCBs.next }
ELSE { iocb ← CommUtilDefs.AllocateIocb[iocbSize] }
};
ControlBlock: PROC RETURNS [ EthernetOneFace.ControlBlock ] = INLINE {
RETURN [LOOPHOLE[iocb]];
};
ReturnIOCB: PROC = INLINE {
InnerReturn: ENTRY PROC = INLINE {
iocb.next ← freeIOCBs;
freeIOCBs ← iocb;
};
IF iocb # NIL THEN { WaitUntilSent[]; InnerReturn[] };
};
WaitUntilSent: PROC = INLINE {
Horrible! We must ensure that the ethernet microcode isn't still using our IOCB when we free or re-use it. There are two problems:
(a) a suitable response coming in before we've finished retransmitting our packet;
(b) the standard EthernetOneDriver resetting the microcode (so it forgets our request).
To handle (a) we busy-wait for up to 10msec, then wait for single ticks thereafter; to handle (b) we assume our iocb is no longer being used after it's pending for 5 secs. To do better seems to require changes to the EthernetOneFace.
WHILE EthernetOneFace.GetStatus[ControlBlock[]] = pending DO
IF BasicTime.GetClockPulses[] - sentTime < shortWait
THEN Process.Yield[]
ELSE IF BasicTime.GetClockPulses[] - sentTime < longerWait
THEN Process.Pause[1]
ELSE EXIT -- assume someone reset the microcode --;
ENDLOOP;
};
NewCallNumber: ENTRY PROC RETURNS [RPCPkt.CallCount] = INLINE {
RETURN [ callSequence ← callSequence+1 ];
};
reply: BufferDefs.PupBuffer;
recvdHeader: LONG POINTER TO Header;
myPSB: PrincOps.PsbIndex = PrincOpsUtils.PsbHandleToIndex[PrincOpsUtils.ReadPSB[]];
acked: BOOL;
thisPktID: RPCPkt.PktID;
header: LONG POINTER TO Header = @outPkt.header;
localHost: BOOL = header.destHost = myHost;
localNet: BOOL = header.destHost.net = myNet;
pingPulses: BasicTime.Pulses ← minPingPulses;
header.srceHost ← myHost;
header.srceSoc ← RPCPrivate.rpcSocket;
header.srcePSB ← myPSB;
IF header.pktID.pktSeq = 0 -- first packet of a call; yucky interface! --
THEN {
header.type ← SELECT state FROM
sending => [0, rpc, notEnd, pleaseAck, call],
call => [0, rpc, end, dontAck, call],
authReq => [0, rpc, end, dontAck, rfa],
ENDCASE => --receiving, endCall-- ERROR;
header.pktID.callSeq ← NewCallNumber[];
header.pktID.pktSeq ← 1;
acked ← FALSE;
}
ELSE {
header.type ← SELECT state FROM
sending => [0, rpc, notEnd, pleaseAck, data],
receiving => [0, rpc, end, dontAck, ack],
call =>  [0, rpc, end, dontAck, data],
endCall => [0, rpc, end, dontAck, data],
ENDCASE => --authReq-- ERROR;
IF state # receiving --header.type.class = data --
THEN { header.pktID.pktSeq ← header.pktID.pktSeq+1; acked←FALSE }
ELSE acked ← TRUE;
};
thisPktID ← header.pktID;
SetWanting[myPSB];
DO -- loop for pings --
ENABLE UNWIND => {
ClearWanting[myPSB];
ReturnIOCB[];
IF outPktFrame # NIL THEN PrincOpsUtils.Free[outPktFrame];
};
{
foo: CARDINAL ← 0;
transmissions: CARDINAL ← 0;
hops: CARDINALIF localNet THEN 0 ELSE PupDefs.GetHopsToNetwork[header.destHost.net];
retransmitPulses: BasicTime.Pulses ← minRetransmitPulses;
For localNet stuff OR "can't get there" we time out fairly quickly
IF hops IN [1..PupRouterDefs.maxHop] THEN
retransmitPulses ← minRetransmitPulses + pulsesPerHop * hops;
IF outPkt.convHandle # RPC.unencrypted
THEN header.length ← RPCInternal.EncryptPkt[outPkt, length]
ELSE header.length ← length + RPCPkt.pktLengthOverhead;
header.oddByte ← no;
DO -- loop for retransmissions --
{
IF NOT localNet OR firstDevice = EthernetOneFace.nullDeviceHandle
THEN GeneralSend[outPkt]
ELSE {
IF localHost AND NOT( EthernetOneFace.hearSelf AND transmitLocalPkts )
THEN LocalSend[outPkt];
IF NOT localHost OR transmitLocalPkts THEN {
IF iocb = NIL THEN GetIOCB[] ELSE WaitUntilSent[];
-- Pup checksum --
outPkt.data[header.length-RPCPkt.pktLengthOverhead] ← 177777B;
outPkt.encapsulation ← Encapsulation[ethernetOne[,,,,,,
header.destHost.host, myDeviceHost, pup]];
EthernetOneFace.QueueOutput[firstDevice,
@outPkt.encapsulation + DriverTypes.ethernetEncapsulationOffset,
header.length + (1+DriverTypes.ethernetEncapsulationBytes)/2,
ControlBlock[]]
};
};
sentTime ← BasicTime.GetClockPulses[];
sent ← sent+1;
wait for response: an ack or the reply or a timeout
DO -- loop for each incoming packet (including garbage) --
reply ← MyReceive[
myPSB, sentTime, (IF acked THEN pingPulses ELSE retransmitPulses)];
IF reply = NIL THEN
IF acked
THEN GOTO ping
ELSE { header.type.ack ← pleaseAck; GOTO retransmit };
recvdHeader ← LOOPHOLE[@reply.pupLength];
IF recvdHeader.type.class = rfa THEN {
[] ← RPCInternal.ReplyToRFA[
reply, header--encrypted--, thisPktID--clear--, inPkt.convHandle];
can't set "acked", because we must retransmit our data packet until we obtain the correct destPSB from some ack pkt
LOOP;
};
IF outPkt.convHandle # RPC.unencrypted
AND recvdHeader.conv = header.conv
AND recvdHeader.srceHost = header.destHost
THEN {
ok: BOOL;
[ok, newLen] ← RPCInternal.DecryptPkt[recvdHeader, outPkt.convHandle];
IF ~ok AND recvdHeader.type.class#ack THEN
ERROR RPC.CallFailed[runtimeProtocol
! UNWIND => GiveBackBuffer[reply] ];
}
ELSE newLen ← recvdHeader.length - RPCPkt.pktLengthOverhead;
IF recvdHeader.conv = header.conv
AND recvdHeader.srceHost = header.destHost
AND recvdHeader.pktID.activity = thisPktID.activity
THEN -- pkt is related to our call --
SELECT TRUE FROM
recvdHeader.pktID.callSeq = thisPktID.callSeq =>
pkt is in our call
SELECT TRUE FROM
a) pkt has next sequence number to ours
recvdHeader.pktID.pktSeq = 1+thisPktID.pktSeq => {
IF state = sending OR state = endCall THEN
he's not allowed to generate that pktSeq!
ERROR RPC.CallFailed[runtimeProtocol
! UNWIND => GiveBackBuffer[reply] ];
SELECT recvdHeader.type.class FROM
data => GOTO done;
ack => {
This can happen if state=call and callee sent next data pkt, but it was lost and now he is responding to our retransmission or ping. Soon, he will retransmit his data pkt.
acked ← TRUE;
GiveBackBuffer[reply];
};
ENDCASE => --call,rfa--
ERROR RPC.CallFailed[runtimeProtocol
! UNWIND => GiveBackBuffer[reply] ];
};
b) pkt has same sequence number as ours
recvdHeader.pktID.pktSeq = thisPktID.pktSeq => {
SELECT recvdHeader.type.class FROM
ack => {
acknowledgement of our packet
IF header.type.class = call THEN
header.destPSB ← recvdHeader.srcePSB;
acked ← TRUE;
IF state = sending OR state = endCall
THEN {GiveBackBuffer[reply]; reply←NIL; GOTO done}
ELSE -- state = call, authReq, or receiving --
Even if "pleaseAck", we don't need to ack it,
because other end should send data pkt soon --
GiveBackBuffer[reply];
};
data, call => -- retransmisson of his packet --
IF state = receiving
THEN IF recvdHeader.type.ack = pleaseAck
THEN {
GiveBackBuffer[reply]; reply ← NIL;
GOTO retransmit -- we're already sending an ack --
}
ELSE GiveBackBuffer[reply]
ELSE ERROR RPC.CallFailed[runtimeProtocol
! UNWIND => GiveBackBuffer[reply] ];
ENDCASE => --rfa --
ERROR RPC.CallFailed[runtimeProtocol
! UNWIND => GiveBackBuffer[reply] ];
};
c) pkt has earlier sequence number than ours
recvdHeader.pktID.pktSeq < thisPktID.pktSeq =>
GiveBackBuffer[reply]; -- no need to ack it --
d) pkt has some future sequence number
ENDCASE =>
ERROR RPC.CallFailed[runtimeProtocol ! UNWIND => GiveBackBuffer[reply] ];
recvdHeader.pktID.callSeq > thisPktID.callSeq AND state=endCall => {
IF recvdHeader.type.class # call
THEN ERROR RPC.CallFailed[runtimeProtocol ! UNWIND => GiveBackBuffer[reply] ];
acks our last packet, so we can handle the call
GOTO done
}
ENDCASE => {
wrong call: let someone else do it
recvdHeader.destPSB ← PrincOps.PsbNull;
EnqueueAgain[reply];
}
ELSE {
wrong conversation or activity: let someone else do it
recvdHeader.destPSB ← PrincOps.PsbNull;
EnqueueAgain[reply];
};
Incoming RFA packets don't reach here.
ENDLOOP--for each incoming packet--;
EXITS
retransmit => {
transmissions ← transmissions+1;
IF (transmissions = maxTransmissions AND signalTimeout) OR state = authReq
Don't retransmit RFA: caller will retransmit call pkt. Otherwise, if a spurious worker process occurred because of call pkt retransmission before response to RFA, then the spurious worker process sits needlessly retransmitting RFA's until it times out.
THEN { SIGNAL RPC.CallFailed[timeout]; transmissions ← 0 };
retransmitted ← retransmitted+1;
retransmitPulses ← retransmitPulses + minRetransmitPulses;
};
};
ENDLOOP-- for each transmission --;
EXITS
ping => {
header.type ← [0, rpc, end, pleaseAck, ack];
length ← 0; header.pktID ← thisPktID;
acked ← FALSE;
pingPulses ← MIN[maxPingPulses, pingPulses * 2];
};
};
only exit from loop is "GOTO done" or UNWIND
REPEAT done => {
This isn't covered by any UNWIND
ClearWanting[myPSB];
ReturnIOCB[];
IF outPktFrame # NIL THEN PrincOpsUtils.Free[outPktFrame];
IF reply = NIL
THEN { --restore clear pktID-- header.pktID ← thisPktID; RETURN [FALSE, newLen] }
ELSE {
IF recvdHeader.outcome = signal AND state = call
AND signalHandler # NIL
THEN [outPkt, length, outPktFrame] ←
RPCInternal.DoSignal[reply, newLen, signalHandler, inPkt.convHandle]
ELSE {
IF newLen > maxlength THEN
ERROR RPC.CallFailed[runtimeProtocol ! UNWIND => GiveBackBuffer[reply]];
PrincOpsUtils.LongCopy[
from: recvdHeader, to: @inPkt.header, nwords: recvdHeader.length];
GiveBackBuffer[reply];
RETURN [TRUE, newLen]
};
}
};
ENDLOOP-- for each ping--;
We get here only after coming back from a call of DoSignal
ENDLOOP-- for signal handlers --;
we can't get here!
};
GeneralSend: PROC [pkt: RPCLupine.RPCPkt] = {
b: BufferDefs.PupBuffer = PupDefs.GetFreePupBuffer[];
PrincOpsUtils.LongCopy[from: @(pkt.header), to: @(b.pupLength),
nwords: ConcreteHeader[@pkt.header].length];
PupDefs.PupRouterSendThis[b];
};
LocalSend: PROC [pkt: RPCLupine.RPCPkt] = {
handle talking to ourselves if the ethernet head can't
b: BufferDefs.PupBuffer = PupDefs.GetFreePupBuffer[];
PrincOpsUtils.LongCopy[
from: @(pkt.header), to: @(b.pupLength), nwords: ConcreteHeader[@pkt.header].length];
IF NOT AcceptPkt[b] THEN PupDefs.ReturnFreePupBuffer[b];
};
SetWanting: ENTRY PROC [myPSB: PrincOps.PsbIndex] = INLINE {
wanting[myPSB] ← TRUE;
};
ClearWanting: PROC [myPSB: PrincOps.PsbIndex] = INLINE {
spare: BufferDefs.PupBuffer;
InnerClear: ENTRY PROC = INLINE {
wanting[myPSB] ← FALSE;
IF (spare ← waiterPkts[myPSB]) # NIL THEN waiterPkts[myPSB] ← NIL;
};
InnerClear[];
IF spare # NIL THEN GiveBackBuffer[spare] --ignore it, outside monitor--;
};
MyReceive: ENTRY PROC [myPSB: PrincOps.PsbIndex, sentTime, waitTime: BasicTime.Pulses] RETURNS [recvd: BufferDefs.PupBuffer] = INLINE {
ENABLE UNWIND => NULL;
Returns NIL if no packet arrives within waitTime pulses after sentTime
DO
IF (recvd ← waiterPkts[myPSB]) = NIL
THEN IF BasicTime.GetClockPulses[] - sentTime < waitTime
THEN WAIT waiterCond
ELSE EXIT
ELSE { waiterPkts[myPSB] ← NIL; EXIT };
ENDLOOP;
};
IdleReceive: PUBLIC PROC [pkt: RPCLupine.RPCPkt, maxlength: CARDINAL] = {
b: BufferDefs.PupBuffer;
InnerIdler: ENTRY PROC = {
IF idlers >= idlersMax THEN {
servers←servers-1; RETURN WITH ERROR KillServer[] };
idlers ← idlers + 1;
DO WAIT idlerCond; IF idlerPkt # NIL THEN EXIT ENDLOOP;
IF idlers < idlersMin AND servers < serversMax THEN {
servers←servers+1;
Process.Detach[FORK Server[]];
};
b ← idlerPkt;
{
recvdHeader: LONG POINTER TO Header = LOOPHOLE[@b.pupLength];
idlerPkt ← LOOPHOLE[idlerPkt.next, BufferDefs.PupBuffer]; b.next ← NIL;
IF recvdHeader.length > maxlength
THEN ERROR RecvdPktTooLong[] --NULL??--
ELSE PrincOpsUtils.LongCopy[
from: @b.pupLength, to: @pkt.header, nwords: recvdHeader.length];
};
};
InnerIdler[];
GiveBackBuffer[b];--outside monitor--
};
QueuesScrambled: ERROR = CODE;
spyProc: PROC [BufferDefs.PupBuffer] ← NIL;
SetSpyProc: PUBLIC ENTRY SAFE PROC [p: PROC [BufferDefs.PupBuffer]] = CHECKED {
spyProc ← p;
};
EnqueueRecvd: ENTRY PROC [b: BufferDefs.PupBuffer, report: BOOL] RETURNS [BOOL] = {
Dispatch packet to appropriate RPC process, if any. Packet is known to be a Pup, and is addressed to our socket.
header: LONG POINTER TO Header = LOOPHOLE[@b.pupLength];
IF report AND spyProc # NIL THEN spyProc[b];
IF header.destHost = myHost AND header.type.subType = rpc
THEN {
destPSB: PrincOps.PsbIndex = header.destPSB;
recvd ← recvd+1;
IF destPSB NOT IN (PrincOps.PsbNull..LAST[PrincOps.PsbIndex]]
OR NOT wanting[destPSB]
THEN {
give to idle process to deal with
Pkts are dealt with LIFO by idlers, but it doesn't matter (much)
IF idlers = 0 THEN RETURN [FALSE]; -- too busy, drop the packet
b.next ← idlerPkt;
idlerPkt ← b;
idlers ← idlers-1;
NOTIFY idlerCond;
}
ELSE {
someone wants this packet: give them it
IF waiterPkts[destPSB] # NIL THEN RETURN [FALSE];
waiterPkts[destPSB] ← b; BROADCAST waiterCond;
};
RETURN [TRUE]
}
ELSE RETURN [FALSE];
};
GiveBackBuffer: PROC [b: BufferDefs.PupBuffer] =
NOTE: calls of this must be made outside our monitor, because RPCPrivate.ReturnBuffer acquires the EthernetDriver monitor, and the EthernetDriver may call EnqueueRecvd which acquires our monitor!
IF PrincOpsUtils.IsBound[LOOPHOLE[RPCPrivate.ReturnBuffer]]
THEN RPCPrivate.ReturnBuffer
ELSE PupDefs.ReturnFreePupBuffer;
AcceptPkt: PROC [b: BufferDefs.PupBuffer] RETURNS [BOOL] = {
RETURN [ EnqueueRecvd[b: b, report: TRUE] ];
};
EnqueueAgain: PUBLIC PROC [b: BufferDefs.PupBuffer] = {
IF NOT EnqueueRecvd[b: b, report: FALSE] THEN GiveBackBuffer[b];
};
Listener: PROC = {
Catch any packets that get as far as the Pup socket level
soc: PupDefs.PupSocket = PupDefs.PupSocketMake[
local: RPCPrivate.rpcSocket, remote:, ticks: PupDefs.veryLongWait];
DO
ENABLE ABORTED => EXIT;
b: BufferDefs.PupBuffer = soc.get[];
IF b = NIL THEN LOOP;
RRA: be prepared for a few glitchy NILs to get through
IF NOT AcceptPkt[b] THEN PupDefs.ReturnFreePupBuffer[b];
ENDLOOP;
PupDefs.PupSocketDestroy[soc];
};
listenerProcess: PROCESS;
Server: PROC = {
RPCInternal.ServerMain[ ! KillServer => CONTINUE ];
};
******** Initialization ********
Initialize: ENTRY PROC = {
PupDefs.PupPackageMake[];
DriverDefs.ChangeNumberOfInputBuffers[TRUE];
myAddr ← PupDefs.AnyLocalPupAddress[RPCPrivate.rpcSocket];
myNet ← myAddr.net;
myDeviceHost ← myAddr.host;
myHost ← [myNet, myAddr.host];
START RPCInternal.RPCBinding; -- exports "RPCInternal.exportTable" --
START RPCInternal.RPCSecurity; -- exports "RPCInternal.firstConversation" --
START RPCInternal.RPCPktStreams; -- initialize connection states --
Booting.RegisterProcs[c: Checkpoint, r: Rollback];
servers ← servers+1; Process.Detach[FORK Server[]];
listenerProcess ← FORK Listener[];
};
Checkpoint: Booting.CheckpointProc = TRUSTED {
RPCPrivate.GetRPCPackets[NIL];
};
Rollback: Booting.RollbackProc = TRUSTED {
InnerRollback: ENTRY PROC = TRUSTED {
RESTART RPCInternal.RPCPktStreams; -- forget connection counts --
RESTART RPCInternal.RPCSecurity; -- invalidate local conversations --
RESTART RPCInternal.RPCBinding; -- nothing? --
};
InnerRollback[];
RPCPrivate.GetRPCPackets[AcceptPkt];
};
Initialize[];
RPCPrivate.GetRPCPackets[AcceptPkt];
}.
Bob Hagmann November 1, 1984 7:45:11 am
maxTransmissions ← 20 == this was set up to 100 during the time when Luther was thrashing
Bob Hagmann February 11, 1985 4:37:25 pm PST
changes to: GiveBackBuffer
Polle Zellweger (PTZ) August 2, 1985 1:39:27 pm PDT
changes to: PktExchange -- use newLen (NAT) rather than newLength [0..254] so that full-sized encrypted packets for other conversations don't cause bounds faults (the padding and/or the key can add a few words)