34 lines
641 B
Go
34 lines
641 B
Go
package ioutils
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
func SynchronizeStreams(description string, stream1, stream2 io.ReadWriter) {
|
|
waitChannel := make(chan bool, 2)
|
|
|
|
go func() {
|
|
defer func() {
|
|
waitChannel <- true
|
|
}()
|
|
_, err := io.Copy(stream1, stream2)
|
|
if err != nil {
|
|
log.Printf("SynchronizeStreams: %s: error <-: %v\n", description, err)
|
|
}
|
|
}()
|
|
|
|
go func() {
|
|
defer func() {
|
|
waitChannel <- true
|
|
}()
|
|
_, err := io.Copy(stream2, stream1)
|
|
if err != nil {
|
|
log.Printf("SynchronizeStreams: %s: error ->: %v\n", description, err)
|
|
}
|
|
}()
|
|
|
|
<-waitChannel
|
|
log.Printf("SynchronizeStreams: %s: Connection closed", description)
|
|
}
|