• Brad Fitzpatrick's avatar
    net: add Dialer.Cancel to cancel pending dials · 24a83d35
    Brad Fitzpatrick authored
    Dialer.Cancel is a new optional <-chan struct{} channel whose closure
    indicates that the dial should be canceled. It is compatible with the
    x/net/context and http.Request.Cancel types.
    
    Tested by hand with:
    
    package main
    
        import (
                "log"
                "net"
                "time"
        )
    
        func main() {
                log.Printf("start.")
                var d net.Dialer
                cancel := make(chan struct{})
                time.AfterFunc(2*time.Second, func() {
                        log.Printf("timeout firing")
                        close(cancel)
                })
                d.Cancel = cancel
                c, err := d.Dial("tcp", "192.168.0.1:22")
                if err != nil {
                        log.Print(err)
                        return
                }
                log.Fatalf("unexpected connect: %v", c)
        }
    
    Which says:
    
        2015/12/14 22:24:58 start.
        2015/12/14 22:25:00 timeout firing
        2015/12/14 22:25:00 dial tcp 192.168.0.1:22: operation was canceled
    
    Fixes #11225
    
    Change-Id: I2ef39e3a540e29fe6bfec03ab7a629a6b187fcb3
    Reviewed-on: https://go-review.googlesource.com/17821Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    24a83d35
Name
Last commit
Last update
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...