зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1239979: Add |BluetoothSocket::Accept| method, r=btian
The new method |Accept| of |BluetoothSocket| encapsulates the code for accepting from a passive socket. Having this method will allow for storing the socket interface in |BluetoothSocket| itself.
This commit is contained in:
Родитель
a88bdd194f
Коммит
857bbd0291
|
@ -429,24 +429,20 @@ private:
|
|||
class InvokeAcceptTask final : public SocketTask<DroidSocketImpl>
|
||||
{
|
||||
public:
|
||||
InvokeAcceptTask(DroidSocketImpl* aImpl, int aFd)
|
||||
InvokeAcceptTask(DroidSocketImpl* aImpl, int aListenFd)
|
||||
: SocketTask<DroidSocketImpl>(aImpl)
|
||||
, mFd(aFd)
|
||||
, mListenFd(aListenFd)
|
||||
{ }
|
||||
|
||||
void Run() override
|
||||
{
|
||||
MOZ_ASSERT(GetIO()->IsConsumerThread());
|
||||
MOZ_ASSERT(sBluetoothSocketInterface);
|
||||
|
||||
BluetoothSocketResultHandler* res = new AcceptResultHandler(GetIO());
|
||||
GetIO()->mConsumer->SetCurrentResultHandler(res);
|
||||
|
||||
sBluetoothSocketInterface->Accept(mFd, res);
|
||||
GetIO()->mConsumer->Accept(mListenFd, new AcceptResultHandler(GetIO()));
|
||||
}
|
||||
|
||||
private:
|
||||
int mFd;
|
||||
int mListenFd;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -751,6 +747,15 @@ BluetoothSocket::Listen(const nsAString& aServiceName,
|
|||
MessageLoop::current(), XRE_GetIOMessageLoop());
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothSocket::Accept(int aListenFd, BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
SetCurrentResultHandler(aRes);
|
||||
sBluetoothSocketInterface->Accept(aListenFd, aRes);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,8 @@ public:
|
|||
int aChannel,
|
||||
bool aAuth, bool aEncrypt);
|
||||
|
||||
nsresult Accept(int aListenFd, BluetoothSocketResultHandler* aRes);
|
||||
|
||||
/**
|
||||
* Method to be called whenever data is received. This is only called on the
|
||||
* consumer thread.
|
||||
|
@ -70,11 +72,6 @@ public:
|
|||
mDeviceAddress = aDeviceAddress;
|
||||
}
|
||||
|
||||
inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
mCurrentRes = aRes;
|
||||
}
|
||||
|
||||
// Methods for |DataSocket|
|
||||
//
|
||||
|
||||
|
@ -90,6 +87,11 @@ public:
|
|||
void OnDisconnect() override;
|
||||
|
||||
private:
|
||||
inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
mCurrentRes = aRes;
|
||||
}
|
||||
|
||||
BluetoothSocketObserver* mObserver;
|
||||
BluetoothSocketResultHandler* mCurrentRes;
|
||||
DroidSocketImpl* mImpl;
|
||||
|
|
Загрузка…
Ссылка в новой задаче