diff --git a/client/main.go b/client/main.go index c79521659..1b98ffe86 100644 --- a/client/main.go +++ b/client/main.go @@ -77,10 +77,18 @@ func handleClient(sess *smux.Session, p1 io.ReadWriteCloser, quiet bool) { streamCopy := func(dst io.Writer, src io.Reader) chan struct{} { die := make(chan struct{}) go func() { - buf := xmitBuf.Get().([]byte) - io.CopyBuffer(dst, src, buf) - xmitBuf.Put(buf) - close(die) + if wt, ok := src.(io.WriterTo); ok { + wt.WriteTo(dst) + close(die) + } else if rt, ok := dst.(io.ReaderFrom); ok { + rt.ReadFrom(src) + close(die) + } else { + buf := xmitBuf.Get().([]byte) + io.CopyBuffer(dst, src, buf) + xmitBuf.Put(buf) + close(die) + } }() return die } diff --git a/server/main.go b/server/main.go index 6f66c23ee..75897a1ba 100644 --- a/server/main.go +++ b/server/main.go @@ -105,10 +105,18 @@ func handleClient(p1, p2 io.ReadWriteCloser, quiet bool) { streamCopy := func(dst io.Writer, src io.Reader) chan struct{} { die := make(chan struct{}) go func() { - buf := xmitBuf.Get().([]byte) - io.CopyBuffer(dst, src, buf) - xmitBuf.Put(buf) - close(die) + if wt, ok := src.(io.WriterTo); ok { + wt.WriteTo(dst) + close(die) + } else if rt, ok := dst.(io.ReaderFrom); ok { + rt.ReadFrom(src) + close(die) + } else { + buf := xmitBuf.Get().([]byte) + io.CopyBuffer(dst, src, buf) + xmitBuf.Put(buf) + close(die) + } }() return die }