net: avoid Shutdown during Close

Once we've evicted all the blocked I/O, the ref count
should go to zero quickly, so it should be safe to
postpone the close(2) until then.

Fixes #1898.
Fixes #2116.
Fixes #2122.

R=golang-dev, mikioh.mikioh, bradfitz, fullung, iant
CC=golang-dev
https://golang.org/cl/5649076
diff --git a/src/pkg/net/dial_test.go b/src/pkg/net/dial_test.go
index bc87551..e5a797e 100644
--- a/src/pkg/net/dial_test.go
+++ b/src/pkg/net/dial_test.go
@@ -114,6 +114,12 @@
 	if testing.Short() {
 		n = 1000
 	}
+	switch runtime.GOOS {
+	case "darwin", "freebsd", "openbsd", "windows":
+		// Non-Linux systems take a long time to figure
+		// out that there is nothing listening on localhost.
+		n = 100
+	}
 	for i := 0; i < n; i++ {
 		c, err := Dial("tcp", addr)
 		if err == nil {