mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1159209: Remove template parameters from |SocketIOEventRunnable|, r=kmachulis
This patch removes the template parameters from |SocketIOEventRunnable| and moves its methods into the C++ source file. All users have been adapted.
This commit is contained in:
parent
5c10976f50
commit
6999dd655b
@ -91,13 +91,13 @@ public:
|
||||
AddWatchers(WRITE_WATCHER, false);
|
||||
}
|
||||
|
||||
bool IsShutdownOnMainThread()
|
||||
bool IsShutdownOnMainThread() const override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
return mConsumer == nullptr;
|
||||
}
|
||||
|
||||
bool IsShutdownOnIOThread()
|
||||
bool IsShutdownOnIOThread() const
|
||||
{
|
||||
return mShuttingDownOnIOThread;
|
||||
}
|
||||
@ -144,7 +144,7 @@ public:
|
||||
return GetBluetoothSocket();
|
||||
}
|
||||
|
||||
SocketBase* GetSocketBase()
|
||||
SocketBase* GetSocketBase() override
|
||||
{
|
||||
return GetDataSocket();
|
||||
}
|
||||
@ -310,10 +310,8 @@ DroidSocketImpl::Accept(int aFd)
|
||||
SetFd(aFd);
|
||||
mConnectionStatus = SOCKET_IS_CONNECTED;
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<DroidSocketImpl>(
|
||||
this, SocketIOEventRunnable<DroidSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -499,10 +497,8 @@ DroidSocketImpl::OnSocketCanConnectWithoutBlocking(int aFd)
|
||||
|
||||
mConnectionStatus = SOCKET_IS_CONNECTED;
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<DroidSocketImpl>(
|
||||
this, SocketIOEventRunnable<DroidSocketImpl>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
|
@ -38,12 +38,12 @@ public:
|
||||
|
||||
BluetoothSocket* GetBluetoothSocket();
|
||||
DataSocket* GetDataSocket();
|
||||
SocketBase* GetSocketBase();
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
// Shutdown state
|
||||
//
|
||||
|
||||
bool IsShutdownOnMainThread() const;
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
void ShutdownOnMainThread();
|
||||
|
||||
bool IsShutdownOnIOThread() const;
|
||||
@ -352,10 +352,8 @@ BluetoothSocket::BluetoothSocketIO::OnAccepted(
|
||||
}
|
||||
SetSocket(aFd, SOCKET_IS_CONNECTED);
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<BluetoothSocketIO>(
|
||||
this, SocketIOEventRunnable<BluetoothSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -381,10 +379,8 @@ BluetoothSocket::BluetoothSocketIO::OnConnected()
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<BluetoothSocketIO>(
|
||||
this, SocketIOEventRunnable<BluetoothSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -457,11 +453,9 @@ BluetoothSocket::BluetoothSocketIO::FireSocketError()
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<BluetoothSocketIO>(
|
||||
this, SocketIOEventRunnable<BluetoothSocketIO>::CONNECT_ERROR);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR));
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -192,6 +192,7 @@ BluetoothDaemonPDUConsumer::~BluetoothDaemonPDUConsumer()
|
||||
//
|
||||
|
||||
class BluetoothDaemonConnectionIO final : public UnixSocketWatcher
|
||||
, public SocketIOBase
|
||||
, public ConnectionOrientedSocketIO
|
||||
{
|
||||
public:
|
||||
@ -478,11 +479,8 @@ BluetoothDaemonConnectionIO::OnConnected()
|
||||
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
|
||||
MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTED);
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<BluetoothDaemonConnectionIO>(
|
||||
this,
|
||||
SocketIOEventRunnable<BluetoothDaemonConnectionIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -501,11 +499,8 @@ BluetoothDaemonConnectionIO::OnError(const char* aFunction, int aErrno)
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<BluetoothDaemonConnectionIO>(
|
||||
this,
|
||||
SocketIOEventRunnable<BluetoothDaemonConnectionIO>::CONNECT_ERROR);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR));
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -33,12 +33,12 @@ public:
|
||||
|
||||
void GetSocketAddr(nsAString& aAddrStr) const;
|
||||
DataSocket* GetDataSocket();
|
||||
SocketBase* GetSocketBase();
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
// Shutdown state
|
||||
//
|
||||
|
||||
bool IsShutdownOnMainThread() const;
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
void ShutdownOnMainThread();
|
||||
|
||||
bool IsShutdownOnIOThread() const;
|
||||
@ -258,10 +258,8 @@ ListenSocketIO::OnListening()
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
|
||||
/* We signal a successful 'connection' to a local address for listening. */
|
||||
nsRefPtr<nsRunnable> runnable =
|
||||
new SocketIOEventRunnable<ListenSocketIO>(
|
||||
this, SocketIOEventRunnable<ListenSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(runnable);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
}
|
||||
|
||||
void
|
||||
@ -282,11 +280,8 @@ ListenSocketIO::FireSocketError()
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<ListenSocketIO>(
|
||||
this, SocketIOEventRunnable<ListenSocketIO>::CONNECT_ERROR);
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR));
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -278,5 +278,42 @@ SocketIOBase::SocketIOBase()
|
||||
SocketIOBase::~SocketIOBase()
|
||||
{ }
|
||||
|
||||
//
|
||||
// SocketIOEventRunnable
|
||||
//
|
||||
|
||||
SocketIOEventRunnable::SocketIOEventRunnable(SocketIOBase* aIO,
|
||||
SocketEvent aEvent)
|
||||
: SocketIORunnable<SocketIOBase>(aIO)
|
||||
, mEvent(aEvent)
|
||||
{ }
|
||||
|
||||
NS_METHOD
|
||||
SocketIOEventRunnable::Run()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
SocketIOBase* io = SocketIORunnable<SocketIOBase>::GetIO();
|
||||
|
||||
if (NS_WARN_IF(io->IsShutdownOnMainThread())) {
|
||||
// Since we've already explicitly closed and the close
|
||||
// happened before this, this isn't really an error.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
SocketBase* socketBase = io->GetSocketBase();
|
||||
MOZ_ASSERT(socketBase);
|
||||
|
||||
if (mEvent == CONNECT_SUCCESS) {
|
||||
socketBase->NotifySuccess();
|
||||
} else if (mEvent == CONNECT_ERROR) {
|
||||
socketBase->NotifyError();
|
||||
} else if (mEvent == DISCONNECT) {
|
||||
socketBase->NotifyDisconnect();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -310,6 +310,39 @@ private:
|
||||
uint32_t mConnectDelayMs;
|
||||
};
|
||||
|
||||
//
|
||||
// SocketIOBase
|
||||
//
|
||||
|
||||
/**
|
||||
* |SocketIOBase| is a base class for Socket I/O classes that
|
||||
* perform operations on the I/O thread.
|
||||
*/
|
||||
class SocketIOBase
|
||||
{
|
||||
public:
|
||||
virtual ~SocketIOBase();
|
||||
|
||||
/**
|
||||
* Implemented by socket I/O classes to return the current instance of
|
||||
* |SocketBase|.
|
||||
*
|
||||
* @return The current instance of |SocketBase|
|
||||
*/
|
||||
virtual SocketBase* GetSocketBase() = 0;
|
||||
|
||||
/**
|
||||
* Implemented by socket I/O classes to signal that socket class has
|
||||
* been shut down.
|
||||
*
|
||||
* @return True if the socket class has been shut down, false otherwise.
|
||||
*/
|
||||
virtual bool IsShutdownOnMainThread() const = 0;
|
||||
|
||||
protected:
|
||||
SocketIOBase();
|
||||
};
|
||||
|
||||
//
|
||||
// Socket I/O runnables
|
||||
//
|
||||
@ -340,11 +373,11 @@ private:
|
||||
T* mIO;
|
||||
};
|
||||
|
||||
/* |SocketIOEventRunnable| reports the connection state on the
|
||||
* I/O thrad back to the main thread.
|
||||
/**
|
||||
* |SocketIOEventRunnable| reports the connection state on the
|
||||
* I/O thread back to the main thread.
|
||||
*/
|
||||
template <typename T>
|
||||
class SocketIOEventRunnable final : public SocketIORunnable<T>
|
||||
class SocketIOEventRunnable final : public SocketIORunnable<SocketIOBase>
|
||||
{
|
||||
public:
|
||||
enum SocketEvent {
|
||||
@ -353,37 +386,9 @@ public:
|
||||
DISCONNECT
|
||||
};
|
||||
|
||||
SocketIOEventRunnable(T* aIO, SocketEvent e)
|
||||
: SocketIORunnable<T>(aIO)
|
||||
, mEvent(e)
|
||||
{ }
|
||||
SocketIOEventRunnable(SocketIOBase* aIO, SocketEvent aEvent);
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
T* io = SocketIORunnable<T>::GetIO();
|
||||
|
||||
if (io->IsShutdownOnMainThread()) {
|
||||
NS_WARNING("I/O consumer has already been closed!");
|
||||
// Since we've already explicitly closed and the close happened before
|
||||
// this, this isn't really an error. Since we've warned, return OK.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
SocketBase* base = io->GetSocketBase();
|
||||
MOZ_ASSERT(base);
|
||||
|
||||
if (mEvent == CONNECT_SUCCESS) {
|
||||
base->NotifySuccess();
|
||||
} else if (mEvent == CONNECT_ERROR) {
|
||||
base->NotifyError();
|
||||
} else if (mEvent == DISCONNECT) {
|
||||
base->NotifyDisconnect();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
private:
|
||||
SocketEvent mEvent;
|
||||
@ -440,23 +445,6 @@ private:
|
||||
nsAutoPtr<T> mInstance;
|
||||
};
|
||||
|
||||
//
|
||||
// SocketIOBase
|
||||
//
|
||||
|
||||
/**
|
||||
* |SocketIOBase| is a base class for Socket I/O classes that
|
||||
* perform operations on the I/O thread.
|
||||
*/
|
||||
class SocketIOBase
|
||||
{
|
||||
public:
|
||||
virtual ~SocketIOBase();
|
||||
|
||||
protected:
|
||||
SocketIOBase();
|
||||
};
|
||||
|
||||
//
|
||||
// Socket I/O tasks
|
||||
//
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
|
||||
StreamSocket* GetStreamSocket();
|
||||
DataSocket* GetDataSocket();
|
||||
SocketBase* GetSocketBase();
|
||||
SocketBase* GetSocketBase() override;
|
||||
|
||||
// StreamSocketIOBase
|
||||
//
|
||||
@ -55,7 +55,7 @@ public:
|
||||
// Shutdown state
|
||||
//
|
||||
|
||||
bool IsShutdownOnMainThread() const;
|
||||
bool IsShutdownOnMainThread() const override;
|
||||
void ShutdownOnMainThread();
|
||||
|
||||
bool IsShutdownOnIOThread() const;
|
||||
@ -303,11 +303,8 @@ StreamSocketIO::Accept(int aFd,
|
||||
mAddrSize = aAddrLen;
|
||||
|
||||
// Signal success
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<StreamSocketIO>(
|
||||
this, SocketIOEventRunnable<StreamSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -377,10 +374,8 @@ StreamSocketIO::OnAccepted(int aFd,
|
||||
}
|
||||
SetSocket(aFd, SOCKET_IS_CONNECTED);
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<StreamSocketIO>(
|
||||
this, SocketIOEventRunnable<StreamSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -406,10 +401,8 @@ StreamSocketIO::OnConnected()
|
||||
return;
|
||||
}
|
||||
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<StreamSocketIO>(
|
||||
this, SocketIOEventRunnable<StreamSocketIO>::CONNECT_SUCCESS);
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_SUCCESS));
|
||||
|
||||
AddWatchers(READ_WATCHER, true);
|
||||
if (HasPendingData()) {
|
||||
@ -475,11 +468,8 @@ StreamSocketIO::FireSocketError()
|
||||
Close();
|
||||
|
||||
// Tell the main thread we've errored
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIOEventRunnable<StreamSocketIO>(
|
||||
this, SocketIOEventRunnable<StreamSocketIO>::CONNECT_ERROR);
|
||||
|
||||
NS_DispatchToMainThread(r);
|
||||
NS_DispatchToMainThread(
|
||||
new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR));
|
||||
}
|
||||
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user