XNSStreamExtras.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Demers, March 4, 1987 1:16:14 pm PST
DIRECTORY
IO USING [STREAM],
XNS USING [Address, Socket, unknownSocket],
XNSStream USING [Listener, Milliseconds, waitForever];
XNSStreamExtras: CEDAR DEFINITIONS ~ {
Listening
XFilterProc: TYPE = PROC [remote: XNS.Address, clientData: REF]
RETURNS [accept: BOOL];
XListenerProc: TYPE = PROC [stream: IO.STREAM, remote: XNS.Address, clientData: REF];
CreateXListener: PROC [
socket: XNS.Socket ← XNS.unknownSocket,
worker: XListenerProc,
getTimeout, putTimeout: XNSStream.Milliseconds ← XNSStream.waitForever,
clientData: REFNIL,
filter: XFilterProc ← NIL, -- NIL => Accept all requests
echoFilter: XFilterProc ← NIL] -- NIL => Answer all echos
RETURNS [XNSStream.Listener];
An active Listener will respond to a connection request by:
1) Checking for duplicates.
2) Calling the client's filter. Returning FALSE will reject the connection.
3) Creating a stream with the specified timeouts.
4) FORKing a new instance of worker to interact with the new stream.
5) Detaching the new process.
If filter returns TRUE, a worker will always be FORKed. (All error conditions have already been checked.) worker must catch ConnectionClosed and Timeout (unless waitForever was specified) and it should Close the stream before returning.
echoFilter is handy when several instances of a server run on different machines. Grapevine, for example, flings an echo packet at all the interesting servers, and then tries to open a connection to the first one that answers. echoFilter can be used to answer "no" if filter is very likley to reject a connection attempt. (There is no promise that filter or worker will be called if echoFilter doesn't reject a packet.)
GetLocalFromListener: PROC [listener: XNSStream.Listener] RETURNS [local: XNS.Address];
}.