From 19580c73bfb1acb3b0cded07a82d5fe6870443bf Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 12 Aug 2012 17:37:04 +0000 Subject: [PATCH] drivers/serial/serial.c open, read, write, and poll methods will not return a short transfer or an EINTR error if a signal is received while waiting (only) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5022 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog.txt | 2 ++ system/readline/readline.c | 52 +++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 1bb2a08b5..37d05bacd 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -274,3 +274,5 @@ no arguments outputs a short list of commands. With -v lists all command line details. And command name can be added to just get help on one command. + * system/readline.c: If character input/output is interrupted by a + signal, then readline() will try the read/write again. diff --git a/system/readline/readline.c b/system/readline/readline.c index f7fa6a635..bdd39e67b 100644 --- a/system/readline/readline.c +++ b/system/readline/readline.c @@ -103,13 +103,34 @@ static inline int readline_rawgetc(int infd) char buffer; ssize_t nread; - nread = read(infd, &buffer, 1); - if (nread < 1) - { - /* Return EOF if the end of file (0) or error (-1) occurs */ + /* Loop until we successfully read a character (or until an unexpected + * error occurs). + */ - return EOF; + do + { + /* Read one character from the incoming stream */ + + nread = read(infd, &buffer, 1); + + /* Return EOF if the end of file (0) or error (-1) occurs. */ + + if (nread < 1) + { + /* EINTR is not really an error; it simply means that a signal we + * received while watiing for intput. + */ + + if (nread == 0 || errno != EINTR) + { + return EOF; + } + } } + while (nread < 1); + + /* On success, returnt he character that was read */ + return (int)buffer; } @@ -121,7 +142,26 @@ static inline int readline_rawgetc(int infd) static inline void readline_consoleputc(int ch, int outfd) { char buffer = ch; - (void)write(outfd, &buffer, 1); + ssize_t nwritten; + + /* Loop until we successfully write a character (or until an unexpected + * error occurs). + */ + + do + { + /* Write the character to the outgoing stream */ + + nwritten = write(outfd, &buffer, 1); + + /* Check for irrecoverable write errors. */ + + if (nwritten < 0 && errno != EINTR) + { + break; + } + } + while (nwritten < 1); } #endif