net: context plumbing, add Dialer.DialContext
For #12580 (http.Transport tracing/analytics)
Updates #13021
Change-Id: I126e494a7bd872e42c388ecb58499ecbf0f014cc
Reviewed-on: https://go-review.googlesource.com/22101
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
diff --git a/src/net/net.go b/src/net/net.go
index 3b37b33..27e9ca3 100644
--- a/src/net/net.go
+++ b/src/net/net.go
@@ -79,6 +79,7 @@
package net
import (
+ "context"
"errors"
"io"
"os"
@@ -377,6 +378,22 @@
ErrWriteToConnected = errors.New("use of WriteTo with pre-connected connection")
)
+// mapErr maps from the context errors to the historical internal net
+// error values.
+//
+// TODO(bradfitz): get rid of this after adjusting tests and making
+// context.DeadlineExceeded implement net.Error?
+func mapErr(err error) error {
+ switch err {
+ case context.Canceled:
+ return errCanceled
+ case context.DeadlineExceeded:
+ return errTimeout
+ default:
+ return err
+ }
+}
+
// OpError is the error type usually returned by functions in the net
// package. It describes the operation, network type, and address of
// an error.