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.
This commit is contained in:
Thomas Zimmermann 2014-07-31 09:29:18 +02:00
parent f7d3ad8087
commit 5bcb6a6ac5
2 changed files with 41 additions and 33 deletions

View File

@ -209,6 +209,45 @@ private:
SocketEvent mEvent;
};
/* |SocketReceiveRunnable| transfers data received on the I/O thread
* to the consumer on the main thread.
*/
template <typename T>
class SocketIOReceiveRunnable MOZ_FINAL : public SocketIORunnable<T>
{
public:
SocketIOReceiveRunnable(T* aIO, UnixSocketRawData* aData)
: SocketIORunnable<T>(aIO)
, mData(aData)
{ }
NS_IMETHOD Run() MOZ_OVERRIDE
{
MOZ_ASSERT(NS_IsMainThread());
T* io = SocketIORunnable<T>::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<UnixSocketRawData> mData;
};
}
}

View File

@ -201,37 +201,6 @@ private:
T* mInstance;
};
class SocketReceiveRunnable : public SocketIORunnable<UnixSocketImpl>
{
public:
SocketReceiveRunnable(UnixSocketImpl* aImpl, UnixSocketRawData* aData)
: SocketIORunnable<UnixSocketImpl>(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<UnixSocketRawData> mRawData;
};
class RequestClosingSocketRunnable : public SocketIORunnable<UnixSocketImpl>
{
public:
@ -638,8 +607,8 @@ UnixSocketImpl::OnSocketCanReceiveWithoutBlocking()
#endif
incoming->mSize = ret;
nsRefPtr<SocketReceiveRunnable> r =
new SocketReceiveRunnable(this, incoming.forget());
nsRefPtr<nsRunnable> r =
new SocketIOReceiveRunnable<UnixSocketImpl>(this, incoming.forget());
NS_DispatchToMainThread(r);
// If ret is less than MAX_READ_SIZE, there's no