Fixes #33743.
Change-Id: I80621321d56b6cf312a86e272800f1ad03c5544c
GitHub-Last-Rev:
d91cb3697516ccfc3f956e97837404cbfee5922f
GitHub-Pull-Request: golang/go#33856
Reviewed-on: https://go-review.googlesource.com/c/go/+/191879
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
// The zero value for each field is equivalent to dialing
// without that option. Dialing with the zero value of Dialer
// is therefore equivalent to just calling the Dial function.
+//
+// It is safe to call Dialer's methods concurrently.
type Dialer struct {
// Timeout is the maximum amount of time a dial will wait for
// a connect to complete. If Deadline is also set, it may fail
package net_test
import (
+ "context"
"fmt"
"io"
"log"
"net"
+ "time"
)
func ExampleListener() {
}
}
+func ExampleDialer() {
+ var d net.Dialer
+ ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
+ defer cancel()
+
+ conn, err := d.DialContext(ctx, "tcp", "localhost:12345")
+ if err != nil {
+ log.Fatalf("Failed to dial: %v", err)
+ }
+ defer conn.Close()
+
+ if _, err := conn.Write([]byte("Hello, World!")); err != nil {
+ log.Fatal(err)
+ }
+}
+
func ExampleIPv4() {
fmt.Println(net.IPv4(8, 8, 8, 8))