RPCBcstListenImpl.mesa; Clean up and enqueue incoming broadcast RPC packets (!!)
Based on an original idea by A. Birrell;
adapted for Thrush By D. Swinehart March 23, 1983 5:19 pm
DIRECTORY
PupDefs USING[GetLocalPupAddress, PupBuffer, PupSocket, PupSocketDestroy, PupSocketMake, ReturnFreePupBuffer, veryLongWait],
PupTypes USING[ PupHostID, PupSocketID ],
RPCBcstListen,
RPCPkt   USING [ Header ],
RPCPktIO  USING [ EnqueueRecvd ],
RPCPrivate USING[ rpcSocket ]
;
RPCBcstListenImpl: CEDAR PROGRAM
IMPORTS PupDefs, RPCPktIO
EXPORTS RPCBcstListen--BcstListenInitialize--
SHARES RPCPktIO = {
bcstRpcSocket: PupTypes.PupSocketID = [0, 45B];
BcstListener: PROC = TRUSTED {
A machine running BcstListener has agreed to accept RPC Call packets that are broadcast
to this network. The assumption is that not very many machines will need to provide
broadcast services. Convert the Pup to appear to be addressed to us, and dispatch it to
the RPC system.
myDeviceHost: PupTypes.PupHostID ←
PupDefs.GetLocalPupAddress[bcstRpcSocket, [[0],[0],[0,0]]].host;
soc: PupDefs.PupSocket = PupDefs.PupSocketMake[local: bcstRpcSocket, remote: [[0],[0],[0,0]],
ticks: PupDefs.veryLongWait];
DO ENABLE ABORTED => EXIT;
b: PupDefs.PupBuffer = soc.get[];
header: LONG POINTER TO RPCPkt.Header = LOOPHOLE[@b.pupLength];
header.destHost.host ← myDeviceHost;
header.destSoc ← RPCPrivate.rpcSocket;
IF NOT RPCPktIO.EnqueueRecvd[b, TRUE] THEN PupDefs.ReturnFreePupBuffer[b]; ENDLOOP;
PupDefs.PupSocketDestroy[soc];
};
bcstListenerProcess: PROCESS;
BcstListenInitialize: PUBLIC PROC = { bcstListenerProcess ← FORK BcstListener[]; };
Unless there's a problem, just start self.
BcstListenInitialize[];
}.