From d1328e694e8738550f7aa6661ec245a61b8bc279 Mon Sep 17 00:00:00 2001 From: Martin Lund Date: Sun, 11 May 2025 07:11:07 +0200 Subject: [PATCH] Fix write in non-interactive piping mode So that piping does not break when write buffer is full because e.g. device has flow control enabled and can't keep up. --- src/tty.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tty.c b/src/tty.c index c5e6876..6bd6f91 100644 --- a/src/tty.c +++ b/src/tty.c @@ -2641,6 +2641,19 @@ int tty_connect(void) /* If stdin is a pipe forward all input to tty device */ if (interactive_mode == false) { + // Set blocking mode for serial device (blocking write) + int flags = fcntl(device_fd, F_GETFL, 0); + if (flags == -1) + { + tio_error_printf("Could not read descriptor flags (%s)", strerror(errno)); + exit(EXIT_FAILURE); + } + if (fcntl(device_fd, F_SETFL, flags & ~O_NONBLOCK) == -1) + { + tio_error_printf("Could not set descriptor flags (%s)", strerror(errno)); + exit(EXIT_FAILURE); + } + while (true) { int ret = read(pipefd[0], &input_char, 1);