File tree Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Expand file tree Collapse file tree 1 file changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -6,18 +6,23 @@ import (
66
77// proxy between two sockets
88func Shovel (local , remote io.ReadWriteCloser ) error {
9- err := make (chan error )
9+ errch := make (chan error , 1 )
1010
11- go chanCopy (err , local , remote )
12- go chanCopy (err , remote , local )
11+ go chanCopy (errch , local , remote )
12+ go chanCopy (errch , remote , local )
1313
14- return <- err
14+ for i := 0 ; i < 2 ; i ++ {
15+ if err := <- errch ; err != nil {
16+ // If this returns early the second func will push into the
17+ // buffer, and the GC will clean up
18+ return err
19+ }
20+ }
21+ return nil
1522}
1623
1724// copy between pipes, sending errors to channel
1825func chanCopy (e chan error , dst , src io.ReadWriter ) {
1926 _ , err := io .Copy (dst , src )
20- if err != nil {
21- e <- err
22- }
27+ e <- err
2328}
You can’t perform that action at this time.
0 commit comments