RPCBcstListenImpl.mesa; Clean up and enqueue incoming broadcast RPC packets (!!)
Based on an original idea by A. Birrell;
adapted for Thrush By D. Swinehart September 15, 1985 12:55:08 pm PDT
DIRECTORY
PupDefs USING[GetLocalPupAddress, PupBuffer, PupSocket, PupSocketDestroy, PupSocketMake, veryLongWait],
PupTypes USING[ PupHostID, PupSocketID ],
RPCBcstListen,
RPCPkt   USING [ EnqueueAgain, Header ],
RPCPrivate USING[ rpcSocket ]
;
RPCBcstListenImpl: CEDAR PROGRAM
IMPORTS PupDefs, RPCPkt
EXPORTS RPCBcstListen = {
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;
RPCPkt.EnqueueAgain[b];
ENDLOOP;
PupDefs.PupSocketDestroy[soc];
};
bcstListenerProcess: PROCESS;
BcstListenInitialize: PUBLIC PROC = { bcstListenerProcess ← FORK BcstListener[]; };
Unless there's a problem, just start self.
BcstListenInitialize[];
}.