diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-12 17:37:04 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-08-12 17:37:04 +0000 |
commit | 2b184e2630f74fe4f568212de7e143a9bc3743b8 (patch) | |
tree | b8701e6c319c085758d39c4dd7d08c380fc2088a /apps/system | |
parent | 0512367a9c707f26b9a2b9057cf64714f46a0dc4 (diff) | |
download | px4-firmware-2b184e2630f74fe4f568212de7e143a9bc3743b8.tar.gz px4-firmware-2b184e2630f74fe4f568212de7e143a9bc3743b8.tar.bz2 px4-firmware-2b184e2630f74fe4f568212de7e143a9bc3743b8.zip |
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: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5022 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'apps/system')
-rw-r--r-- | apps/system/readline/readline.c | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/apps/system/readline/readline.c b/apps/system/readline/readline.c index f7fa6a635..bdd39e67b 100644 --- a/apps/system/readline/readline.c +++ b/apps/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) + /* Loop until we successfully read a character (or until an unexpected + * error occurs). + */ + + do { - /* Return EOF if the end of file (0) or error (-1) occurs */ + /* 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. + */ - return EOF; + 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 |