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

net/http: convert Server.disableKeepAlives to atomic type

Change-Id: I87526520b519554ea344288cc0f0940d7b182e21
Reviewed-on: https://go-review.googlesource.com/c/go/+/428815
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
cuiweixie 2022-09-06 22:07:08 +08:00 committed by Damien Neil
parent f1b7b2fc52
commit 7db923fe56

View File

@ -2681,7 +2681,7 @@ type Server struct {
inShutdown atomic.Bool // true when server is in shutdown
disableKeepAlives int32 // accessed atomically.
disableKeepAlives atomic.Bool
nextProtoOnce sync.Once // guards setupHTTP2_* init
nextProtoErr error // result of http2.ConfigureServer if used
@ -3169,7 +3169,7 @@ func (s *Server) readHeaderTimeout() time.Duration {
}
func (s *Server) doKeepAlives() bool {
return atomic.LoadInt32(&s.disableKeepAlives) == 0 && !s.shuttingDown()
return !s.disableKeepAlives.Load() && !s.shuttingDown()
}
func (s *Server) shuttingDown() bool {
@ -3182,10 +3182,10 @@ func (s *Server) shuttingDown() bool {
// shutting down should disable them.
func (srv *Server) SetKeepAlivesEnabled(v bool) {
if v {
atomic.StoreInt32(&srv.disableKeepAlives, 0)
srv.disableKeepAlives.Store(false)
return
}
atomic.StoreInt32(&srv.disableKeepAlives, 1)
srv.disableKeepAlives.Store(true)
// Close idle HTTP/1 conns:
srv.closeIdleConns()