// PupEchoServ.bcpl -- Companion file is PupEchoInit.bcpl

// Last modified January 26, 1979  2:50 PM by Boggs

get "Pup0.decl"
get "Pup1.decl"
get "PupEchoServ.decl"

external
[
// outgoing procedures
EchoServCtx

// incoming procedures
Block; Dequeue; DoubleIncrement; MoveBlock
CompletePup; ReleasePBI; ExchangePorts

// outgoing statics
@es
]

static @es

//----------------------------------------------------------------------------
let EchoServCtx(ctx) be		// a context
//----------------------------------------------------------------------------
[
Block() repeatwhile es>>ES.soc>>PupSoc.iQ.head eq 0
let pbi = Dequeue(lv es>>ES.soc>>PupSoc.iQ)
ExchangePorts(pbi)
switchon pbi>>PBI.pup.type into
   [
   case ptEchoMe:
      [
      DoubleIncrement(lv es>>ES.stats.packetsEchoed)
      CompletePup(pbi, ptImAnEcho)
      endcase
      ]
   case ptStatsRequest:
      [
      MoveBlock(lv pbi>>PBI.pup.words, lv es>>ES.stats, size Stats/16)
      CompletePup(pbi, ptStatsReply, pupOvBytes+size Stats/8)
      endcase
      ]
   default: ReleasePBI(pbi)
   ]
] repeat