Fix assertion failure when closing data channel, and add a unit test.

BUG=4066
R=jiayl@webrtc.org, juberti@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/31109004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7816 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
bemasc@webrtc.org 2014-12-04 23:16:52 +00:00
parent 4b407aa985
commit 9b5467e88d
6 changed files with 19 additions and 10 deletions

View File

@ -441,7 +441,7 @@ void DataChannel::DisconnectFromTransport() {
provider_->DisconnectDataChannel(this);
connected_to_provider_ = false;
if (data_channel_type_ == cricket::DCT_SCTP) {
if (data_channel_type_ == cricket::DCT_SCTP && config_.id >= 0) {
provider_->RemoveSctpDataStream(config_.id);
}
}

View File

@ -54,9 +54,9 @@ class DataChannelProviderInterface {
// Disconnects from the transport signals.
virtual void DisconnectDataChannel(DataChannel* data_channel) = 0;
// Adds the data channel SID to the transport for SCTP.
virtual void AddSctpDataStream(uint32 sid) = 0;
virtual void AddSctpDataStream(int sid) = 0;
// Removes the data channel SID from the transport for SCTP.
virtual void RemoveSctpDataStream(uint32 sid) = 0;
virtual void RemoveSctpDataStream(int sid) = 0;
// Returns true if the transport channel is ready to send data.
virtual bool ReadyToSendData() const = 0;

View File

@ -423,3 +423,10 @@ TEST_F(SctpDataChannelTest, SendEmptyData) {
EXPECT_EQ(webrtc::DataChannelInterface::kOpen,
webrtc_data_channel_->state());
}
// Tests that a channel can be closed without being opened or assigned an sid.
TEST_F(SctpDataChannelTest, NeverOpened) {
provider_.set_transport_available(true);
webrtc_data_channel_->OnTransportChannelCreated();
webrtc_data_channel_->Close();
}

View File

@ -71,7 +71,8 @@ class FakeDataChannelProvider : public webrtc::DataChannelProviderInterface {
connected_channels_.erase(data_channel);
}
virtual void AddSctpDataStream(uint32 sid) OVERRIDE {
virtual void AddSctpDataStream(int sid) OVERRIDE {
ASSERT(sid >= 0);
if (!transport_available_) {
return;
}
@ -79,7 +80,8 @@ class FakeDataChannelProvider : public webrtc::DataChannelProviderInterface {
recv_ssrcs_.insert(sid);
}
virtual void RemoveSctpDataStream(uint32 sid) OVERRIDE {
virtual void RemoveSctpDataStream(int sid) OVERRIDE {
ASSERT(sid >= 0);
send_ssrcs_.erase(sid);
recv_ssrcs_.erase(sid);
}

View File

@ -1136,7 +1136,7 @@ void WebRtcSession::DisconnectDataChannel(DataChannel* webrtc_data_channel) {
data_channel_->SignalDataReceived.disconnect(webrtc_data_channel);
}
void WebRtcSession::AddSctpDataStream(uint32 sid) {
void WebRtcSession::AddSctpDataStream(int sid) {
if (!data_channel_.get()) {
LOG(LS_ERROR) << "AddDataChannelStreams called when data_channel_ is NULL.";
return;
@ -1145,8 +1145,8 @@ void WebRtcSession::AddSctpDataStream(uint32 sid) {
data_channel_->AddSendStream(cricket::StreamParams::CreateLegacy(sid));
}
void WebRtcSession::RemoveSctpDataStream(uint32 sid) {
mediastream_signaling_->RemoveSctpDataChannel(static_cast<int>(sid));
void WebRtcSession::RemoveSctpDataStream(int sid) {
mediastream_signaling_->RemoveSctpDataChannel(sid);
if (!data_channel_.get()) {
LOG(LS_ERROR) << "RemoveDataChannelStreams called when data_channel_ is "

View File

@ -203,8 +203,8 @@ class WebRtcSession : public cricket::BaseSession,
cricket::SendDataResult* result) OVERRIDE;
virtual bool ConnectDataChannel(DataChannel* webrtc_data_channel) OVERRIDE;
virtual void DisconnectDataChannel(DataChannel* webrtc_data_channel) OVERRIDE;
virtual void AddSctpDataStream(uint32 sid) OVERRIDE;
virtual void RemoveSctpDataStream(uint32 sid) OVERRIDE;
virtual void AddSctpDataStream(int sid) OVERRIDE;
virtual void RemoveSctpDataStream(int sid) OVERRIDE;
virtual bool ReadyToSendData() const OVERRIDE;
// Implements DataChannelFactory.