macOS Bluetooth: report RemoteHostClosed error when the RFCOMM channel is closed

The ChannelDelegate::channelClosed() virtual method is called in two
cases:
* when an attempt to open the channel failed (because of the timeout
  or an error in rfcommChannelOpenComplete() callbalk).
* when the rfcommChannelClosed() callback is triggered. This happens
  only when the remote host closes the connection.

In the first case we set UnknownSocketError. Keep this behavior.

In the second case no error was reported, which is different from how
other backends behave. This patch updates the code to set the
RemoteHostClosed error if the channelClosed() is called, and the
socket was in Connected state.

Task-number: QTBUG-123430
Pick-to: 6.8 6.7 6.5
Change-Id: Ie21a2e66b570a32b1c4401305738515bc6d04f85
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
Ivan Solovev 2024-08-23 16:00:18 +02:00
parent 05b8398aa6
commit c382034457
1 changed files with 2 additions and 0 deletions

View File

@ -497,6 +497,8 @@ void QBluetoothSocketPrivateDarwin::channelClosed()
// (thus close/abort probably will not work).
if (!isConnecting) {
if (state == QBluetoothSocket::SocketState::ConnectedState)
q_ptr->setSocketError(QBluetoothSocket::SocketError::RemoteHostClosedError);
q_ptr->setOpenMode(QIODevice::NotOpen);
q_ptr->setSocketState(QBluetoothSocket::SocketState::UnconnectedState);
emit q_ptr->readChannelFinished();