From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 1/2] hciemu: Fix silently dropping packet if writev return -EAGAIN
Date: Thu, 26 Feb 2026 15:03:29 -0500 [thread overview]
Message-ID: <20260226200330.313530-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The code has been silently dropping packets due to lack of buffer
since hciemu design is single threaded it cannot do partial writes
or flushes to force the buffer to be consumed and give space to the
next chunk, so in order to fix this the code will now attempt to
detect if a socket runs out of space and automatically bump the
buffer with use of SO_SNDBUF.
---
emulator/hciemu.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/emulator/hciemu.c b/emulator/hciemu.c
index 8c73a07eede0..01a8e80b727e 100644
--- a/emulator/hciemu.c
+++ b/emulator/hciemu.c
@@ -118,8 +118,35 @@ static void writev_callback(const struct iovec *iov, int iovlen,
fd = g_io_channel_unix_get_fd(channel);
written = writev(fd, iov, iovlen);
- if (written < 0)
- return;
+ if (written < 0) {
+ ssize_t ret;
+ int size, data_len;
+ socklen_t len = sizeof(size);
+ int i;
+
+ if (errno != EAGAIN)
+ return;
+
+ data_len = 0;
+
+ for (i = 0; i < iovlen; i++)
+ data_len += iov[i].iov_len;
+
+ /* Automatically bump the send buffer size if the data to be
+ * sent is larger than the current buffer size. This is needed
+ * for btdev which doesn't flush the socket buffer until all
+ * data has been sent.
+ */
+ ret = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, &len);
+ if (!ret) {
+ size += data_len;
+ setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, len);
+ }
+
+ written = writev(fd, iov, iovlen);
+ if (written < 0)
+ return;
+ }
}
static gboolean receive_bthost(GIOChannel *channel, GIOCondition condition,
--
2.52.0
next reply other threads:[~2026-02-26 20:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 20:03 Luiz Augusto von Dentz [this message]
2026-02-26 20:03 ` [PATCH BlueZ v2 2/2] bthost: Add segmentation support for L2CAP LE-(E)CRED mode Luiz Augusto von Dentz
2026-02-26 21:05 ` [BlueZ,v2,1/2] hciemu: Fix silently dropping packet if writev return -EAGAIN bluez.test.bot
2026-03-03 15:40 ` [PATCH BlueZ v2 1/2] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260226200330.313530-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox