]> Cypherpunks repositories - gostls13.git/commitdiff
http: shut up a false Transport warning on Windows
authorBrad Fitzpatrick <bradfitz@golang.org>
Fri, 14 Oct 2011 18:31:00 +0000 (11:31 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 14 Oct 2011 18:31:00 +0000 (11:31 -0700)
Fixes #2057

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5269044

src/pkg/http/Makefile
src/pkg/http/transport.go
src/pkg/http/transport_windows.go [new file with mode: 0644]

index af4fbc12e024ba36a415373afb8d6210e967af02..bde50cf7a251166c6cb6fa37f93f624c1503ef03 100644 (file)
@@ -24,4 +24,9 @@ GOFILES=\
        transfer.go\
        transport.go\
 
+GOFILES_windows=\
+       transport_windows.go\
+       
+GOFILES+=$(GOFILES_$(GOOS))
+
 include ../../Make.pkg
index a580e1f7cb40a90e68a3a8139055c6628ad32a3d..d46d565677f2f72da60279546abc524c638aaf1e 100644 (file)
@@ -489,12 +489,24 @@ func (pc *persistConn) expectingResponse() bool {
        return pc.numExpectedResponses > 0
 }
 
+var remoteSideClosedFunc func(os.Error) bool // or nil to use default
+
+func remoteSideClosed(err os.Error) bool {
+       if err == os.EOF || err == os.EINVAL {
+               return true
+       }
+       if remoteSideClosedFunc != nil {
+               return remoteSideClosedFunc(err)
+       }
+       return false
+}
+
 func (pc *persistConn) readLoop() {
        alive := true
        for alive {
                pb, err := pc.br.Peek(1)
                if err != nil {
-                       if (err == os.EOF || err == os.EINVAL) && !pc.expectingResponse() {
+                       if remoteSideClosed(err) && !pc.expectingResponse() {
                                // Remote side closed on us.  (We probably hit their
                                // max idle timeout)
                                pc.close()
diff --git a/src/pkg/http/transport_windows.go b/src/pkg/http/transport_windows.go
new file mode 100644 (file)
index 0000000..1ae7d83
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package http
+
+import (
+       "os"
+       "net"
+)
+
+func init() {
+       remoteSideClosedFunc = func(err os.Error) (out bool) {
+               op, ok := err.(*net.OpError)
+               if ok && op.Op == "WSARecv" && op.Net == "tcp" && op.Error == os.Errno(10058) {
+                       // TODO(bradfitz): find the symbol for 10058
+                       return true
+               }
+               return false
+       }
+}