From 5d1e78befb7f15dac0a2e70d1f3940b958dee324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 13 Aug 2021 14:11:58 +0200 Subject: [PATCH] protocol_splitter: return correct FIONSPACE This is now possible since we don't parse the protocol. --- .../protocol_splitter/protocol_splitter.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/drivers/protocol_splitter/protocol_splitter.cpp b/src/drivers/protocol_splitter/protocol_splitter.cpp index 966f83c9a0..705342dff5 100644 --- a/src/drivers/protocol_splitter/protocol_splitter.cpp +++ b/src/drivers/protocol_splitter/protocol_splitter.cpp @@ -303,11 +303,19 @@ DevCommon::~DevCommon() int DevCommon::ioctl(struct file *filp, int cmd, unsigned long arg) { - // pretend we have enough space left to write, so mavlink will not drop data and throw off - // our parsing state if (cmd == FIONSPACE) { - *(int *)arg = 1024; - return 0; + int ret = ::ioctl(_fd, FIONSPACE, arg); + + if (ret == 0) { + int *buf_free = (int *)arg; + *buf_free -= sizeof(_header); + + if (*buf_free < 0) { + *buf_free = 0; + } + } + + return ret; } return ::ioctl(_fd, cmd, arg);