Add CloseWriters back and do an interface cast

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-21 12:52:18 -08:00
parent 592c2f6f9a
commit 8e2284aaa2
4 changed files with 11 additions and 7 deletions

View File

@ -829,10 +829,10 @@ func (container *Container) cleanup() {
utils.Errorf("%s: Error close stdin: %s", container.ID, err)
}
}
if err := container.stdout.Close(); err != nil {
if err := container.stdout.CloseWriters(); err != nil {
utils.Errorf("%s: Error close stdout: %s", container.ID, err)
}
if err := container.stderr.Close(); err != nil {
if err := container.stderr.CloseWriters(); err != nil {
utils.Errorf("%s: Error close stderr: %s", container.ID, err)
}
if container.command.Terminal != nil {

View File

@ -14,10 +14,10 @@ type Term interface {
type Pipes struct {
Stdin io.ReadCloser
Stdout, Stderr io.WriteCloser
Stdout, Stderr io.Writer
}
func NewPipes(stdin io.ReadCloser, stdout, stderr io.WriteCloser, useStdin bool) *Pipes {
func NewPipes(stdin io.ReadCloser, stdout, stderr io.Writer, useStdin bool) *Pipes {
p := &Pipes{
Stdout: stdout,
Stderr: stderr,
@ -76,7 +76,11 @@ func (t *TtyConsole) attach(command *Command, pipes *Pipes) error {
command.Console = t.Slave.Name()
go func() {
defer pipes.Stdout.Close()
if wb, ok := pipes.Stdout.(interface {
CloseWriters() error
}); ok {
defer wb.CloseWriters()
}
io.Copy(pipes.Stdout, t.Master)
}()

View File

@ -388,7 +388,7 @@ func (w *WriteBroadcaster) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (w *WriteBroadcaster) Close() error {
func (w *WriteBroadcaster) CloseWriters() error {
w.Lock()
defer w.Unlock()
for sw := range w.writers {

View File

@ -110,7 +110,7 @@ func TestWriteBroadcaster(t *testing.T) {
t.Errorf("Buffer contains %v", bufferC.String())
}
writer.Close()
writer.CloseWriters()
}
type devNullCloser int