Register:
PUBLIC
PROC [
protocolFamily:
ATOM,
transportClass:
ATOM,
proc: NetworkStream.RegistrationCallbackProc ]
~ {
prev: LIST OF NetworkStream.Registration;
each: LIST OF NetworkStream.Registration;
rNew: NetworkStream.Registration;
LookupForRegister:
ENTRY
PROC ~ {
ENABLE UNWIND => NULL;
prev ¬ NIL; each ¬ registrations;
DO
IF each = NIL THEN EXIT;
IF (each.first.protocolFamily = protocolFamily)
AND (each.first.transportClass = transportClass) THEN EXIT;
prev ¬ each; each ¬ each.rest;
ENDLOOP;
};
IF protocolFamily = NIL THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $protocolFamily], "missing protocol family"];
IF transportClass = NIL THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $transportClass], "missing transport class"];
LookupForRegister[];
SELECT
TRUE
FROM
(each =
NIL ) => {
rNew ¬ proc[NIL];
IF rNew #
NIL
THEN registrations ¬ CONS[
CompleteRegistration[protocolFamily, transportClass, rNew],
registrations];
};
(each.first.protocolFamily = protocolFamily)
AND (each.first.transportClass = transportClass) => {
rNew ¬ proc[NIL];
SELECT
TRUE
FROM
rNew = each.first => NULL;
rNew # NIL => each.first ¬
CompleteRegistration[protocolFamily, transportClass, rNew];
prev = NIL => registrations ¬ each.rest;
ENDCASE => prev.rest ¬ each.rest;
};
ENDCASE => ERROR;
};
CompleteRegistration:
PROC [family:
ATOM, class:
ATOM, r: NetworkStream.Registration]
RETURNS [NetworkStream.Registration]
~ {
insp: NetworkStream.NetworkStreamProcs ¬ r.inNetworkStreamProcs;
onsp: NetworkStream.NetworkStreamProcs ¬ r.outNetworkStreamProcs;
lp: NetworkStream.ListenerProcs ¬ r.listenerProcs;
IF r.protocolFamily # family THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $protocolFamily], "bad protocol family"];
IF r.transportClass # class THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $transportClass], "bad transport class"];
IF (r.inStreamProcs = NIL) OR (insp = NIL) THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $inputProcs], "bad input procs"];
IF (r.outStreamProcs = NIL) OR (onsp = NIL) THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $outputProcs], "bad output procs"];
IF (r.createListener # NIL) AND (lp = NIL) THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $listenerProcs], "bad listener procs"];
IF (r.createStreams = NIL) AND (r.createListener = NIL) THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $create], "no create proc for streams or listener"];
IF r.createStreams = NIL THEN r.createStreams ¬ DefaultRegisteredCreateStreamsProc;
IF insp.getStreamInfo = NIL THEN insp.getStreamInfo ¬ DefaultGetStreamInfoProc;
IF insp.getTimeout = NIL THEN insp.getTimeout ¬ DefaultGetTimeoutProc;
IF insp.setTimeout = NIL THEN insp.setTimeout ¬ DefaultSetTimeoutProc;
IF insp.sendSoon = NIL THEN insp.sendSoon ¬ InputSendSoonProc;
IF insp.getIndexDetails = NIL THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $getIndexDetails], "no input GetIndexDetails proc"];
IF insp.getStreamState = NIL THEN insp.getStreamState ¬ DefaultGetStreamStateProc;
IF insp.setSubStreamType = NIL THEN insp.setSubStreamType ¬ InputSetSubStreamTypeProc;
IF insp.sendEndOfMessage = NIL THEN insp.sendEndOfMessage ¬ InputSendEndOfMessageProc;
IF insp.waitAttention = NIL THEN insp.waitAttention ¬ DefaultWaitAttentionProc;
IF insp.sendAttention = NIL THEN insp.sendAttention ¬ InputSendAttentionProc;
IF insp.waitAck = NIL THEN insp.waitAck ¬ InputWaitAckProc;
IF insp.finalizeStream = NIL THEN insp.finalizeStream ¬ DefaultFinalizeStreamProc;
IF onsp.getStreamInfo = NIL THEN onsp.getStreamInfo ¬ DefaultGetStreamInfoProc;
IF onsp.getTimeout = NIL THEN onsp.getTimeout ¬ DefaultGetTimeoutProc;
IF onsp.setTimeout = NIL THEN onsp.setTimeout ¬ DefaultSetTimeoutProc;
IF onsp.sendSoon = NIL THEN onsp.sendSoon ¬ DefaultSendSoonProc;
IF onsp.getIndexDetails = NIL THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $getIndexDetails], "no output GetIndexDetails proc"];
IF onsp.getStreamState = NIL THEN onsp.getStreamState ¬ OutputGetStreamStateProc;
IF onsp.setSubStreamType = NIL THEN onsp.setSubStreamType ¬ DefaultSetSubStreamTypeProc;
IF onsp.sendEndOfMessage = NIL THEN onsp.sendEndOfMessage ¬ DefaultSendEndOfMessageProc;
IF onsp.waitAttention = NIL THEN onsp.waitAttention ¬ OutputWaitAttentionProc;
IF onsp.sendAttention = NIL THEN onsp.sendAttention ¬ DefaultSendAttentionProc;
IF onsp.waitAck = NIL THEN onsp.waitAck ¬ DefaultWaitAckProc;
IF onsp.finalizeStream = NIL THEN onsp.finalizeStream ¬ DefaultFinalizeStreamProc;
IF r.createListener = NIL THEN r.createListener ¬ DefaultRegisteredCreateListenerProc;
IF lp #
NIL
THEN {
IF lp.getListenerInfo = NIL THEN lp.getListenerInfo ¬ DefaultGetListenerInfoProc;
IF lp.destroyListener = NIL THEN RaiseIOError[Failure, NIL, LIST[$networkStreamError, $Register, $destroyListener], "bad destroyListener proc"];
IF lp.finalizeListener = NIL THEN lp.finalizeListener ¬ DefaultFinalizeListenerProc;
};
RETURN [r];
};