• Brad Fitzpatrick's avatar
    net: add DialOpt, the extensible Dial w/ options dialer · 752fec22
    Brad Fitzpatrick authored
    Add DialOpt. So we have:
    
    func Dial(net, addr string) (Conn, error)
    func DialTimeout(net, addr string, timeout time.Duration) (Conn, error)
    func DialOpt(addr string, opts ...DialOption) (Conn, error)
    
    DialTimeout (and Dial) are regrettable in retrospect. Maybe
    in a future Go we'll be back down to one Dial, with DialOpt
    becoming Dial.
    
    DialOpt looks like:
    
    c, err := net.DialOpt("google.com:80")  // tcp is default
    c, err := net.DialOpt("google.com:80", net.Timeout(30 * time.Second))
    c, err := net.DialOpt("google.com:80", net.TCPFastOpen())
    c, err := net.DialOpt("google.com:80", net.LocalAddr(..))
    c, err := net.DialOpt("google.com:53", net.Network("udp6"))
    
    And then: (clustered in godoc)
    
    type DialOption interface { /* private only */ }
      func Deadline(time.Time) DialOption
      func LocalAddr(Addr) DialOption
      func Network(string) DialOption
      func TCPFastOpen() DialOption
      func Timeout(time.Duration) DialOption
    
    I'm pretty confident we could add Happy Eyeballs to this too.
    
    Fixes #3097
    Update #3610
    Update #4842
    
    R=golang-dev, r, dave, minux.ma, rsc
    CC=golang-dev
    https://golang.org/cl/7365049
    752fec22
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
include Loading commit data...
lib Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.hgignore Loading commit data...
.hgtags Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...