From 0fdfc2e1ff5a395fc68c3f8b0b26886dfc7741b5 Mon Sep 17 00:00:00 2001 From: Nicolas Dusart Date: Wed, 23 Oct 2024 15:14:03 +0200 Subject: [PATCH] handle EINTR return code from tcdrain to effectively block until flush is complete --- src/posix/tty.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/posix/tty.rs b/src/posix/tty.rs index fe7e8499..41131fc2 100644 --- a/src/posix/tty.rs +++ b/src/posix/tty.rs @@ -441,8 +441,13 @@ impl io::Write for TTYPort { } fn flush(&mut self) -> io::Result<()> { - nix::sys::termios::tcdrain(self.fd) - .map_err(|_| io::Error::new(io::ErrorKind::Other, "flush failed")) + loop { + return match nix::sys::termios::tcdrain(self.fd) { + Ok(_) => Ok(()), + Err(nix::errno::Errno::EINTR) => continue, + Err(_) => Err(io::Error::new(io::ErrorKind::Other, "flush failed")), + }; + } } }