Index: talk/app/webrtc/datachannel.cc |
diff --git a/talk/app/webrtc/datachannel.cc b/talk/app/webrtc/datachannel.cc |
index 690ee65d3b713f9f8ee1257b3e48593aaaefd61e..0252d6580db73911fdf99e290802d0319d5a12ae 100644 |
--- a/talk/app/webrtc/datachannel.cc |
+++ b/talk/app/webrtc/datachannel.cc |
@@ -31,6 +31,7 @@ |
#include "talk/app/webrtc/mediastreamprovider.h" |
#include "talk/app/webrtc/sctputils.h" |
+#include "talk/media/sctp/sctpdataengine.h" |
#include "webrtc/base/logging.h" |
#include "webrtc/base/refcount.h" |
@@ -43,6 +44,42 @@ enum { |
MSG_CHANNELREADY, |
}; |
+bool SctpSidAllocator::AllocateSctpSid(rtc::SSLRole role, int* sid) { |
pthatcher1
2015/10/07 02:50:51
Might as well remove "Sctp" from the method name a
Taylor Brandstetter
2015/10/09 19:54:08
Done.
|
+ int potential_sid = (role == rtc::SSL_CLIENT) ? 0 : 1; |
+ while (!IsSctpSidAvailable(potential_sid)) { |
+ potential_sid += 2; |
+ if (potential_sid > static_cast<int>(cricket::kMaxSctpSid)) { |
+ return false; |
+ } |
+ } |
+ |
+ *sid = potential_sid; |
+ used_sids_.insert(potential_sid); |
+ return true; |
+} |
+ |
+bool SctpSidAllocator::ReserveSctpSid(int sid) { |
+ if (!IsSctpSidAvailable(sid)) { |
+ return false; |
+ } |
+ used_sids_.insert(sid); |
+ return true; |
+} |
+ |
+void SctpSidAllocator::ReleaseSctpSid(int sid) { |
+ auto it = used_sids_.find(sid); |
+ if (it != used_sids_.end()) { |
+ used_sids_.erase(it); |
+ } |
+} |
+ |
+bool SctpSidAllocator::IsSctpSidAvailable(int sid) const { |
+ if (sid < 0 || sid > static_cast<int>(cricket::kMaxSctpSid)) { |
+ return false; |
+ } |
+ return used_sids_.find(sid) == used_sids_.end(); |
+} |
+ |
DataChannel::PacketQueue::PacketQueue() : byte_count_(0) {} |
DataChannel::PacketQueue::~PacketQueue() { |
@@ -361,6 +398,12 @@ void DataChannel::OnDataReceived(cricket::DataChannel* channel, |
} |
} |
+void DataChannel::OnStreamClosedRemotely(uint32 sid) { |
Taylor Brandstetter
2015/10/07 00:26:19
Was previously MediaStreamSignaling::OnRemoteSctpD
|
+ if (data_channel_type_ == cricket::DCT_SCTP && sid == config_.id) { |
+ Close(); |
+ } |
+} |
+ |
void DataChannel::OnChannelReady(bool writable) { |
writable_ = writable; |
if (!writable) { |
@@ -436,13 +479,17 @@ void DataChannel::UpdateState() { |
} |
void DataChannel::SetState(DataState state) { |
- if (state_ == state) |
+ if (state_ == state) { |
return; |
+ } |
state_ = state; |
if (observer_) { |
observer_->OnStateChange(); |
} |
+ if (state_ == kClosed) { |
+ SignalClosed(this); |
+ } |
} |
void DataChannel::DisconnectFromProvider() { |