use done chan for waiting pipe

This commit is contained in:
Cooper Oh 2024-07-19 00:32:35 +09:00
parent 5e557d257e
commit d249ef1a3b
1 changed files with 4 additions and 5 deletions

View File

@ -109,17 +109,16 @@ func (s *cstProxyServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
_, _ = fmt.Fprintf(conn, "HTTP/1.1 200 Connection established\r\n\r\n")
wg := sync.WaitGroup{}
wg.Add(2)
done := make(chan struct{}, 2)
go func() {
defer wg.Done()
_, _ = io.Copy(upstream, conn)
done <- struct{}{}
}()
go func() {
defer wg.Done()
_, _ = io.Copy(conn, upstream)
done <- struct{}{}
}()
wg.Wait()
<-done
}
func newProxyServer() *httptest.Server {