From 6f96987e3eba7c8b2bc7f53d078bbf9c1d960c9f Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Tue, 10 Sep 2024 18:20:25 +0300 Subject: [PATCH] cyphal socketcan driver: treat EAGAIN as a timeout instead of an error to retry sending later --- src/drivers/cyphal/CanardSocketCAN.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/drivers/cyphal/CanardSocketCAN.cpp b/src/drivers/cyphal/CanardSocketCAN.cpp index 9b1e3217bbf0..8ccdeca0f4bb 100644 --- a/src/drivers/cyphal/CanardSocketCAN.cpp +++ b/src/drivers/cyphal/CanardSocketCAN.cpp @@ -177,7 +177,15 @@ int16_t CanardSocketCAN::transmit(const CanardTxQueueItem &txf, int timeout_ms) #ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE return sendmsg(_fd, &_send_msg, 0); #else - return sendmsg(_fd, &_send_msg, MSG_DONTWAIT); + /* Use non-blocking calls for devices that don't implement TX deadline*/ + auto res = sendmsg(_fd, &_send_msg, MSG_DONTWAIT); + + /* Treat EAGAIN as a timeout instead of an error. Return 0, so CanardHandle will send the frame again later. */ + if (res < 0 && errno == EAGAIN) { + return 0; + } + + return res; #endif }