SunRPC.mesa
Demers, September 20, 1987 11:59:44 am PDT
DIRECTORY
Arpa USING [Address, nullAddress],
ArpaUDP USING [nullPort, Port],
Basics USING [Card16FromH, Card32FromF, FFromCard32, FWORD, HFromCard16, HWORD, UnsafeBlock],
Rope USING [ROPE],
SunRPCAuth USING [Conversation]
;
SunRPC: CEDAR DEFINITIONS
IMPORTS Basics
~ {
Types
ROPE: TYPE ~ Rope.ROPE;
Address: TYPE ~ Arpa.Address;
nullAddress: Address ~ Arpa.nullAddress;
Port: TYPE ~ ArpaUDP.Port;
nullPort: Port ~ ArpaUDP.nullPort;
UnsafeBlock: TYPE ~ Basics.UnsafeBlock;
Handle: TYPE ~ REF Object;
Object: TYPE;
Server: TYPE ~ REF ServerObject;
ServerObject: TYPE;
Conversation: TYPE ~ SunRPCAuth.Conversation;
Client Handles
Create: PROC [remoteAddress: Address ← nullAddress, remotePort: Port ← nullPort]
RETURNS [h: Handle];
Create a client handle, from which RPC calls can be made.
GetRemote: PROC [h: Handle]
RETURNS [remoteAddress: Address, remotePort: Port];
Get the remote address associated with a client handle.
SetRemote: PROC [h: Handle, remoteAddress: Address ← nullAddress, remotePort: Port ← nullPort]
RETURNS [newH: Handle];
Set the remote address associated with a client handle.
Destroy: PROC [h: Handle];
Destroy a client handle.
Clients
StartCall: PROC [h: Handle, c: Conversation, pgm, version, proc: CARD];
Prepare to serialize the arguments.
On return, h is ready to put the arguments with PutXXX[h, ...].
SendCallAndReceiveReply: PROC [h: Handle, timeoutMsec: CARD, retries: CARD] RETURNS [remoteAddress: Address, remotePort: Port];
Send the arguments and wait for the reply.
On return, h is ready to get the results with GetXXX[h].
! Error[<any>]
ReceiveAnotherReply: PROC [h: Handle, timeoutMsec: CARD]
RETURNS [remoteAddress: Address, remotePort: Port];
Wait for another reply. Used for broadcast-based protocols.
On return, h is ready to get the results with GetXXX[h].
! Error[$timeout | $protocolError | $wrongRPCVersion | $wrongProg | $wrongProgVersion]
ReleaseReply: PROC [h: Handle];
Free some resources associated with the handle.
The next StartCall[h] or Destroy[h] does an implicit ReleaseReply[h] if you forgot it.
Server Registration
CreateServer: PROC [pgm, version: CARD, serverProc: ServerProc, port: Port ← nullPort, concurrency: CARDINAL ← 1, clientData: REFNIL] RETURNS [s: Server];
Register serverProc as server for this program / version.
The concurrency arg is the max number of concurrent calls that will be serviced.
GetServerPort: PROC [s: Server] RETURNS [port: Port];
Determine the port on which server is listening.
DestroyServer: PROC [s: Server];
Destroy a server, releasing resources.
Servers
ServerProc: TYPE ~ PROC [h: Handle, c: Conversation, proc: CARD, clientData: REF]
RETURNS [doReply: BOOL, replyTimeToLive: CARDINAL];
On entry, h is ready to get the arguments with GetXXX[h].
If doReply=FALSE, no reply message will be sent.
The value of replyTimeToLive is the number of seconds the reply message will be kept around by the SunRPC package for duplicate handling.
StartReply: PROC [h: Handle];
On return, h is ready to put the results with PutXXX[h, ...].
A ServerProc may raise Error[...] either before or after calling StartReply[...]; the ServerProc will be unwound and an appropriate reply will be sent to the client.
A ServerProc may raise Error[$abortWithoutReturn], causing no reply message to be sent.
Readers / Writers
OpenReader: PROC [block: REF TEXT] RETURNS [h: Handle];
CloseReader: PUBLIC PROC [h: Handle];
A reader handle allows deserializing data from a REF TEXT block.
OpenWriter: PROC [maxBytes: CARDINAL] RETURNS [h: Handle];
CloseWriter: PROC [h: Handle] RETURNS [output: REF TEXT];
A writer handle allows serializing data into a REF TEXT block.
Serializing / Deserializing
BytesRemaining: PROC [h: Handle] RETURNS [bytes: CARDINAL];
Return number of bytes remaining to be read by GetXXX[h].
GetByte: PROC [h: Handle] RETURNS [byte: BYTE];
SkipBytes: PROC [h: Handle, bytes: CARDINAL];
GetAlign: PROC [h: Handle];
GetH: PROC [h: Handle] RETURNS [hword: Basics.HWORD];
GetCard16: PROC [h: Handle] RETURNS [card16: CARD16] ~ INLINE {
RETURN [Basics.Card16FromH[GetH[h]]] };
GetInt16: PROC [h: Handle] RETURNS [int16: INT16] ~ INLINE {
RETURN [LOOPHOLE[Basics.Card16FromH[GetH[h]]]] };
GetF: PROC [h: Handle] RETURNS [fword: Basics.FWORD];
GetCard32: PROC [h: Handle] RETURNS [card32: CARD32] ~ INLINE {
RETURN [Basics.Card32FromF[GetF[h]]] };
GetInt32: PROC [h: Handle] RETURNS [int32: INT32] ~ INLINE {
RETURN [LOOPHOLE[Basics.Card32FromF[GetF[h]]]] };
UnsafeGetBlock: UNSAFE PROC [h: Handle, block: UnsafeBlock];
GetBlock: PROC [h: Handle, block: REF TEXT, startIndex: CARDINAL ← 0, count: CARDINALCARDINAL.LAST];
GetRefText: PROC [h: Handle] RETURNS [refText: REF TEXT];
GetEphemeralRefText: PROC [h: Handle, oldBuffer: REF TEXTNIL]
RETURNS [newBuffer: REF TEXT];
Reuse "oldBuffer" if it's long enough; otherwise allocate a new one with RefText.ObtainScratch.
GetRope: PROC [h: Handle] RETURNS [ROPE];
PutByte: PROC [h: Handle, byte: BYTE];
PutAlign: PROC [h: Handle, padValue: BYTE ← 0];
PutH: PROC [h: Handle, hword: Basics.HWORD];
PutCard16: PROC [h: Handle, card16: CARD16] ~ INLINE {
PutH[h, Basics.HFromCard16[card16]] };
PutInt16: PROC [h: Handle, int16: INT16] ~ INLINE {
PutH[h, Basics.HFromCard16[LOOPHOLE[int16]]] };
PutF: PROC [h: Handle, fword: Basics.FWORD];
PutCard32: PROC [h: Handle, card32: CARD32] ~ INLINE {
PutF[h, Basics.FFromCard32[card32]] };
PutInt32: PROC [h: Handle, int32: INT32] ~ INLINE {
PutF[h, Basics.FFromCard32[LOOPHOLE[int32]]] };
UnsafePutBlock: UNSAFE PROC [h: Handle, block: UnsafeBlock];
PutBlock: PROC [h: Handle, block: REF READONLY TEXT, startIndex: CARDINAL ← 0, count: CARDINAL ← CARDINAL.LAST];
PutRefText: PROC [h: Handle, refText: REF READONLY TEXT];
PutRope: PROC [h: Handle, rope: ROPE];
Errors
Error: ERROR [code: ATOM];
Codes:
$outOfBufferSpace -- for PutXXX
$outOfData -- for GetXXX
$notNetworkHandle -- inappropriate Destroy of reader or writer handle.
$notLocalHandle -- inappropriate CloseReader or CloseWriter of network handle.
$unreachable
$timeout
$wrongRPCVersion
$protocolError
$badCredentials -- I can't parse them.
$wrongCredentials -- I never heard of you.
$badVerifier -- I can't parse it.
$wrongVerifier -- The verifier doesn't agree with the credentials.
$badReplyVerifier -- I can't parse it.
$wrongReplyVerifier -- Not what I expected.
$weakCredentials -- I believe who you are, but you're not privileged to do this.
$wrongProgram -- Specified program not exported by this server.
$wrongProgramVersion -- Specified program available, but not in the specified version.
$wrongProc -- Specified program and version available, but doesn't have the specified proc.
}...