From f4328c12dec0dc613d4ff58f12b35892dedebd54 Mon Sep 17 00:00:00 2001 From: Wilco Waaijer Date: Sun, 28 Dec 2025 01:08:08 +0100 Subject: [PATCH] fix(hci): Check stop flag periodically, even without incoming data --- src/BluetoothHciSocket.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/BluetoothHciSocket.cpp b/src/BluetoothHciSocket.cpp index 1c0e69e..649160f 100644 --- a/src/BluetoothHciSocket.cpp +++ b/src/BluetoothHciSocket.cpp @@ -672,6 +672,17 @@ bool BluetoothHciSocket::EnsureSocket(const Napi::CallbackInfo& info) { this->EmitError(info, "socket creation failed"); return false; } + + struct timeval tv = {}; + + memset(&tv, 0, sizeof(tv)); + tv.tv_sec = 1; + tv.tv_usec = 0; + + // Allow the poll thread to check the stop flag periodically even when no data is incoming + if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) { + this->EmitError(info, "setsockopt failed for SO_RCVTIMEO"); + } this->_socket = fd; return true;