Skip to content

Commit

Permalink
container/stream/attach: use pools.Copy
Browse files Browse the repository at this point in the history
The use of pools.Copy avoids io.Copy's internal buffer allocation.
This commit replaces io.Copy with pools.Copy to avoid the allocation of
buffers in io.Copy.

Signed-off-by: Cristian Staretu <[email protected]>
  • Loading branch information
unclejack committed Jun 10, 2017
1 parent ba40f45 commit 014095e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions container/stream/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"golang.org/x/net/context"

"github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/term"
)
Expand Down Expand Up @@ -86,7 +87,7 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) chan error
if cfg.TTY {
_, err = copyEscapable(cfg.CStdin, cfg.Stdin, cfg.DetachKeys)
} else {
_, err = io.Copy(cfg.CStdin, cfg.Stdin)
_, err = pools.Copy(cfg.CStdin, cfg.Stdin)
}
if err == io.ErrClosedPipe {
err = nil
Expand Down Expand Up @@ -116,7 +117,7 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) chan error
}

logrus.Debugf("attach: %s: begin", name)
_, err := io.Copy(stream, streamPipe)
_, err := pools.Copy(stream, streamPipe)
if err == io.ErrClosedPipe {
err = nil
}
Expand Down Expand Up @@ -174,5 +175,5 @@ func copyEscapable(dst io.Writer, src io.ReadCloser, keys []byte) (written int64
pr := term.NewEscapeProxy(src, keys)
defer src.Close()

return io.Copy(dst, pr)
return pools.Copy(dst, pr)
}

0 comments on commit 014095e

Please sign in to comment.