зеркало из 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>
|
class InvokeAcceptTask final : public SocketTask<DroidSocketImpl>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InvokeAcceptTask(DroidSocketImpl* aImpl, int aFd)
|
InvokeAcceptTask(DroidSocketImpl* aImpl, int aListenFd)
|
||||||
: SocketTask<DroidSocketImpl>(aImpl)
|
: SocketTask<DroidSocketImpl>(aImpl)
|
||||||
, mFd(aFd)
|
, mListenFd(aListenFd)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void Run() override
|
void Run() override
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(GetIO()->IsConsumerThread());
|
MOZ_ASSERT(GetIO()->IsConsumerThread());
|
||||||
MOZ_ASSERT(sBluetoothSocketInterface);
|
|
||||||
|
|
||||||
BluetoothSocketResultHandler* res = new AcceptResultHandler(GetIO());
|
GetIO()->mConsumer->Accept(mListenFd, new AcceptResultHandler(GetIO()));
|
||||||
GetIO()->mConsumer->SetCurrentResultHandler(res);
|
|
||||||
|
|
||||||
sBluetoothSocketInterface->Accept(mFd, res);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mFd;
|
int mListenFd;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -751,6 +747,15 @@ BluetoothSocket::Listen(const nsAString& aServiceName,
|
||||||
MessageLoop::current(), XRE_GetIOMessageLoop());
|
MessageLoop::current(), XRE_GetIOMessageLoop());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
BluetoothSocket::Accept(int aListenFd, BluetoothSocketResultHandler* aRes)
|
||||||
|
{
|
||||||
|
SetCurrentResultHandler(aRes);
|
||||||
|
sBluetoothSocketInterface->Accept(aListenFd, aRes);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
|
BluetoothSocket::ReceiveSocketData(nsAutoPtr<UnixSocketBuffer>& aBuffer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,8 @@ public:
|
||||||
int aChannel,
|
int aChannel,
|
||||||
bool aAuth, bool aEncrypt);
|
bool aAuth, bool aEncrypt);
|
||||||
|
|
||||||
|
nsresult Accept(int aListenFd, BluetoothSocketResultHandler* aRes);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to be called whenever data is received. This is only called on the
|
* Method to be called whenever data is received. This is only called on the
|
||||||
* consumer thread.
|
* consumer thread.
|
||||||
|
@ -70,11 +72,6 @@ public:
|
||||||
mDeviceAddress = aDeviceAddress;
|
mDeviceAddress = aDeviceAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
|
|
||||||
{
|
|
||||||
mCurrentRes = aRes;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Methods for |DataSocket|
|
// Methods for |DataSocket|
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -90,6 +87,11 @@ public:
|
||||||
void OnDisconnect() override;
|
void OnDisconnect() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline void SetCurrentResultHandler(BluetoothSocketResultHandler* aRes)
|
||||||
|
{
|
||||||
|
mCurrentRes = aRes;
|
||||||
|
}
|
||||||
|
|
||||||
BluetoothSocketObserver* mObserver;
|
BluetoothSocketObserver* mObserver;
|
||||||
BluetoothSocketResultHandler* mCurrentRes;
|
BluetoothSocketResultHandler* mCurrentRes;
|
||||||
DroidSocketImpl* mImpl;
|
DroidSocketImpl* mImpl;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче