From 5bcb6a6ac500f43b578b44020f480132abbc3a61 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 31 Jul 2014 09:29:18 +0200 Subject: [PATCH] Bug 1046109: Add |SocketIOReceiveRunnable|, r=kyle |SocketIOReceiveRunnable| sends received data from the Socket I/O object on the I/O thread to the Socket consumer on the main thread. --- ipc/unixsocket/SocketBase.h | 39 +++++++++++++++++++++++++++++++++++ ipc/unixsocket/UnixSocket.cpp | 35 ++----------------------------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/ipc/unixsocket/SocketBase.h b/ipc/unixsocket/SocketBase.h index 83484290503..510148d2a51 100644 --- a/ipc/unixsocket/SocketBase.h +++ b/ipc/unixsocket/SocketBase.h @@ -209,6 +209,45 @@ private: SocketEvent mEvent; }; +/* |SocketReceiveRunnable| transfers data received on the I/O thread + * to the consumer on the main thread. + */ +template +class SocketIOReceiveRunnable MOZ_FINAL : public SocketIORunnable +{ +public: + SocketIOReceiveRunnable(T* aIO, UnixSocketRawData* aData) + : SocketIORunnable(aIO) + , mData(aData) + { } + + NS_IMETHOD Run() MOZ_OVERRIDE + { + MOZ_ASSERT(NS_IsMainThread()); + + T* io = SocketIORunnable::GetIO(); + + if (io->IsShutdownOnMainThread()) { + NS_WARNING("mConsumer is null, aborting receive!"); + // 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->ReceiveSocketData(mData); + + return NS_OK; + } + +private: + nsAutoPtr mData; +}; + + + } } diff --git a/ipc/unixsocket/UnixSocket.cpp b/ipc/unixsocket/UnixSocket.cpp index 0cd23efa35f..0b29de066aa 100644 --- a/ipc/unixsocket/UnixSocket.cpp +++ b/ipc/unixsocket/UnixSocket.cpp @@ -201,37 +201,6 @@ private: T* mInstance; }; -class SocketReceiveRunnable : public SocketIORunnable -{ -public: - SocketReceiveRunnable(UnixSocketImpl* aImpl, UnixSocketRawData* aData) - : SocketIORunnable(aImpl) - , mRawData(aData) - { - MOZ_ASSERT(aData); - } - - NS_IMETHOD Run() MOZ_OVERRIDE - { - MOZ_ASSERT(NS_IsMainThread()); - - UnixSocketImpl* impl = GetIO(); - - if (impl->IsShutdownOnMainThread()) { - NS_WARNING("mConsumer is null, aborting receive!"); - // 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; - } - - MOZ_ASSERT(impl->mConsumer); - impl->mConsumer->ReceiveSocketData(mRawData); - return NS_OK; - } -private: - nsAutoPtr mRawData; -}; - class RequestClosingSocketRunnable : public SocketIORunnable { public: @@ -638,8 +607,8 @@ UnixSocketImpl::OnSocketCanReceiveWithoutBlocking() #endif incoming->mSize = ret; - nsRefPtr r = - new SocketReceiveRunnable(this, incoming.forget()); + nsRefPtr r = + new SocketIOReceiveRunnable(this, incoming.forget()); NS_DispatchToMainThread(r); // If ret is less than MAX_READ_SIZE, there's no