From 162b7d637249c824ef5637bd41bd2b81caafe441 Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Thu, 11 Sep 2025 12:32:34 -0800 Subject: [PATCH] serial: nuttx: revert tcdrain back to fsync (#25538) * serial: nuttx: revert tcdrain back to fsync * serial: do not print error on EAGAIN --------- Co-authored-by: Alexander Lerach --- platforms/nuttx/src/px4/common/SerialImpl.cpp | 7 +++++-- platforms/posix/src/px4/common/SerialImpl.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/platforms/nuttx/src/px4/common/SerialImpl.cpp b/platforms/nuttx/src/px4/common/SerialImpl.cpp index 904d6124b1..076cd74d4e 100644 --- a/platforms/nuttx/src/px4/common/SerialImpl.cpp +++ b/platforms/nuttx/src/px4/common/SerialImpl.cpp @@ -339,12 +339,15 @@ ssize_t SerialImpl::write(const void *buffer, size_t buffer_size) } int written = ::write(_serial_fd, buffer, buffer_size); - tcdrain(_serial_fd); // Wait until all output is transmitted if (written < 0) { - PX4_ERR("%s write error %d", _port, written); + if (errno != EAGAIN) { + PX4_ERR("%s write error %d", _port, written); + } } + ::fsync(_serial_fd); + return written; } diff --git a/platforms/posix/src/px4/common/SerialImpl.cpp b/platforms/posix/src/px4/common/SerialImpl.cpp index 2298c38292..3afbfa9537 100644 --- a/platforms/posix/src/px4/common/SerialImpl.cpp +++ b/platforms/posix/src/px4/common/SerialImpl.cpp @@ -325,13 +325,15 @@ ssize_t SerialImpl::write(const void *buffer, size_t buffer_size) } int written = ::write(_serial_fd, buffer, buffer_size); - ::fsync(_serial_fd); if (written < 0) { - PX4_ERR("%s write error %d", _port, written); - + if (errno != EAGAIN) { + PX4_ERR("%s write error %d", _port, written); + } } + ::fsync(_serial_fd); + return written; }