зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1239979: Close sockets when deinitializing Bluetooth profile managers, r=btian
This commit is contained in:
Родитель
3db34e3133
Коммит
a88bdd194f
|
@ -130,6 +130,24 @@ BluetoothMapSmsManager::Init()
|
|||
void
|
||||
BluetoothMapSmsManager::Uninit()
|
||||
{
|
||||
if (mMasServerSocket) {
|
||||
mMasServerSocket->SetObserver(nullptr);
|
||||
|
||||
if (mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mMasServerSocket->Close();
|
||||
}
|
||||
mMasServerSocket = nullptr;
|
||||
}
|
||||
|
||||
if (mMasSocket) {
|
||||
mMasSocket->SetObserver(nullptr);
|
||||
|
||||
if (mMasSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mMasSocket->Close();
|
||||
}
|
||||
mMasSocket = nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (NS_WARN_IF(!obs)) {
|
||||
return;
|
||||
|
@ -208,10 +226,11 @@ BluetoothMapSmsManager::Listen()
|
|||
* BT stops; otherwise no more read events would be received even if
|
||||
* BT restarts.
|
||||
*/
|
||||
if (mMasServerSocket) {
|
||||
if (mMasServerSocket &&
|
||||
mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mMasServerSocket->Close();
|
||||
mMasServerSocket = nullptr;
|
||||
}
|
||||
mMasServerSocket = nullptr;
|
||||
|
||||
mMasServerSocket = new BluetoothSocket(this);
|
||||
|
||||
|
@ -1543,7 +1562,17 @@ BluetoothMapSmsManager::OnSocketConnectError(BluetoothSocket* aSocket)
|
|||
}
|
||||
|
||||
// MAS socket connection error
|
||||
|
||||
if (mMasServerSocket &&
|
||||
mMasServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mMasServerSocket->Close();
|
||||
}
|
||||
mMasServerSocket = nullptr;
|
||||
|
||||
if (mMasSocket &&
|
||||
mMasSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mMasSocket->Close();
|
||||
}
|
||||
mMasSocket = nullptr;
|
||||
}
|
||||
|
||||
|
@ -1574,6 +1603,7 @@ BluetoothMapSmsManager::OnSocketDisconnect(BluetoothSocket* aSocket)
|
|||
// MAS socket is disconnected
|
||||
AfterMapSmsDisconnected();
|
||||
mDeviceAddress.Clear();
|
||||
|
||||
mMasSocket = nullptr;
|
||||
|
||||
Listen();
|
||||
|
|
|
@ -249,6 +249,24 @@ BluetoothOppManager::Init()
|
|||
void
|
||||
BluetoothOppManager::Uninit()
|
||||
{
|
||||
if (mServerSocket) {
|
||||
mServerSocket->SetObserver(nullptr);
|
||||
|
||||
if (mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
}
|
||||
|
||||
if (mSocket) {
|
||||
mSocket->SetObserver(nullptr);
|
||||
|
||||
if (mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mSocket->Close();
|
||||
}
|
||||
mSocket = nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
NS_ENSURE_TRUE_VOID(obs);
|
||||
|
||||
|
@ -317,10 +335,11 @@ BluetoothOppManager::ConnectInternal(const BluetoothAddress& aDeviceAddress)
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Stop listening because currently we only support one connection at a time.
|
||||
if (mServerSocket) {
|
||||
if (mServerSocket &&
|
||||
mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
mServerSocket = nullptr;
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
|
||||
mIsServer = false;
|
||||
|
||||
|
@ -394,10 +413,11 @@ BluetoothOppManager::Listen()
|
|||
* BT stops; otherwise no more read events would be received even if
|
||||
* BT restarts.
|
||||
*/
|
||||
if (mServerSocket) {
|
||||
if (mServerSocket &&
|
||||
mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
mServerSocket = nullptr;
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
|
||||
mServerSocket = new BluetoothSocket(this);
|
||||
|
||||
|
@ -1564,7 +1584,16 @@ BluetoothOppManager::OnSocketConnectError(BluetoothSocket* aSocket)
|
|||
{
|
||||
BT_LOGR("[%s]", (mIsServer)? "server" : "client");
|
||||
|
||||
if (mServerSocket &&
|
||||
mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
|
||||
if (mSocket &&
|
||||
mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mSocket->Close();
|
||||
}
|
||||
mSocket = nullptr;
|
||||
|
||||
if (!mIsServer) {
|
||||
|
@ -1614,7 +1643,8 @@ BluetoothOppManager::OnSocketDisconnect(BluetoothSocket* aSocket)
|
|||
mDeviceAddress.Clear();
|
||||
mSuccessFlag = false;
|
||||
|
||||
mSocket = nullptr;
|
||||
mSocket = nullptr; // should already be closed
|
||||
|
||||
// Listen as a server if there's no more batch to process
|
||||
if (!ProcessNextBatch()) {
|
||||
Listen();
|
||||
|
|
|
@ -137,6 +137,24 @@ BluetoothPbapManager::Init()
|
|||
void
|
||||
BluetoothPbapManager::Uninit()
|
||||
{
|
||||
if (mServerSocket) {
|
||||
mServerSocket->SetObserver(nullptr);
|
||||
|
||||
if (mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
}
|
||||
|
||||
if (mSocket) {
|
||||
mSocket->SetObserver(nullptr);
|
||||
|
||||
if (mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mSocket->Close();
|
||||
}
|
||||
mSocket = nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||
if (NS_WARN_IF(!obs)) {
|
||||
return;
|
||||
|
@ -214,10 +232,11 @@ BluetoothPbapManager::Listen()
|
|||
* BT stops; otherwise no more read events would be received even if
|
||||
* BT restarts.
|
||||
*/
|
||||
if (mServerSocket) {
|
||||
if (mServerSocket &&
|
||||
mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
mServerSocket = nullptr;
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
|
||||
mServerSocket = new BluetoothSocket(this);
|
||||
|
||||
|
@ -1164,7 +1183,16 @@ BluetoothPbapManager::OnSocketConnectSuccess(BluetoothSocket* aSocket)
|
|||
void
|
||||
BluetoothPbapManager::OnSocketConnectError(BluetoothSocket* aSocket)
|
||||
{
|
||||
if (mServerSocket &&
|
||||
mServerSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mServerSocket->Close();
|
||||
}
|
||||
mServerSocket = nullptr;
|
||||
|
||||
if (mSocket &&
|
||||
mSocket->GetConnectionStatus() != SOCKET_DISCONNECTED) {
|
||||
mSocket->Close();
|
||||
}
|
||||
mSocket = nullptr;
|
||||
}
|
||||
|
||||
|
@ -1180,7 +1208,8 @@ BluetoothPbapManager::OnSocketDisconnect(BluetoothSocket* aSocket)
|
|||
|
||||
AfterPbapDisconnected();
|
||||
mDeviceAddress.Clear();
|
||||
mSocket = nullptr;
|
||||
|
||||
mSocket = nullptr; // should already be closed
|
||||
|
||||
Listen();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче