]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: convert Server.disableKeepAlives to atomic type
authorcuiweixie <cuiweixie@gmail.com>
Tue, 6 Sep 2022 14:07:08 +0000 (22:07 +0800)
committerDamien Neil <dneil@google.com>
Mon, 19 Sep 2022 22:51:53 +0000 (22:51 +0000)
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>
src/net/http/server.go

index d96283ccc4dd1f8cda10b976efdbae3b5987dc1e..b22528dcdb54dc38adc60ff3c670ea641c102b57 100644 (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()