mirror of https://github.com/golang/go.git
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:
parent
f1b7b2fc52
commit
7db923fe56
|
|
@ -2681,7 +2681,7 @@ type Server struct {
|
||||||
|
|
||||||
inShutdown atomic.Bool // true when server is in shutdown
|
inShutdown atomic.Bool // true when server is in shutdown
|
||||||
|
|
||||||
disableKeepAlives int32 // accessed atomically.
|
disableKeepAlives atomic.Bool
|
||||||
nextProtoOnce sync.Once // guards setupHTTP2_* init
|
nextProtoOnce sync.Once // guards setupHTTP2_* init
|
||||||
nextProtoErr error // result of http2.ConfigureServer if used
|
nextProtoErr error // result of http2.ConfigureServer if used
|
||||||
|
|
||||||
|
|
@ -3169,7 +3169,7 @@ func (s *Server) readHeaderTimeout() time.Duration {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) doKeepAlives() bool {
|
func (s *Server) doKeepAlives() bool {
|
||||||
return atomic.LoadInt32(&s.disableKeepAlives) == 0 && !s.shuttingDown()
|
return !s.disableKeepAlives.Load() && !s.shuttingDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) shuttingDown() bool {
|
func (s *Server) shuttingDown() bool {
|
||||||
|
|
@ -3182,10 +3182,10 @@ func (s *Server) shuttingDown() bool {
|
||||||
// shutting down should disable them.
|
// shutting down should disable them.
|
||||||
func (srv *Server) SetKeepAlivesEnabled(v bool) {
|
func (srv *Server) SetKeepAlivesEnabled(v bool) {
|
||||||
if v {
|
if v {
|
||||||
atomic.StoreInt32(&srv.disableKeepAlives, 0)
|
srv.disableKeepAlives.Store(false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
atomic.StoreInt32(&srv.disableKeepAlives, 1)
|
srv.disableKeepAlives.Store(true)
|
||||||
|
|
||||||
// Close idle HTTP/1 conns:
|
// Close idle HTTP/1 conns:
|
||||||
srv.closeIdleConns()
|
srv.closeIdleConns()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue