Skip to content

Commit

Permalink
Clear input/output buffers on macOS upon TTY open
Browse files Browse the repository at this point in the history
I don't understand why this works, but it resolves problematic behavior
(#49) on macOS. Bisecting history, I found commit
3d6c1b2, which removed flushing the IO
buffers for a TTY, was problematic on macOS. However, the test
`test_osx_pty_pair` which tests pseudo-ttys with baud_rate 0 on macOS
(introduced in b54264b) fails if I
simply reintroduced flushing. Therefore, this change now re-introduces
flushing the IO buffers upon opening a TTY, but only on macOS and only
when baud-rate is non-zero.

Thanks to @berkus for the original work.
  • Loading branch information
astraw authored and eldruin committed Dec 8, 2023
1 parent 14ab9c9 commit 7be36cb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/posix/tty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ impl TTYPort {
));
};

#[cfg(any(target_os = "ios", target_os = "macos"))]
if builder.baud_rate > 0 {
unsafe { libc::tcflush(fd.0, libc::TCIOFLUSH) };
}

// clear O_NONBLOCK flag
fcntl(fd.0, F_SETFL(nix::fcntl::OFlag::empty()))?;

Expand Down

0 comments on commit 7be36cb

Please sign in to comment.