diff --git a/talk/app/webrtc/datachannel.cc b/talk/app/webrtc/datachannel.cc index 952f5bfb6e..6ff0941501 100644 --- a/talk/app/webrtc/datachannel.cc +++ b/talk/app/webrtc/datachannel.cc @@ -215,7 +215,7 @@ bool DataChannel::Send(const DataBuffer& buffer) { return true; } - bool success = SendDataMessage(buffer); + bool success = SendDataMessage(buffer, true); if (data_channel_type_ == cricket::DCT_RTP) { return success; } @@ -461,17 +461,17 @@ void DataChannel::DeliverQueuedReceivedData() { void DataChannel::SendQueuedDataMessages() { ASSERT(was_ever_writable_ && state_ == kOpen); - PacketQueue packet_buffer; - packet_buffer.Swap(&queued_send_data_); - - while (!packet_buffer.Empty()) { - rtc::scoped_ptr buffer(packet_buffer.Front()); - SendDataMessage(*buffer); - packet_buffer.Pop(); + while (!queued_send_data_.Empty()) { + rtc::scoped_ptr buffer(queued_send_data_.Front()); + if (!SendDataMessage(*buffer, false)) { + break; + } + queued_send_data_.Pop(); } } -bool DataChannel::SendDataMessage(const DataBuffer& buffer) { +bool DataChannel::SendDataMessage(const DataBuffer& buffer, + bool queue_if_blocked) { cricket::SendDataParams send_params; if (data_channel_type_ == cricket::DCT_SCTP) { @@ -494,14 +494,26 @@ bool DataChannel::SendDataMessage(const DataBuffer& buffer) { cricket::SendDataResult send_result = cricket::SDR_SUCCESS; bool success = provider_->SendData(send_params, buffer.data, &send_result); - if (!success && data_channel_type_ == cricket::DCT_SCTP) { - if (send_result != cricket::SDR_BLOCK || !QueueSendDataMessage(buffer)) { - LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, " - << "send_result = " << send_result; - Close(); + if (success) { + return true; + } + + if (data_channel_type_ != cricket::DCT_SCTP) { + return false; + } + + if (send_result == cricket::SDR_BLOCK) { + if (!queue_if_blocked || QueueSendDataMessage(buffer)) { + return false; } } - return success; + // Close the channel if the error is not SDR_BLOCK, or if queuing the + // message failed. + LOG(LS_ERROR) << "Closing the DataChannel due to a failure to send data, " + << "send_result = " << send_result; + Close(); + + return false; } bool DataChannel::QueueSendDataMessage(const DataBuffer& buffer) { diff --git a/talk/app/webrtc/datachannel.h b/talk/app/webrtc/datachannel.h index 728d1df90c..1a455b772c 100644 --- a/talk/app/webrtc/datachannel.h +++ b/talk/app/webrtc/datachannel.h @@ -213,7 +213,7 @@ class DataChannel : public DataChannelInterface, void DeliverQueuedReceivedData(); void SendQueuedDataMessages(); - bool SendDataMessage(const DataBuffer& buffer); + bool SendDataMessage(const DataBuffer& buffer, bool queue_if_blocked); bool QueueSendDataMessage(const DataBuffer& buffer); void SendQueuedControlMessages();