mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1168806: Use 'consumer thread' in socket interface, r=kmachulis
The socket IPC interfaces still use 'main thread' in a number of places. This patch changes all such interfaces and documentation to speak of 'consumer thread' instead.
This commit is contained in:
parent
364b0a0542
commit
21a30b633f
@ -123,8 +123,8 @@ public:
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
* mImpl as container.
|
||||
* directly from consumer thread. All non-consumer-thread accesses should
|
||||
* happen with mImpl as container.
|
||||
*/
|
||||
RefPtr<BluetoothSocket> mConsumer;
|
||||
|
||||
@ -143,7 +143,7 @@ public:
|
||||
return GetDataSocket();
|
||||
}
|
||||
|
||||
bool IsShutdownOnMainThread() const override
|
||||
bool IsShutdownOnConsumerThread() const override
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
|
||||
@ -155,10 +155,11 @@ public:
|
||||
return mShuttingDownOnIOThread;
|
||||
}
|
||||
|
||||
void ShutdownOnMainThread() override
|
||||
void ShutdownOnConsumerThread() override
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnConsumerThread());
|
||||
|
||||
mConsumer = nullptr;
|
||||
}
|
||||
|
||||
@ -392,7 +393,7 @@ public:
|
||||
|
||||
mozilla::ScopedClose fd(aFd); // Close received socket fd on error
|
||||
|
||||
if (mImpl->IsShutdownOnMainThread()) {
|
||||
if (mImpl->IsShutdownOnConsumerThread()) {
|
||||
BT_LOGD("mConsumer is null, aborting receive!");
|
||||
return;
|
||||
}
|
||||
@ -412,7 +413,7 @@ public:
|
||||
MOZ_ASSERT(mImpl->IsConsumerThread());
|
||||
BT_LOGR("BluetoothSocketInterface::Accept failed: %d", (int)aStatus);
|
||||
|
||||
if (!mImpl->IsShutdownOnMainThread()) {
|
||||
if (!mImpl->IsShutdownOnConsumerThread()) {
|
||||
// Instead of NotifyError(), call NotifyDisconnect() to trigger
|
||||
// BluetoothOppManager::OnSocketDisconnect() as
|
||||
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
|
||||
@ -534,7 +535,7 @@ DroidSocketImpl::QueryReceiveBuffer(
|
||||
|
||||
/**
|
||||
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||
* to an instance of |BluetoothSocket| on the main thread.
|
||||
* to an instance of |BluetoothSocket| on the consumer thread.
|
||||
*/
|
||||
class DroidSocketImpl::ReceiveRunnable final
|
||||
: public SocketIORunnable<DroidSocketImpl>
|
||||
@ -551,7 +552,7 @@ public:
|
||||
|
||||
MOZ_ASSERT(io->IsConsumerThread());
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
@ -611,7 +612,7 @@ public:
|
||||
{
|
||||
MOZ_ASSERT(mImpl->IsConsumerThread());
|
||||
|
||||
if (mImpl->IsShutdownOnMainThread()) {
|
||||
if (mImpl->IsShutdownOnConsumerThread()) {
|
||||
BT_LOGD("mConsumer is null, aborting send!");
|
||||
return;
|
||||
}
|
||||
@ -631,7 +632,7 @@ public:
|
||||
MOZ_ASSERT(mImpl->IsConsumerThread());
|
||||
BT_WARNING("Connect failed: %d", (int)aStatus);
|
||||
|
||||
if (!mImpl->IsShutdownOnMainThread()) {
|
||||
if (!mImpl->IsShutdownOnConsumerThread()) {
|
||||
// Instead of NotifyError(), call NotifyDisconnect() to trigger
|
||||
// BluetoothOppManager::OnSocketDisconnect() as
|
||||
// DroidSocketImpl::OnFileCanReadWithoutBlocking() in Firefox OS 2.0 in
|
||||
@ -772,7 +773,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
MOZ_ASSERT(mImpl->IsConsumerThread());
|
||||
MOZ_ASSERT(!mImpl->IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!mImpl->IsShutdownOnConsumerThread());
|
||||
|
||||
mImpl->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
@ -800,7 +801,7 @@ BluetoothSocket::Close()
|
||||
// From this point on, we consider mImpl as being deleted.
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mImpl->ShutdownOnMainThread();
|
||||
mImpl->ShutdownOnConsumerThread();
|
||||
mImpl->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mImpl));
|
||||
mImpl = nullptr;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
|
||||
/**
|
||||
* Method to be called whenever data is received. This is only called on the
|
||||
* main thread.
|
||||
* consumer thread.
|
||||
*
|
||||
* @param aBuffer Data received from the socket.
|
||||
*/
|
||||
|
@ -83,10 +83,10 @@ public:
|
||||
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
bool IsShutdownOnConsumerThread() const override;
|
||||
bool IsShutdownOnIOThread() const override;
|
||||
|
||||
void ShutdownOnMainThread() override;
|
||||
void ShutdownOnConsumerThread() override;
|
||||
void ShutdownOnIOThread() override;
|
||||
|
||||
private:
|
||||
@ -96,8 +96,8 @@ private:
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
* mIO as container.
|
||||
* directly from consumer thread. All non-consumer-thread accesses should
|
||||
* happen with mIO as container.
|
||||
*/
|
||||
RefPtr<BluetoothSocket> mConsumer;
|
||||
|
||||
@ -122,7 +122,8 @@ private:
|
||||
struct sockaddr_storage mAddress;
|
||||
|
||||
/**
|
||||
* Task member for delayed connect task. Should only be access on main thread.
|
||||
* Task member for delayed connect task. Should only be access on consumer
|
||||
* thread.
|
||||
*/
|
||||
CancelableTask* mDelayedConnectTask;
|
||||
|
||||
@ -152,7 +153,7 @@ BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO(
|
||||
BluetoothSocket::BluetoothSocketIO::~BluetoothSocketIO()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(IsShutdownOnConsumerThread());
|
||||
}
|
||||
|
||||
void
|
||||
@ -380,7 +381,7 @@ BluetoothSocket::BluetoothSocketIO::FireSocketError()
|
||||
// Clean up watchers, statuses, fds
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
// Tell the consumer thread we've errored
|
||||
GetConsumerThread()->Dispatch(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
|
||||
NS_DISPATCH_NORMAL);
|
||||
@ -405,7 +406,7 @@ BluetoothSocket::BluetoothSocketIO::QueryReceiveBuffer(
|
||||
|
||||
/**
|
||||
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||
* to an instance of |BluetoothSocket| on the main thread.
|
||||
* to an instance of |BluetoothSocket| on the consumer thread.
|
||||
*/
|
||||
class BluetoothSocket::BluetoothSocketIO::ReceiveRunnable final
|
||||
: public SocketIORunnable<BluetoothSocketIO>
|
||||
@ -422,7 +423,7 @@ public:
|
||||
|
||||
MOZ_ASSERT(io->IsConsumerThread());
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
@ -462,7 +463,7 @@ BluetoothSocket::BluetoothSocketIO::GetSocketBase()
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothSocket::BluetoothSocketIO::IsShutdownOnMainThread() const
|
||||
BluetoothSocket::BluetoothSocketIO::IsShutdownOnConsumerThread() const
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
|
||||
@ -470,10 +471,10 @@ BluetoothSocket::BluetoothSocketIO::IsShutdownOnMainThread() const
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothSocket::BluetoothSocketIO::ShutdownOnMainThread()
|
||||
BluetoothSocket::BluetoothSocketIO::ShutdownOnConsumerThread()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnConsumerThread());
|
||||
|
||||
mConsumer = nullptr;
|
||||
}
|
||||
@ -551,7 +552,7 @@ public:
|
||||
}
|
||||
|
||||
BluetoothSocketIO* io = GetIO();
|
||||
if (io->IsShutdownOnMainThread()) {
|
||||
if (io->IsShutdownOnConsumerThread()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -730,7 +731,7 @@ BluetoothSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
{
|
||||
MOZ_ASSERT(mIO);
|
||||
MOZ_ASSERT(mIO->IsConsumerThread());
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
|
||||
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
@ -753,7 +754,7 @@ BluetoothSocket::Close()
|
||||
// From this point on, we consider mIO as being deleted.
|
||||
// We sever the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mIO->ShutdownOnMainThread();
|
||||
mIO->ShutdownOnConsumerThread();
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
|
||||
/**
|
||||
* Method to be called whenever data is received. This is only called on the
|
||||
* main thread.
|
||||
* consumer thread.
|
||||
*
|
||||
* @param aBuffer Data received from the socket.
|
||||
*/
|
||||
|
@ -242,10 +242,10 @@ public:
|
||||
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
bool IsShutdownOnConsumerThread() const override;
|
||||
bool IsShutdownOnIOThread() const override;
|
||||
|
||||
void ShutdownOnMainThread() override;
|
||||
void ShutdownOnConsumerThread() override;
|
||||
void ShutdownOnIOThread() override;
|
||||
|
||||
private:
|
||||
@ -332,7 +332,7 @@ BluetoothDaemonConnectionIO::OnError(const char* aFunction, int aErrno)
|
||||
// Clean up watchers, status, fd
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
// Tell the consumer thread we've errored
|
||||
GetConsumerThread()->Dispatch(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
|
||||
NS_DISPATCH_NORMAL);
|
||||
@ -403,7 +403,7 @@ BluetoothDaemonConnectionIO::GetSocketBase()
|
||||
}
|
||||
|
||||
bool
|
||||
BluetoothDaemonConnectionIO::IsShutdownOnMainThread() const
|
||||
BluetoothDaemonConnectionIO::IsShutdownOnConsumerThread() const
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
|
||||
@ -417,10 +417,10 @@ BluetoothDaemonConnectionIO::IsShutdownOnIOThread() const
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonConnectionIO::ShutdownOnMainThread()
|
||||
BluetoothDaemonConnectionIO::ShutdownOnConsumerThread()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnConsumerThread());
|
||||
|
||||
mConnection = nullptr;
|
||||
}
|
||||
@ -505,7 +505,7 @@ BluetoothDaemonConnection::Close()
|
||||
|
||||
MOZ_ASSERT(mIO->IsConsumerThread());
|
||||
|
||||
mIO->ShutdownOnMainThread();
|
||||
mIO->ShutdownOnConsumerThread();
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
|
@ -94,7 +94,7 @@ private:
|
||||
/*
|
||||
* |BluetoothDaemonPDUConsumer| processes incoming PDUs from the Bluetooth
|
||||
* daemon. Please note that its method |Handle| runs on a different than the
|
||||
* main thread.
|
||||
* consumer thread.
|
||||
*/
|
||||
class BluetoothDaemonPDUConsumer
|
||||
{
|
||||
|
@ -22,21 +22,21 @@ class BluetoothDaemonConnectionConsumer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Callback for socket success. Main-thread only.
|
||||
* Callback for socket success. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
virtual void OnConnectSuccess(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket errors. Main-thread only.
|
||||
* Callback for socket errors. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
virtual void OnConnectError(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket disconnect. Main-thread only.
|
||||
* Callback for socket disconnect. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
|
@ -19,7 +19,7 @@ class UnixSocketConnector;
|
||||
|
||||
/*
|
||||
* |ConnectionOrientedSocketIO| and |ConnectionOrientedSocket| define
|
||||
* interfaces for implementing stream sockets on I/O and main thread.
|
||||
* interfaces for implementing stream sockets on I/O and consumer thread.
|
||||
* |ListenSocket| uses these classes to handle accepted sockets.
|
||||
*/
|
||||
|
||||
@ -39,7 +39,7 @@ class ConnectionOrientedSocket : public DataSocket
|
||||
public:
|
||||
/**
|
||||
* Prepares an instance of |ConnectionOrientedSocket| in DISCONNECTED
|
||||
* state for accepting a connection. Main-thread only.
|
||||
* state for accepting a connection. Consumer-thread only.
|
||||
*
|
||||
* @param aConnector The new connector object, owned by the
|
||||
* connection-oriented socket.
|
||||
|
@ -56,10 +56,10 @@ public:
|
||||
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
bool IsShutdownOnConsumerThread() const override;
|
||||
bool IsShutdownOnIOThread() const override;
|
||||
|
||||
void ShutdownOnMainThread() override;
|
||||
void ShutdownOnConsumerThread() override;
|
||||
void ShutdownOnIOThread() override;
|
||||
|
||||
private:
|
||||
@ -67,8 +67,8 @@ private:
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
* mIO as container.
|
||||
* directly from consumer thread. All non-consumer-thread accesses should
|
||||
* happen with mIO as container.
|
||||
*/
|
||||
RefPtr<ListenSocket> mListenSocket;
|
||||
|
||||
@ -114,7 +114,7 @@ ListenSocketIO::ListenSocketIO(nsIThread* aConsumerThread,
|
||||
ListenSocketIO::~ListenSocketIO()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(IsShutdownOnConsumerThread());
|
||||
}
|
||||
|
||||
UnixSocketConnector*
|
||||
@ -190,7 +190,7 @@ ListenSocketIO::FireSocketError()
|
||||
// Clean up watchers, statuses, fds
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
// Tell the consumer thread we've errored
|
||||
GetConsumerThread()->Dispatch(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
|
||||
NS_DISPATCH_NORMAL);
|
||||
@ -232,7 +232,7 @@ ListenSocketIO::GetSocketBase()
|
||||
}
|
||||
|
||||
bool
|
||||
ListenSocketIO::IsShutdownOnMainThread() const
|
||||
ListenSocketIO::IsShutdownOnConsumerThread() const
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
|
||||
@ -246,10 +246,10 @@ ListenSocketIO::IsShutdownOnIOThread() const
|
||||
}
|
||||
|
||||
void
|
||||
ListenSocketIO::ShutdownOnMainThread()
|
||||
ListenSocketIO::ShutdownOnConsumerThread()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnConsumerThread());
|
||||
|
||||
mListenSocket = nullptr;
|
||||
}
|
||||
@ -391,7 +391,7 @@ ListenSocket::Close()
|
||||
// From this point on, we consider mIO as being deleted. We sever
|
||||
// the relationship here so any future calls to listen or connect
|
||||
// will create a new implementation.
|
||||
mIO->ShutdownOnMainThread();
|
||||
mIO->ShutdownOnConsumerThread();
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
|
@ -19,21 +19,21 @@ public:
|
||||
virtual ~ListenSocketConsumer();
|
||||
|
||||
/**
|
||||
* Callback for socket success. Main-thread only.
|
||||
* Callback for socket success. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the listening socket.
|
||||
*/
|
||||
virtual void OnConnectSuccess(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket errors. Main-thread only.
|
||||
* Callback for socket errors. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the listening socket.
|
||||
*/
|
||||
virtual void OnConnectError(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket disconnect. Main-thread only.
|
||||
* Callback for socket disconnect. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the listeing socket.
|
||||
*/
|
||||
|
@ -302,7 +302,7 @@ SocketIOEventRunnable::Run()
|
||||
|
||||
MOZ_ASSERT(io->IsConsumerThread());
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
@ -338,7 +338,7 @@ SocketIORequestClosingRunnable::Run()
|
||||
|
||||
MOZ_ASSERT(io->IsConsumerThread());
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
@ -388,8 +388,8 @@ SocketIOShutdownTask::Run()
|
||||
// At this point, there should be no new events on the I/O thread
|
||||
// after this one with the possible exception of an accept task,
|
||||
// which ShutdownOnIOThread will cancel for us. We are now fully
|
||||
// shut down, so we can send a message to the main thread to delete
|
||||
// |io| safely knowing that it's not reference any longer.
|
||||
// shut down, so we can send a message to the consumer thread to
|
||||
// delete |io| safely knowing that it's not reference any longer.
|
||||
io->ShutdownOnIOThread();
|
||||
io->GetConsumerThread()->Dispatch(new SocketIODeleteInstanceRunnable(io),
|
||||
NS_DISPATCH_NORMAL);
|
||||
|
@ -256,23 +256,23 @@ public:
|
||||
|
||||
/**
|
||||
* Queues the internal representation of socket for deletion. Can be called
|
||||
* from main thread.
|
||||
* from consumer thread.
|
||||
*/
|
||||
virtual void Close() = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket connect/accept success. Called after connect/accept has
|
||||
* finished. Will be run on main thread, before any reads take place.
|
||||
* finished. Will be run on consumer thread before any reads take place.
|
||||
*/
|
||||
virtual void OnConnectSuccess() = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket connect/accept error. Will be run on main thread.
|
||||
* Callback for socket connect/accept error. Will be run on consumer thread.
|
||||
*/
|
||||
virtual void OnConnectError() = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket disconnect. Will be run on main thread.
|
||||
* Callback for socket disconnect. Will be run on consumer thread.
|
||||
*/
|
||||
virtual void OnDisconnect() = 0;
|
||||
|
||||
@ -340,7 +340,7 @@ public:
|
||||
*
|
||||
* @return True if the socket class has been shut down, false otherwise.
|
||||
*/
|
||||
virtual bool IsShutdownOnMainThread() const = 0;
|
||||
virtual bool IsShutdownOnConsumerThread() const = 0;
|
||||
|
||||
/**
|
||||
* Signals to the socket I/O classes that it has been shut down.
|
||||
@ -351,7 +351,7 @@ public:
|
||||
* Signals to the socket I/O classes that the socket class has been
|
||||
* shut down.
|
||||
*/
|
||||
virtual void ShutdownOnMainThread() = 0;
|
||||
virtual void ShutdownOnConsumerThread() = 0;
|
||||
|
||||
/**
|
||||
* Returns the consumer thread.
|
||||
@ -378,7 +378,7 @@ private:
|
||||
//
|
||||
|
||||
/* |SocketIORunnable| is a runnable for sending a message from
|
||||
* the I/O thread to the main thread.
|
||||
* the I/O thread to the consumer thread.
|
||||
*/
|
||||
template <typename T>
|
||||
class SocketIORunnable : public nsRunnable
|
||||
@ -405,7 +405,7 @@ private:
|
||||
|
||||
/**
|
||||
* |SocketIOEventRunnable| reports the connection state on the
|
||||
* I/O thread back to the main thread.
|
||||
* I/O thread back to the consumer thread.
|
||||
*/
|
||||
class SocketIOEventRunnable final : public SocketIORunnable<SocketIOBase>
|
||||
{
|
||||
@ -426,7 +426,7 @@ private:
|
||||
|
||||
/**
|
||||
* |SocketIORequestClosingRunnable| closes an instance of |SocketBase|
|
||||
* to the main thread.
|
||||
* to the consumer thread.
|
||||
*/
|
||||
class SocketIORequestClosingRunnable final
|
||||
: public SocketIORunnable<SocketIOBase>
|
||||
@ -438,7 +438,7 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* |SocketIODeleteInstanceRunnable| deletes an object on the main thread.
|
||||
* |SocketIODeleteInstanceRunnable| deletes an object on the consumer thread.
|
||||
*/
|
||||
class SocketIODeleteInstanceRunnable final : public nsRunnable
|
||||
{
|
||||
@ -493,7 +493,7 @@ private:
|
||||
|
||||
/**
|
||||
* |SocketIOShutdownTask| signals shutdown to the socket I/O class on
|
||||
* the I/O thread and sends it to the main thread for destruction.
|
||||
* the I/O thread and sends it to the consumer thread for destruction.
|
||||
*/
|
||||
class SocketIOShutdownTask final : public SocketIOTask<SocketIOBase>
|
||||
{
|
||||
|
@ -88,10 +88,10 @@ public:
|
||||
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
bool IsShutdownOnConsumerThread() const override;
|
||||
bool IsShutdownOnIOThread() const override;
|
||||
|
||||
void ShutdownOnMainThread() override;
|
||||
void ShutdownOnConsumerThread() override;
|
||||
void ShutdownOnIOThread() override;
|
||||
|
||||
private:
|
||||
@ -99,8 +99,8 @@ private:
|
||||
|
||||
/**
|
||||
* Consumer pointer. Non-thread safe RefPtr, so should only be manipulated
|
||||
* directly from main thread. All non-main-thread accesses should happen with
|
||||
* mIO as container.
|
||||
* directly from consumer thread. All non-consumer-thread accesses should
|
||||
* happen with mIO as container.
|
||||
*/
|
||||
RefPtr<StreamSocket> mStreamSocket;
|
||||
|
||||
@ -125,7 +125,8 @@ private:
|
||||
struct sockaddr_storage mAddress;
|
||||
|
||||
/**
|
||||
* Task member for delayed connect task. Should only be access on main thread.
|
||||
* Task member for delayed connect task. Should only be access on consumer
|
||||
* thread.
|
||||
*/
|
||||
CancelableTask* mDelayedConnectTask;
|
||||
|
||||
@ -171,7 +172,7 @@ StreamSocketIO::StreamSocketIO(nsIThread* aConsumerThread,
|
||||
StreamSocketIO::~StreamSocketIO()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(IsShutdownOnConsumerThread());
|
||||
}
|
||||
|
||||
StreamSocket*
|
||||
@ -319,7 +320,7 @@ StreamSocketIO::FireSocketError()
|
||||
// Clean up watchers, statuses, fds
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
// Tell the consumer thread we've errored
|
||||
GetConsumerThread()->Dispatch(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR),
|
||||
NS_DISPATCH_NORMAL);
|
||||
@ -371,7 +372,7 @@ StreamSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer)
|
||||
|
||||
/**
|
||||
* |ReceiveRunnable| transfers data received on the I/O thread
|
||||
* to an instance of |StreamSocket| on the main thread.
|
||||
* to an instance of |StreamSocket| on the consumer thread.
|
||||
*/
|
||||
class StreamSocketIO::ReceiveRunnable final
|
||||
: public SocketIORunnable<StreamSocketIO>
|
||||
@ -388,7 +389,7 @@ public:
|
||||
|
||||
MOZ_ASSERT(io->IsConsumerThread());
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
if (NS_WARN_IF(io->IsShutdownOnConsumerThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
@ -428,7 +429,7 @@ StreamSocketIO::GetSocketBase()
|
||||
}
|
||||
|
||||
bool
|
||||
StreamSocketIO::IsShutdownOnMainThread() const
|
||||
StreamSocketIO::IsShutdownOnConsumerThread() const
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
|
||||
@ -442,10 +443,10 @@ StreamSocketIO::IsShutdownOnIOThread() const
|
||||
}
|
||||
|
||||
void
|
||||
StreamSocketIO::ShutdownOnMainThread()
|
||||
StreamSocketIO::ShutdownOnConsumerThread()
|
||||
{
|
||||
MOZ_ASSERT(IsConsumerThread());
|
||||
MOZ_ASSERT(!IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!IsShutdownOnConsumerThread());
|
||||
|
||||
mStreamSocket = nullptr;
|
||||
}
|
||||
@ -498,7 +499,7 @@ public:
|
||||
}
|
||||
|
||||
StreamSocketIO* io = GetIO();
|
||||
if (io->IsShutdownOnMainThread()) {
|
||||
if (io->IsShutdownOnConsumerThread()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -591,7 +592,7 @@ StreamSocket::SendSocketData(UnixSocketIOBuffer* aBuffer)
|
||||
{
|
||||
MOZ_ASSERT(mIO);
|
||||
MOZ_ASSERT(mIO->IsConsumerThread());
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnMainThread());
|
||||
MOZ_ASSERT(!mIO->IsShutdownOnConsumerThread());
|
||||
|
||||
mIO->GetIOLoop()->PostTask(
|
||||
FROM_HERE,
|
||||
@ -611,7 +612,7 @@ StreamSocket::Close()
|
||||
// From this point on, we consider |mIO| as being deleted. We sever
|
||||
// the relationship here so any future calls to |Connect| will create
|
||||
// a new I/O object.
|
||||
mIO->ShutdownOnMainThread();
|
||||
mIO->ShutdownOnConsumerThread();
|
||||
mIO->GetIOLoop()->PostTask(FROM_HERE, new SocketIOShutdownTask(mIO));
|
||||
mIO = nullptr;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
StreamSocket(StreamSocketConsumer* aConsumer, int aIndex);
|
||||
|
||||
/**
|
||||
* Method to be called whenever data is received. Main-thread only.
|
||||
* Method to be called whenever data is received. Consumer-thread only.
|
||||
*
|
||||
* @param aBuffer Data received from the socket.
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ class StreamSocketConsumer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Method to be called whenever data is received. Main-thread only.
|
||||
* Method to be called whenever data is received. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
* @param aBuffer Data received from the socket.
|
||||
@ -30,21 +30,21 @@ public:
|
||||
nsAutoPtr<UnixSocketBuffer>& aBuffer) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket success. Main-thread only.
|
||||
* Callback for socket success. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
virtual void OnConnectSuccess(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket errors. Main-thread only.
|
||||
* Callback for socket errors. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
virtual void OnConnectError(int aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Callback for socket disconnect. Main-thread only.
|
||||
* Callback for socket disconnect. Consumer-thread only.
|
||||
*
|
||||
* @param aIndex The index that has been given to the stream socket.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user