macOS Bluetooth: use a timer when opening RFCOMM channel


An attempt to open an RFCOMM channel should trigger an
rfcommChannelOpenComplete() callback which has an error status.
This happens correctly if the channel is opened successfully (the error
is kIOReturnSuccess in this case).
However, when the remote device is turned off, the attempt to open an
RFCOMM channel never triggers any callback, so the socket simply
hangs in the Connecting state.
Fix it by explicitly using a connection timer. The timer timeout is
picked more or less randomly, but 5s looks like a reasonable time,
because at this point we are simply trying to connect to a known
service. No discovery is needed.

As a drive-by: update the error handling code path in
rfcommChannelOpenComplete() to also signal that the channel is closed.
Otherwise the socket will report an error, but keep hanging in the
Connecting state. This code path is never executed now, but it might
be fixed in later macOS releases.

Task-number: QTBUG-123430
Pick-to: 6.8 6.7 6.5
Change-Id: I187a0b2e293462c6e9b7e5e3afee2e6ddf4d2ab1
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
commit05b8398aa6f1a6e109d92da6a2d6a8b2d9b0e47f
parent90e592dfdc58300257941f6c27fe2776b87b41cb
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeMon, 26 Aug 2024 15:31:43 +0200