From 4143fb4a39a2f4977daac1e42081808256871c32 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Fri, 9 Aug 2019 03:10:50 +0800 Subject: [PATCH] [posix-sim] implement UART flush (#4072) --- examples/platforms/posix/uart-posix.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/examples/platforms/posix/uart-posix.c b/examples/platforms/posix/uart-posix.c index af375dcae..04d32814a 100644 --- a/examples/platforms/posix/uart-posix.c +++ b/examples/platforms/posix/uart-posix.c @@ -224,7 +224,29 @@ void platformUartUpdateFdSet(fd_set *aReadFdSet, fd_set *aWriteFdSet, fd_set *aE otError otPlatUartFlush(void) { - return OT_ERROR_NOT_IMPLEMENTED; + otError error = OT_ERROR_NONE; + ssize_t count; + + otEXPECT_ACTION(s_write_buffer != NULL && s_write_length > 0, error = OT_ERROR_INVALID_STATE); + + while ((count = write(s_out_fd, s_write_buffer, s_write_length)) > 0 && (s_write_length -= count) > 0) + { + s_write_buffer += count; + } + + if (count != -1) + { + assert(s_write_length == 0); + s_write_buffer = NULL; + } + else + { + perror("write(UART)"); + exit(EXIT_FAILURE); + } + +exit: + return error; } void platformUartProcess(void)