Merge pull request #325 from micro/accept_loop

make accept loop
This commit is contained in:
Asim Aslam 2018-11-15 21:23:16 +00:00 committed by GitHub
commit 98bb4a69c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -397,11 +397,35 @@ func (s *rpcServer) Start() error {
s.opts.Address = ts.Addr() s.opts.Address = ts.Addr()
s.Unlock() s.Unlock()
go ts.Accept(s.accept) exit := make(chan bool, 1)
go func() {
for {
err := ts.Accept(s.accept)
// check if we're supposed to exit
select {
case <-exit:
return
default:
}
// check the error and backoff
if err != nil {
log.Logf("Accept error: %v", err)
time.Sleep(time.Second)
continue
}
// no error just exit
return
}
}()
go func() { go func() {
// wait for exit // wait for exit
ch := <-s.exit ch := <-s.exit
exit <- true
// wait for requests to finish // wait for requests to finish
if wait(s.opts.Context) { if wait(s.opts.Context) {