// PupNameInit.bcpl

// Last modified February 2, 1979  3:34 PM by Boggs

get "Pup0.decl"
get "Pup1.decl"
get "PupNameServ.decl"

external
[
// outgoing procedures
CreateNameServ; DestroyNameServ
SetNameBcstInterval

// incoming procedures
NameServCtx; LockNameServ; UnlockNameServ
Allocate; Free; Zero; Enqueue; Unqueue; InitializeContext

// incoming statics
@ns; @ms
]

manifest nsss = alto? 200, 100  // name server stack size

//----------------------------------------------------------------------------
let CreateNameServ() be
//----------------------------------------------------------------------------
[
ns = Allocate(ms>>MS.zone, lenNS); Zero(ns, lenNS)
ns>>NS.stats.version = nameStatsVersion
ns>>NS.ctx = InitializeContext(Allocate(ms>>MS.zone, nsss), nsss, NameServCtx)
Enqueue(ms>>MS.ctxQ, ns>>NS.ctx)
ns>>NS.header = Allocate(ms>>MS.zone, lenHdr); Zero(ns>>NS.header, lenHdr)
ns>>NS.cacheZone = Allocate(ms>>MS.zone, lenCacheZone)
UnlockNameServ()
ns>>NS.bcstTimer = 12  //wait 1 minute before first probe
SetNameBcstInterval(1)  // default is 1 hour
]

//----------------------------------------------------------------------------
and DestroyNameServ() be
//----------------------------------------------------------------------------
[
LockNameServ()
Unqueue(ms>>MS.ctxQ, ns>>NS.ctx)
Free(ms>>MS.zone, ns>>NS.ctx)
Free(ms>>MS.zone, ns>>NS.header)
Free(ms>>MS.zone, ns>>NS.cacheZone)
Free(ms>>MS.zone, ns)
]

//----------------------------------------------------------------------------
and SetNameBcstInterval(hours) be ns>>NS.bcstInterval = hours * 720
//----------------------------------------------------------------------------