[proxy] use a waitgroup as it's more semantically accurate
This commit is contained in:
1 parent
38176dcbb6
commit
5fc16a8267
1 file changed
+8
-8
@@ -9,6 +9,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
. "github.com/weaveworks/weave/common"
|
. "github.com/weaveworks/weave/common"
|
||||||
@@ -94,16 +95,15 @@ func doRawStream(w http.ResponseWriter, resp *http.Response, client *httputil.Cl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
upDone := make(chan struct{})
|
var wg sync.WaitGroup
|
||||||
downDone := make(chan struct{})
|
wg.Add(2)
|
||||||
go copyStream(down, io.MultiReader(rem, up), upDone)
|
go copyStream(down, io.MultiReader(rem, up), &wg)
|
||||||
go copyStream(up, downBuf, downDone)
|
go copyStream(up, downBuf, &wg)
|
||||||
<-upDone
|
wg.Wait()
|
||||||
<-downDone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyStream(dst io.Writer, src io.Reader, done chan struct{}) {
|
func copyStream(dst io.Writer, src io.Reader, wg *sync.WaitGroup) {
|
||||||
defer close(done)
|
defer wg.Done()
|
||||||
if _, err := io.Copy(dst, src); err != nil {
|
if _, err := io.Copy(dst, src); err != nil {
|
||||||
Warning.Print(err)
|
Warning.Print(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user