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

// Last modified January 13, 1979  2:19 PM by Boggs

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

external
[
// outgoing procedures
CreateEchoServ; DestroyEchoServ

// incoming procedures
EchoServCtx
Allocate; Free; Enqueue; Unqueue
InitializeContext; Block; Zero
OpenLevel1Socket; CloseLevel1Socket; SetAllocation

// incoming statics
@es
]


//----------------------------------------------------------------------------
let CreateEchoServ(zone, ctxQ) be
//----------------------------------------------------------------------------
[
es = Allocate(zone, lenES); Zero(es, lenES)
es>>ES.zone = zone
es>>ES.ctxQ = ctxQ
es>>ES.stats.version = echoStatsVersion
es>>ES.soc = Allocate(zone, lenPupSoc)
OpenLevel1Socket(es>>ES.soc, table [ 0; 0; psEchoServ ])
SetAllocation(es>>ES.soc, 1, 1, 0)
es>>ES.ctx = InitializeContext(Allocate(zone, 75), 75, EchoServCtx)
Enqueue(ctxQ, es>>ES.ctx)
]

//----------------------------------------------------------------------------
and DestroyEchoServ() be
//----------------------------------------------------------------------------
[
Unqueue(es>>ES.ctxQ, es>>ES.ctx)
CloseLevel1Socket(es>>ES.soc)
Free(es>>ES.zone, es>>ES.soc)
Free(es>>ES.zone, es>>ES.ctx)
Free(es>>ES.zone, es)
]