@@ -21,6 +21,7 @@ import (
21
21
"context"
22
22
"fmt"
23
23
"net"
24
+ "time"
24
25
)
25
26
26
27
// Available returns whether or not SO_REUSEPORT or equivalent behaviour is
@@ -47,17 +48,25 @@ func ListenPacket(network, address string) (net.PacketConn, error) {
47
48
return listenConfig .ListenPacket (context .Background (), network , address )
48
49
}
49
50
50
- // Dial dials the given network and address. see net.Dialer. Dial
51
+ // Dial dials the given network and address. see net.Dial
51
52
// Returns a net.Conn created from a file descriptor for a socket
52
53
// with SO_REUSEPORT and SO_REUSEADDR option set.
53
54
func Dial (network , laddr , raddr string ) (net.Conn , error ) {
55
+ return DialTimeout (network , laddr , raddr , time .Duration (0 ))
56
+ }
57
+
58
+ // Dial dials the given network and address, with the given timeout. see
59
+ // net.DialTimeout Returns a net.Conn created from a file descriptor for
60
+ // a socket with SO_REUSEPORT and SO_REUSEADDR option set.
61
+ func DialTimeout (network , laddr , raddr string , timeout time.Duration ) (net.Conn , error ) {
54
62
nla , err := ResolveAddr (network , laddr )
55
63
if err != nil {
56
64
return nil , fmt .Errorf ("failed to resolve local addr: %w" , err )
57
65
}
58
66
d := net.Dialer {
59
67
Control : Control ,
60
68
LocalAddr : nla ,
69
+ Timeout : timeout ,
61
70
}
62
71
return d .Dial (network , raddr )
63
72
}
0 commit comments