Bug 1158818: Only store Bluetooth result runnable after command has been sent successfully, r=shuang

With the current code, the Bluetooth result runnable is saved for
receiving before a command has been sent successfully. If sending
fails afterwards, the saved result runnable will still sit in the
result queue, and interfere with later, successful commands.

With this patch, the result runnable is saved only if the sending
was successful.
This commit is contained in:
Thomas Zimmermann 2015-04-30 11:29:25 +02:00
Родитель 65d3ca050c
Коммит 79b0cc601a
3 изменённых файлов: 20 добавлений и 5 удалений

Просмотреть файл

@ -1507,6 +1507,7 @@ BluetoothDaemonProtocol::Send(BluetoothDaemonPDU* aPDU, void* aUserData)
MOZ_ASSERT(mConnection);
MOZ_ASSERT(aPDU);
aPDU->SetConsumer(this);
aPDU->SetUserData(aUserData);
aPDU->UpdateHeader();
return mConnection->Send(aPDU); // Forward PDU to command channel

Просмотреть файл

@ -42,8 +42,9 @@ static const char sBluetoothdSocketName[] = "bluez_hal_socket";
BluetoothDaemonPDU::BluetoothDaemonPDU(uint8_t aService, uint8_t aOpcode,
uint16_t aPayloadSize)
: UnixSocketIOBuffer(HEADER_SIZE + aPayloadSize)
, mUserData(nullptr)
: UnixSocketIOBuffer(HEADER_SIZE + aPayloadSize)
, mConsumer(nullptr)
, mUserData(nullptr)
{
uint8_t* data = Append(HEADER_SIZE);
MOZ_ASSERT(data);
@ -55,8 +56,9 @@ BluetoothDaemonPDU::BluetoothDaemonPDU(uint8_t aService, uint8_t aOpcode,
}
BluetoothDaemonPDU::BluetoothDaemonPDU(size_t aPayloadSize)
: UnixSocketIOBuffer(HEADER_SIZE + aPayloadSize)
, mUserData(nullptr)
: UnixSocketIOBuffer(HEADER_SIZE + aPayloadSize)
, mConsumer(nullptr)
, mUserData(nullptr)
{ }
void
@ -92,6 +94,12 @@ BluetoothDaemonPDU::Send(int aFd)
Consume(res);
if (mConsumer) {
// We successfully sent a PDU, now store the
// result runnable in the consumer.
mConsumer->StoreUserData(*this);
}
return res;
}
@ -376,7 +384,6 @@ BluetoothDaemonConnectionIO::Send(BluetoothDaemonPDU* aPDU)
MOZ_ASSERT(mConsumer);
MOZ_ASSERT(aPDU);
mConsumer->StoreUserData(*aPDU); // Store user data for reply
EnqueueData(aPDU);
AddWatchers(WRITE_WATCHER, false);
}

Просмотреть файл

@ -18,6 +18,7 @@ namespace mozilla {
namespace ipc {
class BluetoothDaemonConnectionIO;
class BluetoothDaemonPDUConsumer;
/*
* |BlutoothDaemonPDU| represents a single PDU that is transfered from or to
@ -55,6 +56,11 @@ public:
uint16_t aPayloadSize);
BluetoothDaemonPDU(size_t aPayloadSize);
void SetConsumer(BluetoothDaemonPDUConsumer* aConsumer)
{
mConsumer = aConsumer;
}
void SetUserData(void* aUserData)
{
mUserData = aUserData;
@ -79,6 +85,7 @@ private:
size_t GetPayloadSize() const;
void OnError(const char* aFunction, int aErrno);
BluetoothDaemonPDUConsumer* mConsumer;
void* mUserData;
ScopedClose mReceivedFd;
};