Commit decf9f6f authored by Davor Kapsa's avatar Davor Kapsa Committed by Brad Fitzpatrick

net/http: use err as error var in server.Serve

Change-Id: Icbf97d640fb26eed646f9e85c1f1c94b1469ca4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/199778Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 868de9a1
...@@ -2886,8 +2886,6 @@ func (srv *Server) Serve(l net.Listener) error { ...@@ -2886,8 +2886,6 @@ func (srv *Server) Serve(l net.Listener) error {
} }
defer srv.trackListener(&l, false) defer srv.trackListener(&l, false)
var tempDelay time.Duration // how long to sleep on accept failure
baseCtx := context.Background() baseCtx := context.Background()
if srv.BaseContext != nil { if srv.BaseContext != nil {
baseCtx = srv.BaseContext(origListener) baseCtx = srv.BaseContext(origListener)
...@@ -2896,16 +2894,18 @@ func (srv *Server) Serve(l net.Listener) error { ...@@ -2896,16 +2894,18 @@ func (srv *Server) Serve(l net.Listener) error {
} }
} }
var tempDelay time.Duration // how long to sleep on accept failure
ctx := context.WithValue(baseCtx, ServerContextKey, srv) ctx := context.WithValue(baseCtx, ServerContextKey, srv)
for { for {
rw, e := l.Accept() rw, err := l.Accept()
if e != nil { if err != nil {
select { select {
case <-srv.getDoneChan(): case <-srv.getDoneChan():
return ErrServerClosed return ErrServerClosed
default: default:
} }
if ne, ok := e.(net.Error); ok && ne.Temporary() { if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 { if tempDelay == 0 {
tempDelay = 5 * time.Millisecond tempDelay = 5 * time.Millisecond
} else { } else {
...@@ -2914,11 +2914,11 @@ func (srv *Server) Serve(l net.Listener) error { ...@@ -2914,11 +2914,11 @@ func (srv *Server) Serve(l net.Listener) error {
if max := 1 * time.Second; tempDelay > max { if max := 1 * time.Second; tempDelay > max {
tempDelay = max tempDelay = max
} }
srv.logf("http: Accept error: %v; retrying in %v", e, tempDelay) srv.logf("http: Accept error: %v; retrying in %v", err, tempDelay)
time.Sleep(tempDelay) time.Sleep(tempDelay)
continue continue
} }
return e return err
} }
if cc := srv.ConnContext; cc != nil { if cc := srv.ConnContext; cc != nil {
ctx = cc(ctx, rw) ctx = cc(ctx, rw)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment