Bug 1046109: Add |SocketIORequestClosingRunnable|, r=kyle

|SocketIORequestClosingRunnable| notifies the Socket consumer on
the main thread to clean up the Socket I/O object and close the
connection.
This commit is contained in:
Thomas Zimmermann
2014-07-31 13:55:28 +02:00
parent 1758b16fde
commit 177d1e74f6
2 changed files with 30 additions and 28 deletions

View File

@@ -246,7 +246,35 @@ private:
nsAutoPtr<UnixSocketRawData> mData; nsAutoPtr<UnixSocketRawData> mData;
}; };
template <typename T>
class SocketIORequestClosingRunnable MOZ_FINAL : public SocketIORunnable<T>
{
public:
SocketIORequestClosingRunnable(T* aImpl)
: SocketIORunnable<T>(aImpl)
{ }
NS_IMETHOD Run() MOZ_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;
}
SocketConsumerBase* consumer = io->GetConsumer();
MOZ_ASSERT(consumer);
consumer->CloseSocket();
return NS_OK;
}
};
} }
} }

View File

@@ -201,32 +201,6 @@ private:
T* mInstance; T* mInstance;
}; };
class RequestClosingSocketRunnable : public SocketIORunnable<UnixSocketImpl>
{
public:
RequestClosingSocketRunnable(UnixSocketImpl* aImpl)
: SocketIORunnable<UnixSocketImpl>(aImpl)
{ }
NS_IMETHOD Run() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
UnixSocketImpl* impl = GetIO();
if (impl->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;
}
// Start from here, same handling flow as calling CloseSocket() from
// upper layer
impl->mConsumer->CloseSocket();
return NS_OK;
}
};
class UnixSocketImplTask : public CancelableTask class UnixSocketImplTask : public CancelableTask
{ {
public: public:
@@ -594,8 +568,8 @@ UnixSocketImpl::OnSocketCanReceiveWithoutBlocking()
// We're done with our descriptors. Ensure that spurious events don't // We're done with our descriptors. Ensure that spurious events don't
// cause us to end up back here. // cause us to end up back here.
RemoveWatchers(READ_WATCHER|WRITE_WATCHER); RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
nsRefPtr<RequestClosingSocketRunnable> r = nsRefPtr<nsRunnable> r =
new RequestClosingSocketRunnable(this); new SocketIORequestClosingRunnable<UnixSocketImpl>(this);
NS_DispatchToMainThread(r); NS_DispatchToMainThread(r);
return; return;
} }