Wait for output to drain.

Hopefully this fixes unpredicatable output when the program is stopping.
This commit is contained in:
Garrett D'Amore 2021-06-10 07:33:55 -07:00
parent 65821462b5
commit 7946eb8e8d
2 changed files with 4 additions and 2 deletions

View File

@ -26,6 +26,7 @@ import (
// tcSetBufParams is used by the tty driver on UNIX systems to configure the // tcSetBufParams is used by the tty driver on UNIX systems to configure the
// buffering parameters (minimum character count and minimum wait time in msec.) // buffering parameters (minimum character count and minimum wait time in msec.)
// This also waits for output to drain first.
func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
_ = syscall.SetNonblock(fd, true) _ = syscall.SetNonblock(fd, true)
tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA) tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA)
@ -34,7 +35,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
} }
tio.Cc[unix.VMIN] = vMin tio.Cc[unix.VMIN] = vMin
tio.Cc[unix.VTIME] = vTime tio.Cc[unix.VTIME] = vTime
if err = unix.IoctlSetTermios(fd, unix.TIOCSETA, tio); err != nil { if err = unix.IoctlSetTermios(fd, unix.TIOCSETAW, tio); err != nil {
return err return err
} }
return nil return nil

View File

@ -24,6 +24,7 @@ import (
// tcSetBufParams is used by the tty driver on UNIX systems to configure the // tcSetBufParams is used by the tty driver on UNIX systems to configure the
// buffering parameters (minimum character count and minimum wait time in msec.) // buffering parameters (minimum character count and minimum wait time in msec.)
// This also waits for output to drain first.
func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
_ = syscall.SetNonblock(fd, true) _ = syscall.SetNonblock(fd, true)
tio, err := unix.IoctlGetTermios(fd, unix.TCGETS) tio, err := unix.IoctlGetTermios(fd, unix.TCGETS)
@ -32,7 +33,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
} }
tio.Cc[unix.VMIN] = vMin tio.Cc[unix.VMIN] = vMin
tio.Cc[unix.VTIME] = vTime tio.Cc[unix.VTIME] = vTime
if err = unix.IoctlSetTermios(fd, unix.TCSETS, tio); err != nil { if err = unix.IoctlSetTermios(fd, unix.TCSETSW, tio); err != nil {
return err return err
} }
return nil return nil