1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:04:48 -07:00

net/http: remove unused doneChan

The https://golang.org/cl/43230 removed use of `getDoneChan`.
This commit is contained in:
Alexander Yastrebov 2022-06-01 02:00:01 +02:00
parent 085529bd5f
commit fe1e4154ea

View File

@ -2688,35 +2688,9 @@ type Server struct {
mu sync.Mutex
listeners map[*net.Listener]struct{}
activeConn map[*conn]struct{}
doneChan chan struct{}
onShutdown []func()
}
func (s *Server) getDoneChan() <-chan struct{} {
s.mu.Lock()
defer s.mu.Unlock()
return s.getDoneChanLocked()
}
func (s *Server) getDoneChanLocked() chan struct{} {
if s.doneChan == nil {
s.doneChan = make(chan struct{})
}
return s.doneChan
}
func (s *Server) closeDoneChanLocked() {
ch := s.getDoneChanLocked()
select {
case <-ch:
// Already closed. Don't close again.
default:
// Safe to close here. We're the only closer, guarded
// by s.mu.
close(ch)
}
}
// Close immediately closes all active net.Listeners and any
// connections in state StateNew, StateActive, or StateIdle. For a
// graceful shutdown, use Shutdown.
@ -2730,7 +2704,6 @@ func (srv *Server) Close() error {
srv.inShutdown.setTrue()
srv.mu.Lock()
defer srv.mu.Unlock()
srv.closeDoneChanLocked()
err := srv.closeListenersLocked()
for c := range srv.activeConn {
c.rwc.Close()
@ -2773,7 +2746,6 @@ func (srv *Server) Shutdown(ctx context.Context) error {
srv.mu.Lock()
lnerr := srv.closeListenersLocked()
srv.closeDoneChanLocked()
for _, f := range srv.onShutdown {
go f()
}
@ -3063,10 +3035,8 @@ func (srv *Server) Serve(l net.Listener) error {
for {
rw, err := l.Accept()
if err != nil {
select {
case <-srv.getDoneChan():
if srv.shuttingDown() {
return ErrServerClosed
default:
}
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {