From 8755a1f2460fa523782e27b6ca7a430a0176ac61 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Mon, 18 Jul 2016 13:56:14 +0200 Subject: Highlight incomplete handling of BTLE packet writes Cases such as partial writes were silently ignored. Since QLowEnergyController works in unbuffered mode such incomplete writes are ignored. The ATT layer will automatically recover from such packets on the line. The EAGAIN case is a similar case as it effectively means the BTLE connection is still ok but the packet can temporarily not be written anyway. In fact, previously QBluetoothSocket reported such cases by returning -1 as a result of QBLuetoothSocket::write(). This was even worse as it caused a drop of the connection without justification. These issues are reproducable when the BTLE connection is flooded with lots of notifications. Task-number: QTBUG-54475 Change-Id: I2b6be555ff676c440971981db0974be83c901eaa Reviewed-by: Christian Kandeler --- src/bluetooth/qlowenergycontroller_bluez.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/bluetooth/qlowenergycontroller_bluez.cpp') diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index d4fe0232..e85fcb34 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -688,12 +688,19 @@ void QLowEnergyControllerPrivate::sendPacket(const QByteArray &packet) { qint64 result = l2cpSocket->write(packet.constData(), packet.size()); + // We ignore result == 0 which is likely to be caused by EAGAIN. + // This packet is effectively discarded but the controller can still recover + if (result == -1) { qCDebug(QT_BT_BLUEZ) << "Cannot write L2CP packet:" << hex << packet.toHex() << l2cpSocket->errorString(); setError(QLowEnergyController::NetworkError); + } else if (result < packet.size()) { + qCWarning(QT_BT_BLUEZ) << "L2CP write request incomplete:" + << result << "of" << packet.size(); } + } void QLowEnergyControllerPrivate::sendNextPendingRequest() -- cgit v1.2.3