author | Thomas Zimmermann <tdz@users.sourceforge.net> |
Mon, 01 Jun 2015 10:42:29 +0200 | |
changeset 246490 | 37c9f1961a9d6b34f8cfd84e7eb821286ab95d3a |
parent 246489 | b8289e7701c97585ae29afca904fa8e083f6917e |
child 246491 | ae55eb4ad6967ab2f9b09a53ad3f3b75d39a1145 |
push id | 28833 |
push user | kwierso@gmail.com |
push date | Mon, 01 Jun 2015 19:19:37 +0000 |
treeherder | mozilla-central@a2d68ee6628c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | shuang |
bugs | 1168446 |
milestone | 41.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp @@ -289,19 +289,20 @@ BluetoothOppManager::ConnectInternal(con mIsServer = false; BluetoothService* bs = BluetoothService::Get(); if (!bs || sInShutdown || mSocket) { OnSocketConnectError(mSocket); return; } - mSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, false, true); - mSocket->ConnectSocket(aDeviceAddress, kObexObjectPush, -1); + mSocket = new BluetoothSocket(this); + mSocket->Connect(aDeviceAddress, kObexObjectPush, + BluetoothSocketType::RFCOMM, -1, + false, true); } void BluetoothOppManager::HandleShutdown() { MOZ_ASSERT(NS_IsMainThread()); sInShutdown = true; Disconnect(nullptr); @@ -351,22 +352,24 @@ BluetoothOppManager::Listen() * BT stops; otherwise no more read events would be received even if * BT restarts. */ if (mServerSocket) { mServerSocket->Close(); mServerSocket = nullptr; } - mServerSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, false, true); + mServerSocket = new BluetoothSocket(this); - if (!mServerSocket->ListenSocket(NS_LITERAL_STRING("OBEX Object Push"), - kObexObjectPush, - BluetoothReservedChannels::CHANNEL_OPUSH)) { + nsresult rv = mServerSocket->Listen(NS_LITERAL_STRING("OBEX Object Push"), + kObexObjectPush, + BluetoothSocketType::RFCOMM, + BluetoothReservedChannels::CHANNEL_OPUSH, + false, true); + if (NS_FAILED(rv)) { BT_WARNING("[OPP] Can't listen on RFCOMM socket!"); mServerSocket = nullptr; return false; } mIsServer = true; return true;
--- a/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothPbapManager.cpp @@ -156,23 +156,25 @@ BluetoothPbapManager::Listen() * BT stops; otherwise no more read events would be received even if * BT restarts. */ if (mServerSocket) { mServerSocket->Close(); mServerSocket = nullptr; } - mServerSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, false, true); + mServerSocket = new BluetoothSocket(this); - if (NS_WARN_IF(!mServerSocket->ListenSocket( - NS_LITERAL_STRING("OBEX Phonebook Access Server"), - kPbapPSE, - BluetoothReservedChannels::CHANNEL_PBAP_PSE))) { + nsresult rv = mServerSocket->Listen( + NS_LITERAL_STRING("OBEX Phonebook Access Server"), + kPbapPSE, + BluetoothSocketType::RFCOMM, + BluetoothReservedChannels::CHANNEL_PBAP_PSE, false, true); + + if (NS_FAILED(rv)) { mServerSocket = nullptr; return false; } BT_LOGR("PBAP socket is listening"); return true; }
--- a/dom/bluetooth/bluedroid/BluetoothSocket.cpp +++ b/dom/bluetooth/bluedroid/BluetoothSocket.cpp @@ -574,25 +574,20 @@ DroidSocketImpl::DiscardBuffer() { // Nothing to do. } // // |BluetoothSocket| // -BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver, - BluetoothSocketType aType, - bool aAuth, - bool aEncrypt) +BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver) : mObserver(aObserver) , mCurrentRes(nullptr) , mImpl(nullptr) - , mAuth(aAuth) - , mEncrypt(aEncrypt) { MOZ_ASSERT(aObserver); EnsureBluetoothSocketHalLoad(); mDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE); } class ConnectSocketResultHandler final : public BluetoothSocketResultHandler @@ -637,38 +632,39 @@ public: mImpl->mConsumer->NotifyDisconnect(); } } private: DroidSocketImpl* mImpl; }; -bool -BluetoothSocket::ConnectSocket(const nsAString& aDeviceAddress, - const BluetoothUuid& aServiceUuid, - int aChannel) +nsresult +BluetoothSocket::Connect(const nsAString& aDeviceAddress, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt) { MOZ_ASSERT(NS_IsMainThread()); - NS_ENSURE_FALSE(mImpl, false); + MOZ_ASSERT(!mImpl); SetConnectionStatus(SOCKET_CONNECTING); mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this); BluetoothSocketResultHandler* res = new ConnectSocketResultHandler(mImpl); SetCurrentResultHandler(res); sBluetoothSocketInterface->Connect( - aDeviceAddress, - BluetoothSocketType::RFCOMM, + aDeviceAddress, aType, aServiceUuid.mUuid, aChannel, - mEncrypt, mAuth, res); + aEncrypt, aAuth, res); - return true; + return NS_OK; } class ListenResultHandler final : public BluetoothSocketResultHandler { public: ListenResultHandler(DroidSocketImpl* aImpl) : mImpl(aImpl) { @@ -689,37 +685,39 @@ public: BT_WARNING("Listen failed: %d", (int)aStatus); } private: DroidSocketImpl* mImpl; }; -bool -BluetoothSocket::ListenSocket(const nsAString& aServiceName, - const BluetoothUuid& aServiceUuid, - int aChannel) +nsresult +BluetoothSocket::Listen(const nsAString& aServiceName, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt) { MOZ_ASSERT(NS_IsMainThread()); - NS_ENSURE_FALSE(mImpl, false); + MOZ_ASSERT(!mImpl); SetConnectionStatus(SOCKET_LISTENING); mImpl = new DroidSocketImpl(XRE_GetIOMessageLoop(), this); BluetoothSocketResultHandler* res = new ListenResultHandler(mImpl); SetCurrentResultHandler(res); sBluetoothSocketInterface->Listen( - BluetoothSocketType::RFCOMM, + aType, aServiceName, aServiceUuid.mUuid, aChannel, - mEncrypt, mAuth, res); + aEncrypt, aAuth, res); - return true; + return NS_OK; } void BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mObserver);
--- a/dom/bluetooth/bluedroid/BluetoothSocket.h +++ b/dom/bluetooth/bluedroid/BluetoothSocket.h @@ -14,28 +14,29 @@ BEGIN_BLUETOOTH_NAMESPACE class BluetoothSocketObserver; class BluetoothSocketResultHandler; class DroidSocketImpl; class BluetoothSocket final : public mozilla::ipc::DataSocket { public: - BluetoothSocket(BluetoothSocketObserver* aObserver, - BluetoothSocketType aType, - bool aAuth, - bool aEncrypt); + BluetoothSocket(BluetoothSocketObserver* aObserver); - bool ConnectSocket(const nsAString& aDeviceAddress, - const BluetoothUuid& aServiceUuid, - int aChannel); + nsresult Connect(const nsAString& aDeviceAddress, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt); - bool ListenSocket(const nsAString& aServiceName, - const BluetoothUuid& aServiceUuid, - int aChannel); + nsresult Listen(const nsAString& aServiceName, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt); /** * Method to be called whenever data is received. This is only called on the * main thread. * * @param aBuffer Data received from the socket. */ void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer); @@ -69,15 +70,13 @@ public: void OnConnectError() override; void OnDisconnect() override; private: BluetoothSocketObserver* mObserver; BluetoothSocketResultHandler* mCurrentRes; DroidSocketImpl* mImpl; nsString mDeviceAddress; - bool mAuth; - bool mEncrypt; }; END_BLUETOOTH_NAMESPACE #endif
--- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -478,20 +478,17 @@ BluetoothHfpManager::Init() NS_ENSURE_SUCCESS(rv, false); nsRefPtr<GetVolumeTask> callback = new GetVolumeTask(); rv = settingsLock->Get(AUDIO_VOLUME_BT_SCO_ID, callback); NS_ENSURE_SUCCESS(rv, false); Listen(); - mScoSocket = new BluetoothSocket(this, - BluetoothSocketType::SCO, - true, - false); + mScoSocket = new BluetoothSocket(this); mScoSocketStatus = mScoSocket->GetConnectionStatus(); ListenSco(); return true; } BluetoothHfpManager::~BluetoothHfpManager() { #ifdef MOZ_B2G_RIL @@ -1155,18 +1152,17 @@ BluetoothHfpManager::Connect(const nsASt } if (mHeadsetSocket) { mHeadsetSocket->Close(); mHeadsetSocket = nullptr; } mController = aController; - mSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true); + mSocket = new BluetoothSocket(this); } bool BluetoothHfpManager::Listen() { MOZ_ASSERT(NS_IsMainThread()); if (sInShutdown) { @@ -1175,37 +1171,43 @@ BluetoothHfpManager::Listen() } if (mSocket) { BT_WARNING("mSocket exists. Failed to listen."); return false; } if (!mHandsfreeSocket) { - mHandsfreeSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true); + mHandsfreeSocket = new BluetoothSocket(this); - if (!mHandsfreeSocket->Listen( - NS_LITERAL_STRING("Handsfree Audio Gateway"), - kHandsfreeAG, - BluetoothReservedChannels::CHANNEL_HANDSFREE_AG)) { + nsresult rv = mHandsfreeSocket->Listen( + NS_LITERAL_STRING("Handsfree Audio Gateway"), + kHandsfreeAG, + BluetoothSocketType::RFCOMM, + BluetoothReservedChannels::CHANNEL_HANDSFREE_AG, + true, true); + + if (NS_FAILED(rv)) { BT_WARNING("[HFP] Can't listen on RFCOMM socket!"); mHandsfreeSocket = nullptr; return false; } } if (!mHeadsetSocket) { - mHeadsetSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true); + mHeadsetSocket = new BluetoothSocket(this); - if (!mHeadsetSocket->Listen( - NS_LITERAL_STRING("Headset Audio Gateway"), - kHeadsetAG, - BluetoothReservedChannels::CHANNEL_HEADSET_AG)) { + nsresult rv = mHeadsetSocket->Listen( + NS_LITERAL_STRING("Headset Audio Gateway"), + kHeadsetAG, + BluetoothSocketType::RFCOMM, + BluetoothReservedChannels::CHANNEL_HEADSET_AG, + true, true); + + if (NS_FAILED(rv)) { BT_WARNING("[HSP] Can't listen on RFCOMM socket!"); mHandsfreeSocket->Close(); mHandsfreeSocket = nullptr; mHeadsetSocket = nullptr; return false; } } @@ -1899,19 +1901,22 @@ BluetoothHfpManager::OnGetServiceChannel mIsHsp = true; } return; } MOZ_ASSERT(mSocket); - if (!mSocket->Connect(aDeviceAddress, - mIsHsp? kHeadsetAG : kHandsfreeAG, - aChannel)) { + nsresult rv = mSocket->Connect(aDeviceAddress, + mIsHsp? kHeadsetAG : kHandsfreeAG, + BluetoothSocketType::RFCOMM, + aChannel, + true, true); + if (NS_FAILED(rv)) { OnConnect(NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); } } void BluetoothHfpManager::OnScoConnectSuccess() { // For active connection request, we need to reply the DOMRequest @@ -1987,17 +1992,19 @@ BluetoothHfpManager::ConnectSco(Bluetoot mConnectScoRequest = true; BT_WARNING("ConnectSco called before Service Level Connection established"); return false; } // Stop listening mScoSocket->Close(); - mScoSocket->Connect(mDeviceAddress, kUnknownService, -1); + mScoSocket->Connect(mDeviceAddress, kUnknownService, + BluetoothSocketType::SCO, + -1, true, false); mScoSocketStatus = mScoSocket->GetConnectionStatus(); mScoRunnable = aRunnable; return true; } bool BluetoothHfpManager::DisconnectSco() @@ -2024,18 +2031,23 @@ BluetoothHfpManager::ListenSco() if (mScoSocket->GetConnectionStatus() == SocketConnectionStatus::SOCKET_LISTENING) { BT_WARNING("SCO socket has been already listening"); return false; } mScoSocket->Close(); - if (!mScoSocket->Listen(NS_LITERAL_STRING("Handsfree Audio Gateway SCO"), - kUnknownService, -1)) { + nsresult rv = mScoSocket->Listen( + NS_LITERAL_STRING("Handsfree Audio Gateway SCO"), + kUnknownService, + BluetoothSocketType::SCO, + -1, true, false); + + if (NS_FAILED(rv)) { BT_WARNING("Can't listen on SCO socket!"); return false; } mScoSocketStatus = mScoSocket->GetConnectionStatus(); return true; }
--- a/dom/bluetooth/bluez/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluez/BluetoothOppManager.cpp @@ -188,35 +188,37 @@ public: mSocket->Close(); } } private: nsRefPtr<BluetoothSocket> mSocket; }; -BluetoothOppManager::BluetoothOppManager() : mConnected(false) - , mRemoteObexVersion(0) - , mRemoteConnectionFlags(0) - , mRemoteMaxPacketLength(0) - , mLastCommand(0) - , mPacketLength(0) - , mPutPacketReceivedLength(0) - , mBodySegmentLength(0) - , mAbortFlag(false) - , mNewFileFlag(false) - , mPutFinalFlag(false) - , mSendTransferCompleteFlag(false) - , mSuccessFlag(false) - , mIsServer(true) - , mWaitingForConfirmationFlag(false) - , mFileLength(0) - , mSentFileLength(0) - , mWaitingToSendPutFinal(false) - , mCurrentBlobIndex(-1) +BluetoothOppManager::BluetoothOppManager() + : mConnected(false) + , mRemoteObexVersion(0) + , mRemoteConnectionFlags(0) + , mRemoteMaxPacketLength(0) + , mLastCommand(0) + , mPacketLength(0) + , mPutPacketReceivedLength(0) + , mBodySegmentLength(0) + , mAbortFlag(false) + , mNewFileFlag(false) + , mPutFinalFlag(false) + , mSendTransferCompleteFlag(false) + , mSuccessFlag(false) + , mIsServer(true) + , mWaitingForConfirmationFlag(false) + , mFileLength(0) + , mSentFileLength(0) + , mWaitingToSendPutFinal(false) + , mCurrentBlobIndex(-1) + , mSocketType(static_cast<BluetoothSocketType>(0)) { mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE); } BluetoothOppManager::~BluetoothOppManager() { nsCOMPtr<nsIObserverService> obs = services::GetObserverService(); NS_ENSURE_TRUE_VOID(obs); @@ -291,18 +293,18 @@ BluetoothOppManager::ConnectInternal(con nsString uuid; BluetoothUuidHelper::GetString(BluetoothServiceClass::OBJECT_PUSH, uuid); if (NS_FAILED(bs->GetServiceChannel(aDeviceAddress, uuid, this))) { OnSocketConnectError(mSocket); return; } - mSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true); + mSocket = new BluetoothSocket(this); + mSocketType = BluetoothSocketType::RFCOMM; } void BluetoothOppManager::HandleShutdown() { MOZ_ASSERT(NS_IsMainThread()); sInShutdown = true; Disconnect(nullptr); @@ -315,35 +317,43 @@ BluetoothOppManager::Listen() MOZ_ASSERT(NS_IsMainThread()); if (mSocket) { BT_WARNING("mSocket exists. Failed to listen."); return false; } if (!mRfcommSocket) { - mRfcommSocket = - new BluetoothSocket(this, BluetoothSocketType::RFCOMM, true, true); + mRfcommSocket = new BluetoothSocket(this); - if (!mRfcommSocket->Listen(NS_LITERAL_STRING("OBEX Object Push"), - kObexObjectPush, - BluetoothReservedChannels::CHANNEL_OPUSH)) { + nsresult rv = mRfcommSocket->Listen( + NS_LITERAL_STRING("OBEX Object Push"), + kObexObjectPush, + BluetoothSocketType::RFCOMM, + BluetoothReservedChannels::CHANNEL_OPUSH, + true, true); + + if (NS_FAILED(rv)) { BT_WARNING("[OPP] Can't listen on RFCOMM socket!"); mRfcommSocket = nullptr; return false; } } if (!mL2capSocket) { - mL2capSocket = - new BluetoothSocket(this, BluetoothSocketType::EL2CAP, true, true); + mL2capSocket = new BluetoothSocket(this); - if (!mL2capSocket->Listen(NS_LITERAL_STRING("OBEX Object Push"), - kObexObjectPush, - BluetoothReservedChannels::CHANNEL_OPUSH_L2CAP)) { + nsresult rv = mL2capSocket->Listen( + NS_LITERAL_STRING("OBEX Object Push"), + kObexObjectPush, + BluetoothSocketType::EL2CAP, + BluetoothReservedChannels::CHANNEL_OPUSH_L2CAP, + true, true); + + if (NS_FAILED(rv)) { BT_WARNING("[OPP] Can't listen on L2CAP socket!"); mRfcommSocket->Close(); mRfcommSocket = nullptr; mL2capSocket = nullptr; return false; } } @@ -1527,22 +1537,24 @@ BluetoothOppManager::OnSocketConnectSucc * If the created connection is an inbound connection, close another server * socket because currently only one file-transfer session is allowed. After * that, we need to make sure that both server socket would be nulled out. * As for outbound connections, we just notify the controller that it's done. */ if (aSocket == mRfcommSocket) { MOZ_ASSERT(!mSocket); mRfcommSocket.swap(mSocket); + mSocketType = BluetoothSocketType::RFCOMM; mL2capSocket->Close(); mL2capSocket = nullptr; } else if (aSocket == mL2capSocket) { MOZ_ASSERT(!mSocket); mL2capSocket.swap(mSocket); + mSocketType = BluetoothSocketType::EL2CAP; mRfcommSocket->Close(); mRfcommSocket = nullptr; } // Cache device address since we can't get socket address when a remote // device disconnect with us. mSocket->GetAddress(mConnectedDeviceAddress); @@ -1556,16 +1568,17 @@ BluetoothOppManager::OnSocketConnectSucc void BluetoothOppManager::OnSocketConnectError(BluetoothSocket* aSocket) { BT_LOGR("[%s]", (mIsServer)? "server" : "client"); mRfcommSocket = nullptr; mL2capSocket = nullptr; mSocket = nullptr; + mSocketType = static_cast<BluetoothSocketType>(0); if (!mIsServer) { // Inform gaia of remaining blobs' sending failure DiscardBlobsToSend(); } // Listen as a server if there's no more batch to process if (!ProcessNextBatch() && !mIsServer) { @@ -1603,16 +1616,18 @@ BluetoothOppManager::OnSocketDisconnect( } } AfterOppDisconnected(); mConnectedDeviceAddress.AssignLiteral(BLUETOOTH_ADDRESS_NONE); mSuccessFlag = false; mSocket = nullptr; + mSocketType = static_cast<BluetoothSocketType>(0); + // Listen as a server if there's no more batch to process if (!ProcessNextBatch()) { Listen(); } } void BluetoothOppManager::Disconnect(BluetoothProfileController* aController) @@ -1649,17 +1664,19 @@ BluetoothOppManager::OnGetServiceChannel } else { OnSocketConnectError(mSocket); } } return; } - if (!mSocket->Connect(aDeviceAddress, kObexObjectPush, aChannel)) { + nsresult rv = mSocket->Connect(aDeviceAddress, kObexObjectPush, + mSocketType, aChannel, true, true); + if (NS_FAILED(rv)) { OnSocketConnectError(mSocket); } } void BluetoothOppManager::OnUpdateSdpRecords(const nsAString& aDeviceAddress) { MOZ_ASSERT(NS_IsMainThread());
--- a/dom/bluetooth/bluez/BluetoothOppManager.h +++ b/dom/bluetooth/bluez/BluetoothOppManager.h @@ -214,16 +214,18 @@ private: nsRefPtr<BluetoothSocket> mSocket; // Server sockets. Once an inbound connection is established, it will hand // over the ownership to mSocket, and get a new server socket while Listen() // is called. nsRefPtr<BluetoothSocket> mRfcommSocket; nsRefPtr<BluetoothSocket> mL2capSocket; + BluetoothSocketType mSocketType; + // This holds the time when OPP manager fail to get service channel and // prepare to refresh SDP records. mozilla::TimeStamp mLastServiceChannelCheck; }; END_BLUETOOTH_NAMESPACE #endif
--- a/dom/bluetooth/bluez/BluetoothSocket.cpp +++ b/dom/bluetooth/bluez/BluetoothSocket.cpp @@ -552,81 +552,79 @@ public: XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new ConnectTask(io)); } }; // // BluetoothSocket // -BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver, - BluetoothSocketType aType, - bool aAuth, - bool aEncrypt) +BluetoothSocket::BluetoothSocket(BluetoothSocketObserver* aObserver) : mObserver(aObserver) - , mType(aType) - , mAuth(aAuth) - , mEncrypt(aEncrypt) , mIO(nullptr) { MOZ_ASSERT(aObserver); } BluetoothSocket::~BluetoothSocket() { MOZ_ASSERT(!mIO); } -bool +nsresult BluetoothSocket::Connect(const nsAString& aDeviceAddress, const BluetoothUuid& aServiceUuid, - int aChannel) + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(!aDeviceAddress.IsEmpty()); nsAutoPtr<BluetoothUnixSocketConnector> connector( new BluetoothUnixSocketConnector(NS_ConvertUTF16toUTF8(aDeviceAddress), - mType, aChannel, mAuth, mEncrypt)); + aType, aChannel, aAuth, aEncrypt)); nsresult rv = Connect(connector); if (NS_FAILED(rv)) { nsAutoString addr; GetAddress(addr); BT_LOGD("%s failed. Current connected device address: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(addr).get()); - return false; + return rv; } connector.forget(); - return true; + return NS_OK; } -bool +nsresult BluetoothSocket::Listen(const nsAString& aServiceName, const BluetoothUuid& aServiceUuid, - int aChannel) + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt) { MOZ_ASSERT(NS_IsMainThread()); nsAutoPtr<BluetoothUnixSocketConnector> connector( new BluetoothUnixSocketConnector(NS_LITERAL_CSTRING(BLUETOOTH_ADDRESS_NONE), - mType, aChannel, mAuth, mEncrypt)); + aType, aChannel, aAuth, aEncrypt)); nsresult rv = Listen(connector); if (NS_FAILED(rv)) { nsAutoString addr; GetAddress(addr); BT_LOGD("%s failed. Current connected device address: %s", __FUNCTION__, NS_ConvertUTF16toUTF8(addr).get()); - return false; + return rv; } connector.forget(); - return true; + return NS_OK; } void BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mObserver);
--- a/dom/bluetooth/bluez/BluetoothSocket.h +++ b/dom/bluetooth/bluez/BluetoothSocket.h @@ -19,28 +19,30 @@ BEGIN_BLUETOOTH_NAMESPACE class BluetoothSocketObserver; class BluetoothUnixSocketConnector; class BluetoothSocket final : public mozilla::ipc::DataSocket { public: - BluetoothSocket(BluetoothSocketObserver* aObserver, - BluetoothSocketType aType, - bool aAuth, - bool aEncrypt); + BluetoothSocket(BluetoothSocketObserver* aObserver); ~BluetoothSocket(); - bool Connect(const nsAString& aDeviceAddress, - const BluetoothUuid& aServiceUuid, - int aChannel); - bool Listen(const nsAString& aServiceName, - const BluetoothUuid& aServiceUuid, - int aChannel); + nsresult Connect(const nsAString& aDeviceAddress, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt); + + nsresult Listen(const nsAString& aServiceName, + const BluetoothUuid& aServiceUuid, + BluetoothSocketType aType, + int aChannel, + bool aAuth, bool aEncrypt); /** * Method to be called whenever data is received. This is only called on the * main thread. * * @param aBuffer Data received from the socket. */ void ReceiveSocketData(nsAutoPtr<mozilla::ipc::UnixSocketBuffer>& aBuffer); @@ -99,17 +101,14 @@ public: private: class BluetoothSocketIO; class ConnectTask; class DelayedConnectTask; class ListenTask; BluetoothSocketObserver* mObserver; - BluetoothSocketType mType; - bool mAuth; - bool mEncrypt; BluetoothSocketIO* mIO; }; END_BLUETOOTH_NAMESPACE #endif
--- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp @@ -73,19 +73,23 @@ BluetoothUnixSocketConnector::CreateSock [BluetoothSocketType::SCO] = BTPROTO_SCO, [BluetoothSocketType::L2CAP] = BTPROTO_L2CAP, [BluetoothSocketType::EL2CAP] = BTPROTO_L2CAP }; MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sType)); MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sProtocol)); + BT_LOGR("mType=%d, sType=%d sProtocol=%d", + static_cast<int>(mType), sType[mType], sProtocol[mType]); + aFd = socket(AF_BLUETOOTH, sType[mType], sProtocol[mType]); if (aFd < 0) { - BT_LOGR("Could not open Bluetooth socket!"); + BT_LOGR("Could not open Bluetooth socket: %d(%s)", + errno, strerror(errno)); return NS_ERROR_FAILURE; } return NS_OK; } nsresult BluetoothUnixSocketConnector::SetSocketFlags(int aFd) const @@ -315,16 +319,19 @@ BluetoothUnixSocketConnector::ConvertAdd break; case BluetoothSocketType::L2CAP: case BluetoothSocketType::EL2CAP: { const struct sockaddr_l2* l2 = reinterpret_cast<const struct sockaddr_l2*>(&aAddress); b = l2->l2_bdaddr.b; } break; + default: + BT_LOGR("Unknown socket type %d", static_cast<int>(mType)); + return NS_ERROR_ILLEGAL_VALUE; } char str[32]; snprintf(str, sizeof(str), "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", b[5], b[4], b[3], b[2], b[1], b[0]); aAddressString.Assign(str);