Bug 1159209: Remove template parameters from |SocketIORequestClosingRunnable|, r=kmachulis

This patch removes the template parameters from
|SocketIORequestClosingRunnable| and moves its methods into
the C++ source file. All users have been adapted.
This commit is contained in:
Thomas Zimmermann 2015-04-29 11:19:28 +02:00
parent 6999dd655b
commit f1e1ede770
7 changed files with 47 additions and 42 deletions

View File

@ -43,7 +43,7 @@ EnsureBluetoothSocketHalLoad()
}
class mozilla::dom::bluetooth::DroidSocketImpl : public ipc::UnixFdWatcher
, protected DataSocketIO
, public DataSocketIO
{
public:
/* The connection status in DroidSocketImpl indicates the current

View File

@ -25,7 +25,7 @@ static const size_t MAX_READ_SIZE = 1 << 16;
class BluetoothSocket::BluetoothSocketIO final
: public UnixSocketWatcher
, protected DataSocketIO
, public DataSocketIO
{
public:
BluetoothSocketIO(MessageLoop* mIOLoop,

View File

@ -403,15 +403,11 @@ BluetoothDaemonConnectionIO::ReceiveData(int aFd)
ssize_t res = mPDU->Receive(aFd);
if (res < 0) {
/* an I/O error occured */
nsRefPtr<nsRunnable> r =
new SocketIORequestClosingRunnable<BluetoothDaemonConnectionIO>(this);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this));
return -1;
} else if (!res) {
/* EOF or peer shut down sending */
nsRefPtr<nsRunnable> r =
new SocketIORequestClosingRunnable<BluetoothDaemonConnectionIO>(this);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(this));
return 0;
}

View File

@ -95,8 +95,7 @@ public:
nsresult rv = QueryReceiveBuffer(&incoming);
if (NS_FAILED(rv)) {
/* an error occured */
nsRefPtr<nsRunnable> r = new SocketIORequestClosingRunnable<T>(aIO);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO));
return -1;
}
@ -104,14 +103,12 @@ public:
if (res < 0) {
/* an I/O error occured */
DiscardBuffer();
nsRefPtr<nsRunnable> r = new SocketIORequestClosingRunnable<T>(aIO);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO));
return -1;
} else if (!res) {
/* EOF or peer shut down sending */
DiscardBuffer();
nsRefPtr<nsRunnable> r = new SocketIORequestClosingRunnable<T>(aIO);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO));
return 0;
}
@ -138,8 +135,7 @@ public:
ssize_t res = outgoing->Send(aFd);
if (res < 0) {
/* an I/O error occured */
nsRefPtr<nsRunnable> r = new SocketIORequestClosingRunnable<T>(aIO);
NS_DispatchToMainThread(r);
NS_DispatchToMainThread(new SocketIORequestClosingRunnable(aIO));
return NS_ERROR_FAILURE;
} else if (!res && outgoing->GetSize()) {
/* I/O is currently blocked; try again later */

View File

@ -315,5 +315,35 @@ SocketIOEventRunnable::Run()
return NS_OK;
}
//
// SocketIORequestClosingRunnable
//
SocketIORequestClosingRunnable::SocketIORequestClosingRunnable(
SocketIOBase* aIO)
: SocketIORunnable<SocketIOBase>(aIO)
{ }
NS_METHOD
SocketIORequestClosingRunnable::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);
socketBase->CloseSocket();
return NS_OK;
}
}
}

View File

@ -394,34 +394,17 @@ private:
SocketEvent mEvent;
};
template <typename T>
class SocketIORequestClosingRunnable final : public SocketIORunnable<T>
/**
* |SocketIORequestClosingRunnable| closes an instance of |SocketBase|
* to the main thread.
*/
class SocketIORequestClosingRunnable final
: public SocketIORunnable<SocketIOBase>
{
public:
SocketIORequestClosingRunnable(T* aImpl)
: SocketIORunnable<T>(aImpl)
{ }
SocketIORequestClosingRunnable(SocketIOBase* aIO);
NS_IMETHOD Run() override
{
MOZ_ASSERT(NS_IsMainThread());
T* io = SocketIORunnable<T>::GetIO();
if (io->IsShutdownOnMainThread()) {
NS_WARNING("CloseSocket has already been called!");
// 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);
base->CloseSocket();
return NS_OK;
}
NS_IMETHOD Run() override;
};
/* |SocketIODeleteInstanceRunnable| deletes an object on the main thread.

View File

@ -21,7 +21,7 @@ namespace ipc {
class StreamSocketIO final
: public UnixSocketWatcher
, protected DataSocketIO
, public DataSocketIO
, public ConnectionOrientedSocketIO
{
public: