use a WriteCloser and close the pipe in streams

This commit is contained in:
vyzo 2018-09-13 20:17:22 +03:00
parent 3c37581465
commit daf1ac8c67
1 changed files with 2 additions and 2 deletions

View File

@ -13,12 +13,13 @@ func (d *Daemon) doStreamPipe(c net.Conn, s inet.Stream) {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(2) wg.Add(2)
pipe := func(dst io.Writer, src io.Reader) { pipe := func(dst io.WriteCloser, src io.Reader) {
_, err := io.Copy(dst, src) _, err := io.Copy(dst, src)
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
log.Debugf("stream error: %s", err.Error()) log.Debugf("stream error: %s", err.Error())
s.Reset() s.Reset()
} }
dst.Close()
wg.Done() wg.Done()
} }
@ -26,7 +27,6 @@ func (d *Daemon) doStreamPipe(c net.Conn, s inet.Stream) {
go pipe(s, c) go pipe(s, c)
wg.Wait() wg.Wait()
s.Close()
} }
func (d *Daemon) handleStream(s inet.Stream) { func (d *Daemon) handleStream(s inet.Stream) {