converge/pkg/support/iowrappers/sync.go
Erik Brakkee 882f97fa17 many small changes
* removed the Async utility
* now using Ping message to webclient for keep alive instaed of actual content
* added remote shell to AgentInfo
* retry of connections to the agent
* better logging for SynchronizeStreams
2024-09-08 11:16:49 +02:00

34 lines
644 B
Go

package iowrappers
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)
}