Addr string // host:port where the server is listening.
err error
cond *sync.Cond
- done bool
+ running bool
listener *net.TCPListener
wantDown bool
}
mutex := &sync.RWMutex{}
srv.cond = sync.NewCond(mutex.RLocker())
+ srv.running = true
go func() {
err = srv.Serve(tcpKeepAliveListener{srv.listener})
if !srv.wantDown {
srv.err = err
}
mutex.Lock()
- srv.done = true
+ srv.running = false
srv.cond.Broadcast()
mutex.Unlock()
}()
// Wait returns when the server has shut down.
func (srv *server) Wait() error {
+ if srv.cond == nil {
+ return nil
+ }
srv.cond.L.Lock()
defer srv.cond.L.Unlock()
- for !srv.done {
+ for srv.running {
srv.cond.Wait()
}
return srv.err