DIRECTORY BufferDefs USING [OisBuffer], CommunicationInternal USING [], CommFlags USING [doStats], Echo USING [echoRequest, echoResponse], OISCP USING [ReturnFreeOisBuffer, unknownNetID], OISCPConstants USING [echoerSocket], Router USING [FindMyHostID], Socket USING [Abort, ChannelAborted, Create, Delete, GetPacket, PutPacket, SetWaitTime, TimeOut, TransferStatus, WaitTime], SocketInternal USING [SocketObject], NSAddress USING [NetworkAddress], StatsDefs USING [StatIncr, StatBump]; EchoServerImpl: PROGRAM IMPORTS OISCP, Router, Socket, StatsDefs EXPORTS CommunicationInternal, Echo, Socket SHARES BufferDefs = BEGIN NetworkAddress: PUBLIC TYPE = NSAddress.NetworkAddress; ChannelHandle: TYPE = REF ChannelObject; ChannelObject: PUBLIC TYPE = SocketInternal.SocketObject; nBuffers: CARDINAL = 2; cH: ChannelHandle; localAddr: NetworkAddress; echoServerFork: PROCESS; echoerTimeout: Socket.WaitTime = 7777777777B; -- in msec (about 10 days) CreateServer: PUBLIC PROCEDURE = BEGIN localAddr _ [net: OISCP.unknownNetID, host: Router.FindMyHostID[], socket: OISCPConstants.echoerSocket]; cH _ Socket.Create[localAddr, 0, nBuffers, 0, FALSE]; echoServerFork _ FORK EchoServer[]; END; -- CreateServer DeleteServer: PUBLIC PROCEDURE = BEGIN Socket.Abort[cH]; JOIN echoServerFork; Socket.Delete[cH]; END; EchoServer: PROCEDURE = BEGIN buf: BufferDefs.OisBuffer; Socket.SetWaitTime[cH, echoerTimeout]; DO buf _ NIL; buf _ Socket.GetPacket[ cH ! Socket.TimeOut => RETRY; Socket.ChannelAborted => EXIT]; SELECT LOOPHOLE[buf.status, Socket.TransferStatus] FROM goodCompletion => BEGIN IF buf.ois.transCntlAndPktTp.packetType = echo THEN BEGIN firstWord: LONG POINTER TO WORD _ @buf.ois.oisWords[0]; IF firstWord^ = Echo.echoRequest THEN BEGIN buf.ois.destination _ buf.ois.source; firstWord^ _ Echo.echoResponse; IF CommFlags.doStats THEN StatsDefs.StatIncr[packetsEchoed]; IF CommFlags.doStats THEN StatsDefs.StatBump[bytesEchoed, buf.ois.pktLength]; Socket.PutPacket[cH, buf ! Socket.ChannelAborted => BEGIN OISCP.ReturnFreeOisBuffer[buf]; EXIT; END]; LOOP; END ELSE IF CommFlags.doStats THEN StatsDefs.StatIncr[packetsBadEchoed] END ELSE IF CommFlags.doStats THEN StatsDefs.StatIncr[packetsBadEchoed]; END; -- end goodCompletion aborted => EXIT; ENDCASE => NULL; OISCP.ReturnFreeOisBuffer[buf]; ENDLOOP; Socket.Abort[cH]; END; -- EchoServer END. πEchoServerImpl.mesa - implementation module for the Pilot OISCP Echo Server Copyright c 1985 by Xerox Corporation. All rights reserved. Garlick on: January 23, 1981 5:43 PM EXPORTED TYPE(s) global constants to all global variables to all Cold Procedures This procedure creates an echo server. no send or reserve buffers, 2 receive buffers, FALSE -> share buffers from system pool. This procedure deletes the echo server. DeleteListener Hot Procedures This procedure echos Echo protocol packets back to the remote end. init the PhysicalRecords and start the gets wait for an echo request packet b.status can be one of aborted or goodCompletion examine this packet good packet, echo it we got here via an abort or error; now clean up this world. Κ©˜codešœK™KKšœ Οmœ1™