You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
482 B
Go

8 years ago
package obfssh
import (
"io"
4 years ago
"github.com/fangdingjun/go-log/v5"
8 years ago
)
// PipeAndClose pipe the data between c and s, close both when done
func PipeAndClose(c io.ReadWriteCloser, s io.ReadWriteCloser) {
7 years ago
defer func() {
if err := recover(); err != nil {
log.Errorf("recovered: %+v", err)
7 years ago
}
}()
8 years ago
defer c.Close()
defer s.Close()
cc := make(chan struct{}, 2)
8 years ago
go func() {
io.Copy(c, s)
cc <- struct{}{}
8 years ago
}()
go func() {
io.Copy(s, c)
cc <- struct{}{}
8 years ago
}()
<-cc
}