Bug 805251 - Clean up DataChannel close logic r=mcmanus

This commit is contained in:
Randell Jesup 2013-01-17 05:26:40 -05:00
parent 4b4576db69
commit c5ffbdba65
2 changed files with 36 additions and 45 deletions

View File

@ -910,7 +910,7 @@ DataChannelConnection::SendDeferredMessages()
still_blocked = true;
} else {
// Close the channel, inform the user
Close(channel->mStreamOut);
Close(channel);
}
}
}
@ -1215,18 +1215,6 @@ DataChannelConnection::HandleDataMessage(uint32_t ppid,
}
}
// Called with mLock locked!
void
DataChannel::SendOrQueue(DataChannelOnMessageAvailable *aMessage)
{
if (!mReady &&
(mState == CONNECTING || mState == WAITING_TO_OPEN)) {
mQueuedMessages.AppendElement(aMessage);
} else {
NS_DispatchToMainThread(aMessage);
}
}
// Called with mLock locked!
void
DataChannelConnection::HandleMessage(const void *buffer, size_t length, uint32_t ppid, uint16_t streamIn)
@ -2032,27 +2020,24 @@ DataChannelConnection::SendMsgCommon(uint16_t stream, const nsACString &aMsg,
}
void
DataChannelConnection::Close(uint16_t streamOut)
DataChannelConnection::Close(DataChannel *aChannel)
{
nsRefPtr<DataChannel> channel; // make sure it doesn't go away on us
MOZ_ASSERT(aChannel);
nsRefPtr<DataChannel> channel(aChannel); // make sure it doesn't go away on us
MutexAutoLock lock(mLock);
channel = FindChannelByStreamOut(streamOut);
if (channel) {
LOG(("Connection %p/Channel %p: Closing stream %d",
(void *) channel->mConnection.get(), (void *) channel.get(), streamOut));
if (channel->mState == CLOSED || channel->mState == CLOSING) {
LOG(("Channel already closing/closed (%d)", channel->mState));
return;
}
channel->mBufferedData.Clear();
if (channel->mStreamOut != INVALID_STREAM)
ResetOutgoingStream(channel->mStreamOut);
SendOutgoingStreamReset();
channel->mState = CLOSING;
} else {
LOG(("!!!? no channel when closing stream %d?",streamOut));
LOG(("Connection %p/Channel %p: Closing stream %d",
channel->mConnection.get(), channel.get(), channel->mStreamOut));
if (channel->mState == CLOSED || channel->mState == CLOSING) {
LOG(("Channel already closing/closed (%d)", channel->mState));
return;
}
channel->mBufferedData.Clear();
if (channel->mStreamOut != INVALID_STREAM) {
ResetOutgoingStream(channel->mStreamOut);
SendOutgoingStreamReset();
}
channel->mState = CLOSING;
}
void DataChannelConnection::CloseAll()
@ -2082,8 +2067,14 @@ void DataChannelConnection::CloseAll()
DataChannel::~DataChannel()
{
if (mConnection)
Close();
Close();
}
void
DataChannel::Close()
{
ENSURE_DATACONNECTION;
mConnection->Close(this);
}
// Used when disconnecting from the DataChannelConnection
@ -2103,18 +2094,6 @@ DataChannel::Destroy()
mConnection = nullptr;
}
void
DataChannel::Close()
{
if (mState == CLOSING || mState == CLOSED ||
mStreamOut == INVALID_STREAM) {
return;
}
mState = CLOSING;
ENSURE_DATACONNECTION;
mConnection->Close(mStreamOut);
}
void
DataChannel::SetListener(DataChannelListener *aListener, nsISupports *aContext)
{
@ -2161,4 +2140,16 @@ DataChannel::GetBufferedAmount()
return buffered;
}
// Called with mLock locked!
void
DataChannel::SendOrQueue(DataChannelOnMessageAvailable *aMessage)
{
if (!mReady &&
(mState == CONNECTING || mState == WAITING_TO_OPEN)) {
mQueuedMessages.AppendElement(aMessage);
} else {
NS_DispatchToMainThread(aMessage);
}
}
} // namespace mozilla

View File

@ -138,7 +138,7 @@ public:
DataChannelListener *aListener,
nsISupports *aContext);
void Close(uint16_t stream);
void Close(DataChannel *aChannel);
void CloseAll();
int32_t SendMsg(uint16_t stream, const nsACString &aMsg)