diff options
author | Brad Pankow <brad@livio.io> | 2016-07-27 11:07:37 -0400 |
---|---|---|
committer | Brad Pankow <brad@livio.io> | 2016-07-27 13:43:07 -0400 |
commit | b01f3bafe6a74a21109355573328b2dd8c35a5b9 (patch) | |
tree | 3bade0a16351c0ecbbea7944c3ea12bf53d4847c | |
parent | f95d608893b6a537ec2e7e753a6b162f067c1c01 (diff) | |
download | sdl_core-b01f3bafe6a74a21109355573328b2dd8c35a5b9.tar.gz |
Change socket close logic to prevent double close (CID 137866)
This simplifies the logic used to connect to bluetooth sockets. It
prevents the rfcomm_socket from being closed twice or being left
unclosed.
-rw-r--r-- | src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc b/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc index 4240c9a3a4..4b092bcf50 100644 --- a/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc +++ b/src/components/transport_manager/src/bluetooth/bluetooth_socket_connection.cc @@ -103,14 +103,12 @@ bool BluetoothSocketConnection::Establish(ConnectError** error) { if (0 == connect_status) { LOG4CXX_DEBUG(logger_, "rfcomm Connect ok"); break; - } - if (errno != 111 && errno != 104) { - LOG4CXX_DEBUG(logger_, "rfcomm Connect errno " << errno); - break; - } - if (errno) { - LOG4CXX_DEBUG(logger_, "rfcomm Connect errno " << errno); - close(rfcomm_socket); + } else { // If connect_status is not 0, an errno is returned + LOG4CXX_WARN_WITH_ERRNO(logger_, "rfcomm Connect failed"); + close(rfcomm_socket); // Always close the socket upon error + if (errno != ECONNREFUSED && errno != ECONNRESET) { + break; + } } sleep(2); } while (--attempts > 0); @@ -120,7 +118,6 @@ bool BluetoothSocketConnection::Establish(ConnectError** error) { "Failed to Connect to remote device " << BluetoothDevice::GetUniqueDeviceId( remoteSocketAddress.rc_bdaddr) << " for session " << this); *error = new ConnectError(); - close(rfcomm_socket); LOG4CXX_TRACE(logger_, "exit with FALSE"); return false; } |