mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 15:55:16 +00:00
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:
parent
fee8753bfe
commit
1cb02024c4
@ -246,7 +246,35 @@ private:
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -201,32 +201,6 @@ private:
|
||||
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
|
||||
{
|
||||
public:
|
||||
@ -594,8 +568,8 @@ UnixSocketImpl::OnSocketCanReceiveWithoutBlocking()
|
||||
// We're done with our descriptors. Ensure that spurious events don't
|
||||
// cause us to end up back here.
|
||||
RemoveWatchers(READ_WATCHER|WRITE_WATCHER);
|
||||
nsRefPtr<RequestClosingSocketRunnable> r =
|
||||
new RequestClosingSocketRunnable(this);
|
||||
nsRefPtr<nsRunnable> r =
|
||||
new SocketIORequestClosingRunnable<UnixSocketImpl>(this);
|
||||
NS_DispatchToMainThread(r);
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user