DIRECTORY BasicTime, Commander, IO, NetworkStream, Process, SimpleFeedback; RoundTripServer: CEDAR PROGRAM IMPORTS BasicTime, Commander, IO, NetworkStream, Process, SimpleFeedback = BEGIN Time: TYPE ~ RECORD [s, us: INT]; unixOrg: BasicTime.GMT ~ BasicTime.Pack[[year: 1970, month: January, day: 1, hour: 0, minute: 0, second: 0, zone: 0, dst: no]]; soon: CARD ฌ 0; l: NetworkStream.Listener ฌ NIL; SetSoon: Commander.CommandProc ~ { in: IO.STREAM ~ IO.RIS[cmd.commandLine]; soon ฌ in.GetCard[]; RETURN [$Success, IO.PutFR1["soon = %g", [cardinal[soon]] ]]}; Stopit: Commander.CommandProc ~ { IF l#NIL THEN { NetworkStream.DestroyListener[l !NetworkStream.Error => CONTINUE]; l ฌ NIL; Process.PauseMsec[5000]}; RETURN}; Restart: Commander.CommandProc ~ { IF l#NIL THEN { NetworkStream.DestroyListener[l !NetworkStream.Error => CONTINUE]; l ฌ NIL; Process.PauseMsec[5000]}; IF MakeListener[] THEN RETURN [$Success, "Server re-made"] ELSE RETURN [$Failure, "Something went wrong"]}; MakeListener: PROC RETURNS [success: BOOL ฌ TRUE] ~ { l ฌ NetworkStream.CreateListener[ protocolFamily: $ARPA, local: ":58801", transportClass: $basicStream, listenerWorkerProc: Work !NetworkStream.Error => { SimpleFeedback.PutFL[$RoundTripServer, oneLiner, $Error, "NetworkStream.Error[LIST[%g, ..], %g] creating RoundTripServer listener.", LIST[[atom[codes.first]], [rope[msg]] ]]; success ฌ FALSE; CONTINUE} ]; RETURN}; Work: PROC [listener: NetworkStream.Listener, in, out: IO.STREAM] ~ { start, mid: Time; GetNow: PROC RETURNS [Time] ~ { egmt: BasicTime.ExtendedGMT ~ BasicTime.ExtendedNow[]; RETURN [[BasicTime.Period[from: unixOrg, to: egmt.gmt], egmt.usecs]]}; GetTime: PROC RETURNS [Time] ~ { s: CARD ~ GetCard[]; us: CARD ~ GetCard[]; RETURN [[s, us]]}; GetCard: PROC RETURNS [CARD] ~ { hi: CARDINAL ~ GetShort[]; RETURN [hi*10000H + GetShort[]]}; GetShort: PROC RETURNS [CARDINAL] ~ { hi: BYTE ~ in.GetChar[].ORD; RETURN [hi*100H + in.GetChar[].ORD]}; PutCard: PROC [c: CARD] ~ {PutShort[c/10000H]; PutShort[c MOD 10000H]}; PutShort: PROC [c: CARDINAL] ~ { out.PutChar[VAL[c/100H]]; out.PutChar[VAL[c MOD 100H]]}; DO ENABLE IO.Error, IO.EndOfStream => EXIT; start ฌ GetTime[]; mid ฌ GetNow[]; PutCard[start.s]; PutCard[start.us]; PutCard[mid.s]; PutCard[mid.us]; NetworkStream.SendSoon[out, soon]; ENDLOOP; in.Close[!IO.Error => CONTINUE]; out.Close[!IO.Error => CONTINUE]; RETURN}; Start: PROC ~ { [] ฌ MakeListener[]; Commander.Register["RoundTripSetSoon", SetSoon, ""]; Commander.Register["RoundTripStop", Stopit, "kills server"]; Commander.Register["RoundTripRestart", Restart, "(re-)creates server"]; }; Start[]; END. € RoundTripServer.mesa Copyright ำ 1992 by Xerox Corporation. All rights reserved. Spreitze, March 25, 1992 12:47 pm PST สห–(cedarcode) style•NewlineDelimiter ™code™Kšœ ฯeœ1™—K˜šŸœ˜!šžœžœžœ˜Kšœ8žœ˜BKšœžœ˜Kšœ˜—Kšžœ˜—K˜šŸœ˜"šžœžœžœ˜Kšœ8žœ˜BKšœžœ˜Kšœ˜—šžœ˜Kšžœžœ˜(Kšžœžœ%˜0——K˜š Ÿ œžœžœ žœžœ˜5˜!Kšœ˜Kšœ˜Kšœ˜Kšœ˜˜Kšœ…žœ%˜ฎKšœ žœ˜Kšžœ˜ —Kšœ˜—Kšžœ˜—K˜šŸœžœ-žœžœ˜EK˜šŸœžœžœ ˜Kšœ6˜6Kšžœ@˜F—šŸœžœžœ ˜ Kšœžœ ˜Kšœžœ ˜Kšžœ ˜—šŸœžœžœžœ˜ Kšœžœžœ˜<—šŸœžœžœžœ˜%Kšœžœžœ˜Kšžœžœ˜%—KšŸœžœžœ$žœ ˜GšŸœžœžœ˜ Kšœ žœ ˜Kšœ žœžœ ˜—š žœžœžœžœžœ˜+K˜K˜K˜K˜K˜K˜Kšœ"˜"Kšžœ˜—Kšœ žœ žœ˜ Kšœ žœ žœ˜!Kšžœ˜—K˜šŸœžœ˜K˜K˜BK˜