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