SunPMapServerStub.mesa
Demers, October 8, 1987 5:40:09 pm PDT
DIRECTORY
ArpaUDP USING [Address],
Basics USING [HFromCard16],
SunPMap USING [callit, dump, getPort, ipProtocolUDP, MapEntry, null, program, programVersion, set, udpPort, unset],
SunPMapServer USING [Callit, Dump, GetPort, Null, Set, Unset],
SunRPC USING [CreateServer, Error, GetCard32, GetRefText, Handle, PutCard32, PutRefText, Server, ServerProc, StartReply],
SunRPCAuth USING [Conversation]
;
SunPMapServerStub: CEDAR PROGRAM
IMPORTS Basics, SunRPC, SunPMapServer
~ {
Types
Address: TYPE ~ ArpaUDP.Address;
Handle: TYPE ~ SunRPC.Handle;
Conversation: TYPE ~ SunRPCAuth.Conversation;
MapEntry: TYPE ~ SunPMap.MapEntry;
Parameters
fastTimeout: CARD ← 200;
mediumTimeout: CARD ← 500;
defaultReplyTTL: CARDINAL ← 2;
defaultRetries: CARD ← 2;
noRetries: CARD ← 0;
Procedures
Serve: SunRPC.ServerProc -- [h: Handle, c: Conservation, proc: CARD, clientData: REF] RETURNS [doReply: BOOL, replyTimeToLive: CARDINAL] -- ~ {
doReply ← TRUE;
replyTimeToLive ← defaultReplyTTL;
SELECT proc FROM
SunPMap.null => ServeNull[h, c];
SunPMap.set => ServeSet[h, c];
SunPMap.unset => ServeUnset[h, c];
SunPMap.getPort => ServeGetPort[h, c];
SunPMap.dump => ServeDump[h, c];
SunPMap.callit => ServeCallit[h, c];
ENDCASE => ERROR SunRPC.Error[$wrongProc];
};
ServeNull: PROC [h: Handle, c: Conversation] ~ {
SunRPC.StartReply[h];
SunPMapServer.Null[h, c];
};
ServeSet: PROC [h: Handle, c: Conversation] ~ {
program, version, protocol, port: CARD32;
success: BOOL;
program ← SunRPC.GetCard32[h];
version ← SunRPC.GetCard32[h];
protocol ← SunRPC.GetCard32[h];
port ← SunRPC.GetCard32[h];
SunRPC.StartReply[h];
success ← SunPMapServer.Set[h, c, program, version, protocol, port];
SunRPC.PutCard32[h, IF success THEN 1 ELSE 0];
};
ServeUnset: PROC [h: Handle, c: Conversation]
~ {
program, version: CARD32;
success: BOOL;
program ← SunRPC.GetCard32[h];
version ← SunRPC.GetCard32[h];
SunRPC.StartReply[h];
success ← SunPMapServer.Unset[h, c, program, version];
SunRPC.PutCard32[h, IF success THEN 1 ELSE 0];
};
ServeGetPort: PROC [h: Handle, c: Conversation] ~ {
program, version, protocol: CARD32;
port: CARD32;
program ← SunRPC.GetCard32[h];
version ← SunRPC.GetCard32[h];
protocol ← SunRPC.GetCard32[h];
SunRPC.StartReply[h];
port ← SunPMapServer.GetPort[h, c, program, version, protocol];
SunRPC.PutCard32[h, port];
};
ServeDump: PROC [h: Handle, c: Conversation] ~ {
EachMapEntry: PROC [mapEntry: MapEntry] ~ {
SunRPC.PutCard32[h, 1];
SunRPC.PutCard32[h, mapEntry.program];
SunRPC.PutCard32[h, mapEntry.version];
SunRPC.PutCard32[h, mapEntry.protocol];
SunRPC.PutCard32[h, mapEntry.port];
};
SunRPC.StartReply[h];
SunPMapServer.Dump[h, c, EachMapEntry];
SunRPC.PutCard32[h, 0];
};
ServeCallit: PUBLIC PROC [h: Handle, c: Conversation] ~ {
program, version, proc: CARD32;
args: REF TEXT;
port: CARD32;
result: REF TEXT;
program ← SunRPC.GetCard32[h];
version ← SunRPC.GetCard32[h];
proc← SunRPC.GetCard32[h];
args ← SunRPC.GetRefText[h];
SunRPC.StartReply[h];
[port, result] ← SunPMapServer.Callit[h, c, program, version, proc, args];
SunRPC.PutCard32[h, port];
SunRPC.PutRefText[h, result];
};
theServer: SunRPC.Server;
Init: PROC ~ {
theServer ← SunRPC.CreateServer[SunPMap.program, SunPMap.programVersion, Serve, Basics.HFromCard16[SunPMap.udpPort], 3, NIL];
[] ← SunPMapServer.Set[NIL, NIL, SunPMap.program, SunPMap.programVersion, SunPMap.ipProtocolUDP, SunPMap.udpPort];
};
Init[];
}...