Copied Types and Constants
BytePtr: TYPE ~ LONG POINTER TO BYTE;
FWORD: TYPE ~ Basics.FWORD;
HWORD: TYPE ~ Basics.HWORD;
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Ticks: TYPE ~ Process.Ticks;
Handle: TYPE ~ CrRPC.Handle;
Clearinghouse Client Calls
Here's the stuff to do GetAddresses for a clearinghouse ...
CreateRefXNSAddress:
UNSAFE
PROC [from:
LONG
POINTER
TO
XNS.Address]
RETURNS [copy:
REF
XNS.Address] ~
TRUSTED {
copy ¬ NEW[XNS.Address ¬ (from)];
};
GetCMUXHandleClass:
PROC
RETURNS [class:
ATOM] ~ { class ¬ $CMUX };
PutMySimpleCredentialsAndVerifier:
PROC [h: Handle, s:
STREAM] ~ {
Credentials
Simple type
CrRPC.PutCard16[s, 0];
Length, in words
CrRPC.PutCard16[s, 11];
Three-part name ...
CrRPC.PutRope[s, "Xerox"];
CrRPC.PutRope[s, "PARC"];
CrRPC.PutRope[s, "Demers"];
Verifier
Length, in words
CrRPC.PutCard16[s, 1];
Hashed password
CrRPC.PutCard16[s, 0d0e9H];
};
GetAndDumpContentsOfStream:
PROC [h: Handle, s:
STREAM] ~ {
WHILE
NOT
IO.EndOf[s]
DO
x: CARD16 ¬ CrRPC.GetCard16[s];
DebugMsg[IO.PutFR1["%x\n", IO.card[x]]];
ENDLOOP;
};
PutListAddressesArgs: CrRPC.PutArgsProc ~ {
msg: ROPE ¬ "PutListAddressesArgs was called\n";
DebugMsg[msg];
};
GetListAddressesResults: CrRPC.GetResultsProc
-- [h, s] -- ~ {
msg: ROPE ¬ "GetListAddressesResults was called\n";
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetListAddressesResults\n"];
};
GetListAddressesError: CrRPC.GetErrorProc
-- [h, s, errNum] -- ~ {
msg: ROPE ¬ IO.PutFR1["GetListAddressesError errnum %g\n", IO.card[errNum]];
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetListAddressesError\n"];
};
CallListAddresses:
PROC [h: Handle] ~ {
CrRPC.Call[h, 2, 3, 0, PutListAddressesArgs, GetListAddressesResults, GetListAddressesError];
};
PutListDomainsServedArgs: CrRPC.PutArgsProc ~ {
msg: ROPE ¬ "PutListDomainsServerArgs was called\n";
DebugMsg[msg];
Immediate Bulk Data
CrRPC.PutBulkDataSink[h, s, XferListDomainsServedBulkData];
PutMySimpleCredentialsAndVerifier[h, s];
msg ¬ "PutListDomainsServerArgs done\n";
DebugMsg[msg];
};
XferOneDomain:
PROC[s:
STREAM] ~ {
DebugMsg["Domain : "];
DebugMsg[CrRPC.GetRope[s]];
DebugMsg[":"];
DebugMsg[CrRPC.GetRope[s]];
DebugMsg["\n"];
};
XferDomainSeq:
PROC[s:
STREAM] ~ {
seqLen: CARD16;
DebugMsg["XferDomainSeq called\n"];
seqLen ¬ CrRPC.GetCard16[s];
WHILE seqLen > 0
DO
XferOneDomain[s];
seqLen ¬ seqLen - 1;
ENDLOOP;
};
XferListDomainsServedBulkData: CrRPC.BulkDataXferProc
-- [h, s, checkAbort] -- ~ {
DebugMsg["XferListDomainsServedBulkData called\n"];
IF checkAbort[h] THEN RETURN [FALSE];
DO
tag: CARD16 ¬ CrRPC.GetCard16[s];
SELECT tag
FROM
0 => {
XferDomainSeq[s];
IF checkAbort[h] THEN RETURN [FALSE];
};
1 => {
XferDomainSeq[s];
IF checkAbort[h] THEN RETURN [FALSE];
IF NOT IO.EndOf[s] THEN DebugMsg[IO.PutFR1["bulk data ends before endOfStream, charsAvail %g\n", IO.int[IO.CharsAvail[s, FALSE]]]]; -- DEBUG
RETURN [FALSE];
};
ENDCASE => {
DebugMsg[IO.PutFR1["error: bulk data tag %g\n", IO.card[tag]]];
RETURN [TRUE];
};
ENDLOOP;
};
GetListDomainsServedResults: CrRPC.GetResultsProc
-- [h, s] -- ~ {
msg: ROPE ¬ "GetListDomainsServedResults was called\n";
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetListDomainsServedResults\n"];
};
GetListDomainsServedError: CrRPC.GetErrorProc
-- [h, s, errNum] -- ~ {
msg: ROPE ¬ IO.PutFR1["GetListDomainsServedError errnum %g\n", IO.card[errNum]];
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetListDomainsServedError\n"];
};
CallListDomainsServed:
PROC [h: Handle] ~ {
CrRPC.Call[h, 2, 3, 1, PutListDomainsServedArgs, GetListDomainsServedResults, GetListDomainsServedError];
};
PutCheckSimpleCredentialsArgs: CrRPC.PutArgsProc ~ {
msg: ROPE ¬ "PutCheckSimpleCredentialsArgs was called\n";
DebugMsg[msg];
PutMySimpleCredentialsAndVerifier[h, s];
};
GetCheckSimpleCredentialsResults: CrRPC.GetResultsProc
-- [h, s] -- ~ {
msg: ROPE ¬ "GetCheckSimpleCredentialsResults was called\n";
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetCheckSimpleCredentialsResults\n"];
};
GetCheckSimpleCredentialsError: CrRPC.GetErrorProc
-- [h, s, errNum] -- ~ {
msg: ROPE ¬ IO.PutFR1["GetCheckSimpleCredentialsError errnum %g\n", IO.card[errNum]];
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetCheckSimpleCredentialsError\n"];
};
CallCheckSimpleCredentials:
PROC [h: Handle] ~ {
CrRPC.Call[h, 14, 2, 2, PutCheckSimpleCredentialsArgs, GetCheckSimpleCredentialsResults, GetCheckSimpleCredentialsError];
};
Sample Courier Client/Server Pair
This is a client-server pair for a simple protocol:
OutOfRange: ERROR [] = 0;
Negate: PROC [x: INT] RETURNS [minusX: INT] RAISES OutOfRange = 0;
SendToServer: PROC [source: BulkDataSource, abortAfter: INT] RETURNS [nBytesRecvd: CARD32, hash: CARD32] = 1;
GetFromServer: PROC [nBytesWanted: CARD32, sink: BulkDataSink, abortAfter: INT] RETURNS [hash: CARD32] = 2;
samplePgm: CARD32 ¬ 1776;
samplePgmVersion: CARD16 ¬ 0;
sampleNegateProcNum: CARD16 ¬ 0;
sampleSendToServerProcNum: CARD16 ¬ 1;
sampleGetFromServerProcNum: CARD16 ¬ 2;
sampleOutOfRangeErrNum: CARD16 ¬ 0;
CallNegate:
PROC [h: Handle, x:
INT] ~ {
PutNegateArgs: CrRPC.PutArgsProc
-- [h, s] -- ~ {
msg: ROPE ¬ IO.PutFR1["PutNegateArgs %g was called\n", IO.int[x] ];
DebugMsg[msg];
CrRPC.PutInt32[s, x];
};
GetNegateResults: CrRPC.GetResultsProc
-- [h, s] -- ~ {
ans: INT32;
msg: ROPE;
DebugMsg["GetNegateResults called ... "];
ans ¬ CrRPC.GetInt32[s];
msg ¬ IO.PutFR1["recvd %g\n", IO.int[ans] ];
DebugMsg[msg];
};
GetNegateError: CrRPC.GetErrorProc
-- [h, s, errNum] -- ~ {
msg: ROPE ¬ IO.PutFR1["GetNegateError errnum %g\n", IO.card[errNum]];
DebugMsg[msg];
GetAndDumpContentsOfStream[h, s];
DebugMsg["done with GetNegateError\n"];
};
CrRPC.Call[h, samplePgm, samplePgmVersion, sampleNegateProcNum, PutNegateArgs, GetNegateResults, GetNegateError];
};
ServeNegate:
PROC [h: Handle, s:
STREAM, beginReturn: CrRPC.BeginReturnProc, beginError: CrRPC.BeginErrorProc] ~ {
x: INT;
msg: ROPE;
DebugMsg["ServeNegate ["];
x ¬ CrRPC.GetInt32[s];
msg ¬ IO.PutFR1["%g] ", IO.int[x] ];
DebugMsg[msg];
IF x =
INT.
FIRST
THEN {
DebugMsg["raises OutOfRange\n"];
beginError[h, sampleOutOfRangeErrNum];
RETURN;
};
msg ¬ IO.PutFR1["returns %g\n", IO.int[-x] ];
beginReturn[h];
DebugMsg[msg];
CrRPC.PutInt32[s, -x];
};
ServeSample: CrRPC.ServerProc
-- [h, s, pgm, pgmVersion, proc, beginReturn, beginError, beginReject] -- ~ {
msg: ROPE;
SELECT proc
FROM
sampleNegateProcNum => {
ServeNegate[h, s, beginReturn, beginError];
};
ENDCASE => {
msg ¬ IO.PutFR1["ServeSample proc %g rejected\n", IO.card[proc]];
DebugMsg[msg];
beginReject[h, CrRPC.noSuchProcedure];
};
};
pleaseStopSample: BOOL ¬ FALSE;
SetPleaseStopSample:
PROC [new:
INT]
RETURNS [old:
INT] ~ {
old ¬ IF pleaseStopSample THEN 1 ELSE 0;
pleaseStopSample ¬ (new # 0);
};
StopSampleQueryProc: CrRPC.StopServerQueryProc
-- [h] RETURNS [BOOL] -- ~ {
RETURN [pleaseStopSample];
};
AtomFromUnixString:
PROC [s: CStrings.CString]
RETURNS [
ATOM] ~ {
RETURN[ Atom.MakeAtom[UXStrings.ToRope[s, 40]] ];
};
}.