ComputeServerPupsImpl.mesa
The Compute Server side of the Summoner.
Last Edited by: Bob Hagmann, May 9, 1986 8:50:16 am PDT
Hal Murray, March 22, 1986 9:45:52 pm PST
Copyright © 1984 by Xerox Corporation. All rights reserved.
DIRECTORY
Basics,
Commander,
ComputeServerClient,
ComputeServer,
ComputeServerControl,
ComputeServerInternal,
InterpreterToolPrivate,
IO,
PrincOps,
Process,
PupName USING [MyName, MyRope],
Rope;
ComputeServerPupsImpl:
CEDAR
PROGRAM
IMPORTS IO, Process, PupName
EXPORTS ComputeServerControl, ComputeServerInternal
= BEGIN
Variable Declarations
STREAM: TYPE = IO.STREAM;
ROPE: TYPE = Rope.ROPE;
myHostName: PUBLIC ROPE ← PupName.MyName[];
MyNetAddressRope: PUBLIC ROPE ← PupName.MyRope[];
inStreamProcs:
PUBLIC
REF
IO.StreamProcs ←
IO.CreateStreamProcs[
variety: $input,
class: $ROPE,
getChar: inBufGetChar,
endOf: inBufEndOf,
charsAvail: inCharsAvail,
getIndex: inBufGetIndex,
close: inBufClose
];
outStreamProcs:
PUBLIC
REF
IO.StreamProcs ←
IO.CreateStreamProcs[
variety: $output,
class: $ROPE,
putChar: outBufPutChar,
getIndex: outBufGetIndex,
close: outBufClose
];
BufStreamData: TYPE = ComputeServerInternal.BufStreamData;
bufStreamState: TYPE = ComputeServerInternal.bufStreamState;
BufStreamDataObject: TYPE = ComputeServerInternal.BufStreamDataObject;
Internal Streams
input procedures
inBufGetChar:
PUBLIC
PROC [self:
STREAM]
RETURNS [ch:
CHAR] = {
data: BufStreamData = NARROW[self.streamData];
DO
IF data.EOF = true THEN ERROR IO.EndOfStream[self];
IF data.
EOF = pending
AND data.inPointer = data.outPointer
THEN {
data.EOF ← true;
ERROR IO.EndOfStream[self];
};
IF data.inPointer # data.outPointer
THEN {
ch ← data.buffer[data.inPointer MOD ComputeServerInternal.BufStreamBufferSize];
data.inPointer ← data.inPointer + 1;
RETURN;
}
ELSE
IF data.listenerItem.success = communicationFailure
THEN {
Process.CheckForAbort[];
ERROR IO.Error[ec: Failure, stream: self];
};
Process.Pause[5];
ENDLOOP;
};
inBufEndOf:
PROC [self:
STREAM]
RETURNS [
BOOL] = {
data: BufStreamData = NARROW[self.streamData];
WHILE data.
EOF = false
AND data.inPointer = data.outPointer
DO
Process.Pause[5];
ENDLOOP;
IF data.EOF = true OR data.inPointer = data.outPointer THEN RETURN[TRUE] ELSE RETURN[FALSE];
};
inCharsAvail:
PUBLIC
PROC [self:
STREAM, wait:
BOOL]
RETURNS [
INT] = {
data: BufStreamData = NARROW[self.streamData];
RETURN[(IF data.EOF # false THEN 1 ELSE 0) + data.outPointer - data.inPointer];
};
inBufGetIndex:
PROC [self:
STREAM]
RETURNS [
INT] = {
data: BufStreamData = NARROW[self.streamData];
RETURN[data.inPointer];
};
inBufClose:
PROC [self:
STREAM, abort:
BOOL] = {
data: BufStreamData = NARROW[self.streamData];
data.EOF ← true;
};
output procedures
outBufPutChar:
PUBLIC
PROC [self:
STREAM, char:
CHAR] = {
data: BufStreamData = NARROW[self.streamData];
WHILE (data.inPointer - (data.outPointer + 1))
MOD ComputeServerInternal.BufStreamBufferSize = 0
DO
IF data.listenerItem.success = communicationFailure THEN RETURN; -- ignore output once communications fails
Process.Pause[5];
ENDLOOP;
data.buffer[data.outPointer MOD ComputeServerInternal.BufStreamBufferSize] ← char;
data.outPointer ← data.outPointer + 1;
};
outBufGetIndex:
PROC [self:
STREAM]
RETURNS [
INT] = {
data: BufStreamData = NARROW[self.streamData];
RETURN[data.outPointer];
};
outBufClose:
PROC [self:
STREAM, abort:
BOOL] = {
data: BufStreamData = NARROW[self.streamData];
IF data.EOF = false THEN data.EOF ← pending;
};
END.
Bob Hagmann May 3, 1985 8:41:54 am PDT
changes to: DIRECTORY, ComputeServerPupsImpl, inBufGetChar