posix/uart: Fixes for failure to terminate (#568)

These changes address various issues found in the POSIX platform UART
driver which lead to the process not terminating properly when the
parent dies or closes `stdin`/`stdout`. Some of the errors could even
lead to unexpected program termination.

Among the various errors corrected are:

*   Using `assert()` to terminate under normal operating conditions.
*   `posixUartProcess()` only checked `s_in_fd` for readability and
    did not check `s_out_fd` for writability. It also caused data
    corruption if `write()` ever returned less than all of the bytes
    sent.
*   `ISIG` was being set on the termios flags. This can cause problems
    when the serial API is used for binary data (Like when used with
    the NCP app). (This requires the CLI be explicitly able to be able
    to handle CTRL-C when built for POSIX)
*   Socket errors weren't being tracked on `select()`.
*   The platform main loop would (possibly) terminate if `select()`
    failed with `EINTR`, which makes it difficult to attach to the
    process with a debugger.
This commit is contained in:
Robert Quattlebaum
2016-09-12 13:47:18 -07:00
committed by Jonathan Hui
parent 56f3239c44
commit 9b1de7bbb2
5 changed files with 129 additions and 36 deletions
+7
View File
@@ -98,6 +98,13 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength)
break;
#ifdef OPENTHREAD_EXAMPLES_POSIX
case 0x03: // ASCII for Ctrl-C
exit(EXIT_SUCCESS);
break;
#endif
case '\b':
case 127:
if (mRxLength > 0)