Skip to content

Commit

Permalink
Wait for output to drain.
Browse files Browse the repository at this point in the history
Hopefully this fixes unpredicatable output when the program is stopping.
  • Loading branch information
gdamore committed Jun 10, 2021
1 parent 6582146 commit 7946eb8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion nonblock_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

// tcSetBufParams is used by the tty driver on UNIX systems to configure the
// 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 {
_ = syscall.SetNonblock(fd, true)
tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA)
Expand All @@ -34,7 +35,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
}
tio.Cc[unix.VMIN] = vMin
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 nil
Expand Down
3 changes: 2 additions & 1 deletion nonblock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// tcSetBufParams is used by the tty driver on UNIX systems to configure the
// 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 {
_ = syscall.SetNonblock(fd, true)
tio, err := unix.IoctlGetTermios(fd, unix.TCGETS)
Expand All @@ -32,7 +33,7 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error {
}
tio.Cc[unix.VMIN] = vMin
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 nil
Expand Down

0 comments on commit 7946eb8

Please sign in to comment.