mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
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:
parent
6999dd655b
commit
f1e1ede770
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -21,7 +21,7 @@ namespace ipc {
|
||||
|
||||
class StreamSocketIO final
|
||||
: public UnixSocketWatcher
|
||||
, protected DataSocketIO
|
||||
, public DataSocketIO
|
||||
, public ConnectionOrientedSocketIO
|
||||
{
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user