diff options
author | Ahmet Alp Balkan <ahmetalpbalkan@gmail.com> | 2015-03-26 15:52:16 -0700 |
---|---|---|
committer | Jessica Frazelle <jess@docker.com> | 2015-03-31 10:39:59 -0700 |
commit | ebcb36a8d270eb233b5955ec33f18a774644a840 (patch) | |
tree | 870992b0f6b8732870c1f90d96e7f718e51716ce | |
parent | e6e8f2d717b5e7f17abaf2016a6b70a6e49581e9 (diff) | |
download | docker-ebcb36a8d270eb233b5955ec33f18a774644a840.tar.gz |
windows: monitorTtySize correctly by polling
This change makes `monitorTtySize` work correctly on windows by polling
into win32 API to get terminal size (because there's no SIGWINCH on
windows) and send it to the engine over Remove API properly.
Average getttysize syscall takes around 30-40 ms on an average windows
machine as far as I can tell, therefore in a `for` loop, checking every
250ms if size has changed or not.
I'm not sure if there's a better way to do it on windows, if so,
somebody please send a link 'cause I could not find.
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
(cherry picked from commit ebbceea8a79766b7624dd7970a79054ecf582b6d)
Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <jess@docker.com> (github: jfrazelle)
Docker-DCO-1.1-Signed-off-by: Jessie Frazelle <princess@docker.com> (github: jfrazelle)
-rw-r--r-- | api/client/utils.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/api/client/utils.go b/api/client/utils.go index 29aa203971..83d1e21775 100644 --- a/api/client/utils.go +++ b/api/client/utils.go @@ -12,8 +12,10 @@ import ( "net/url" "os" gosignal "os/signal" + "runtime" "strconv" "strings" + "time" log "github.com/Sirupsen/logrus" "github.com/docker/docker/api" @@ -277,13 +279,29 @@ func getExecExitCode(cli *DockerCli, execID string) (bool, int, error) { func (cli *DockerCli) monitorTtySize(id string, isExec bool) error { cli.resizeTty(id, isExec) - sigchan := make(chan os.Signal, 1) - gosignal.Notify(sigchan, signal.SIGWINCH) - go func() { - for _ = range sigchan { - cli.resizeTty(id, isExec) - } - }() + if runtime.GOOS == "windows" { + go func() { + prevW, prevH := cli.getTtySize() + for { + time.Sleep(time.Millisecond * 250) + w, h := cli.getTtySize() + + if prevW != w || prevH != h { + cli.resizeTty(id, isExec) + } + prevW = w + prevH = h + } + }() + } else { + sigchan := make(chan os.Signal, 1) + gosignal.Notify(sigchan, signal.SIGWINCH) + go func() { + for _ = range sigchan { + cli.resizeTty(id, isExec) + } + }() + } return nil } |