Skip to content

Commit f6a6981

Browse files
arch/sim: set stdin/stdout nonblocking in host_uart_start()
When NuttX sim is connected via pipe (e.g. by an automation tool), if the host side does not read stdout in time, the pipe buffer fills up and write(1, ...) blocks the entire sim process. This happens inside host_uninterruptible (irq disabled), so the NuttX scheduler is completely frozen and all threads stop. Set both stdin and stdout to nonblocking via ioctl(FIONBIO) so that read()/write() return EAGAIN instead of blocking. The TX data stays in the NuttX xmit buffer and sim_tty_work retries every 1ms until the pipe has space. Signed-off-by: chenzihan1 <chenzihan1@xiaomi.com> Signed-off-by: ligd <liguangdi1@xiaomi.com> Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1 parent b939b11 commit f6a6981

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

arch/sim/src/sim/posix/sim_hostuart.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static void restoremode(void)
9595

9696
void host_uart_start(void)
9797
{
98+
int nonblock = 1;
99+
98100
/* Get the current stdin terminal mode */
99101

100102
tcgetattr(0, &g_cooked);
@@ -103,6 +105,14 @@ void host_uart_start(void)
103105

104106
setrawmode(0);
105107

108+
host_uninterruptible_no_return(ioctl, 0, FIONBIO, &nonblock);
109+
110+
/* Set stdout to non-blocking to prevent write(1, ...) from blocking
111+
* the entire sim process when the host pipe buffer is full.
112+
*/
113+
114+
host_uninterruptible_no_return(ioctl, 1, FIONBIO, &nonblock);
115+
106116
/* Restore the original terminal mode before exit */
107117

108118
atexit(restoremode);

0 commit comments

Comments
 (0)