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:
@@ -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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user