github.com/gondor/docker@v1.9.0-rc1/daemon/execdriver/windows/namedpipes.go (about) 1 // +build windows 2 3 package windows 4 5 import ( 6 "io" 7 8 "github.com/Sirupsen/logrus" 9 "github.com/docker/docker/daemon/execdriver" 10 ) 11 12 // General comment. Handling I/O for a container is very different to Linux. 13 // We use a named pipe to HCS to copy I/O both in and out of the container, 14 // very similar to how docker daemon communicates with a CLI. 15 16 // startStdinCopy asynchronously copies an io.Reader to the container's 17 // process's stdin pipe and closes the pipe when there is no more data to copy. 18 func startStdinCopy(dst io.WriteCloser, src io.Reader) { 19 20 // Anything that comes from the client stdin should be copied 21 // across to the stdin named pipe of the container. 22 go func() { 23 defer dst.Close() 24 bytes, err := io.Copy(dst, src) 25 logrus.Debugf("Copied %d bytes from stdin err=%s", bytes, err) 26 }() 27 } 28 29 // startStdouterrCopy asynchronously copies data from the container's process's 30 // stdout or stderr pipe to an io.Writer and closes the pipe when there is no 31 // more data to copy. 32 func startStdouterrCopy(dst io.Writer, src io.ReadCloser, name string) { 33 // Anything that comes from the container named pipe stdout/err should be copied 34 // across to the stdout/err of the client 35 go func() { 36 defer src.Close() 37 bytes, err := io.Copy(dst, src) 38 logrus.Debugf("Copied %d bytes from %s err=%s", bytes, name, err) 39 }() 40 } 41 42 // setupPipes starts the asynchronous copying of data to and from the named 43 // pipes used byt he HCS for the std handles. 44 func setupPipes(stdin io.WriteCloser, stdout, stderr io.ReadCloser, pipes *execdriver.Pipes) { 45 if stdin != nil { 46 startStdinCopy(stdin, pipes.Stdin) 47 } 48 if stdout != nil { 49 startStdouterrCopy(pipes.Stdout, stdout, "stdout") 50 } 51 if stderr != nil { 52 startStdouterrCopy(pipes.Stderr, stderr, "stderr") 53 } 54 }