Skip to content

Commit

Permalink
pipe 时任意一端断开时即刻断开另一端 (improv)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasen committed Mar 6, 2016
1 parent 1715997 commit 92480b7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.go
Expand Up @@ -310,7 +310,7 @@ func tunneling(addr string, rdr *bufio.Reader, c net.Conn, header *bytes.Buffer)
}

// Start transfering data
ch := make(chan bool, 2)
ch := make(chan struct{}, 2)
go pipe(c, backend, ch)
go pipe(backend, rdr, ch)
<-ch
Expand Down Expand Up @@ -381,14 +381,14 @@ func ipAddrFromRemoteAddr(s string) string {
}

// pipe upstream and downstream
func pipe(dst io.Writer, src io.Reader, ch chan bool) {
func pipe(dst io.Writer, src io.Reader, ch chan struct{}) {
defer func() {
if r := recover(); r != nil {
log.Println("Recovered in", r, ":", string(debug.Stack()))
}
}()
defer func() {
ch <- true
ch <- struct{}{}
}()

_, err := io.Copy(dst, src)
Expand Down

0 comments on commit 92480b7

Please sign in to comment.