diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-11-16 06:48:46 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-11-16 06:48:46 -0600 |
commit | e5080c38b68ef5f127d055be1d44ae76f99eb33e (patch) | |
tree | 0b53495ac3fa28a49afd72ced9f9c13d370f8b9a /apps | |
parent | 71ab30001a1a3e2297e64ae1b65b8b01b8a3ab4f (diff) | |
download | nuttx-e5080c38b68ef5f127d055be1d44ae76f99eb33e.tar.gz nuttx-e5080c38b68ef5f127d055be1d44ae76f99eb33e.tar.bz2 nuttx-e5080c38b68ef5f127d055be1d44ae76f99eb33e.zip |
NSH USB Console: Add logic to restart the console wait if an error occurs while reading from the console. In USB console startup, the logic must be able to open the USB serial and receive 3 newlines. However, it the USB driver is disconnected or otherwise fails before the 3 newlines are received, the receive loop becomes a killer, infinite loop, CPU hog. Noted by spasbyspas
Diffstat (limited to 'apps')
-rw-r--r-- | apps/nshlib/nsh_usbconsole.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/apps/nshlib/nsh_usbconsole.c b/apps/nshlib/nsh_usbconsole.c index 800b36413..bcc2ef300 100644 --- a/apps/nshlib/nsh_usbconsole.c +++ b/apps/nshlib/nsh_usbconsole.c @@ -176,6 +176,8 @@ static int nsh_waitusbready(void) * host-side application opens the connection. */ +restart: + /* Open the USB serial device for read/write access */ do @@ -225,6 +227,17 @@ static int nsh_waitusbready(void) /* No.. Reset the count. We need to see 3 in a row to continue. */ nlc = 0; + + /* If a read error occurred (nbytes < 0) or an end-of-file was + * encountered (nbytes == 0), then close the driver and start + * over. + */ + + if (nbytes <= 0) + { + (void)close(fd); + goto restart; + } } } while (nlc < 3); |