Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel.cc

Issue 1406423008: Stop a session when a new connection becomes writable. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 PortAllocator* allocator) 206 PortAllocator* allocator)
207 : TransportChannelImpl(transport_name, component), 207 : TransportChannelImpl(transport_name, component),
208 transport_(transport), 208 transport_(transport),
209 allocator_(allocator), 209 allocator_(allocator),
210 worker_thread_(rtc::Thread::Current()), 210 worker_thread_(rtc::Thread::Current()),
211 incoming_only_(false), 211 incoming_only_(false),
212 error_(0), 212 error_(0),
213 best_connection_(NULL), 213 best_connection_(NULL),
214 pending_best_connection_(NULL), 214 pending_best_connection_(NULL),
215 sort_dirty_(false), 215 sort_dirty_(false),
216 was_writable_(false),
217 remote_ice_mode_(ICEMODE_FULL), 216 remote_ice_mode_(ICEMODE_FULL),
218 ice_role_(ICEROLE_UNKNOWN), 217 ice_role_(ICEROLE_UNKNOWN),
219 tiebreaker_(0), 218 tiebreaker_(0),
220 remote_candidate_generation_(0), 219 remote_candidate_generation_(0),
221 gathering_state_(kIceGatheringNew), 220 gathering_state_(kIceGatheringNew),
222 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5), 221 check_receiving_delay_(MIN_CHECK_RECEIVING_DELAY * 5),
223 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {} 222 receiving_timeout_(MIN_CHECK_RECEIVING_DELAY * 50) {}
224 223
225 P2PTransportChannel::~P2PTransportChannel() { 224 P2PTransportChannel::~P2PTransportChannel() {
226 ASSERT(worker_thread_ == rtc::Thread::Current()); 225 ASSERT(worker_thread_ == rtc::Thread::Current());
227 226
228 for (size_t i = 0; i < allocator_sessions_.size(); ++i) 227 for (size_t i = 0; i < allocator_sessions_.size(); ++i)
229 delete allocator_sessions_[i]; 228 delete allocator_sessions_[i];
230 } 229 }
231 230
232 // Add the allocator session to our list so that we know which sessions 231 // Add the allocator session to our list so that we know which sessions
233 // are still active. 232 // are still active.
234 void P2PTransportChannel::AddAllocatorSession(PortAllocatorSession* session) { 233 void P2PTransportChannel::AddAllocatorSession(PortAllocatorSession* session) {
234 ASSERT(worker_thread_ == rtc::Thread::Current());
235
235 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size())); 236 session->set_generation(static_cast<uint32_t>(allocator_sessions_.size()));
236 allocator_sessions_.push_back(session); 237 allocator_sessions_.push_back(session);
237 238
238 // We now only want to apply new candidates that we receive to the ports 239 // We now only want to apply new candidates that we receive to the ports
239 // created by this new session because these are replacing those of the 240 // created by this new session because these are replacing those of the
240 // previous sessions. 241 // previous sessions.
241 ports_.clear(); 242 ports_.clear();
242 243
243 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady); 244 session->SignalPortReady.connect(this, &P2PTransportChannel::OnPortReady);
244 session->SignalCandidatesReady.connect( 245 session->SignalCandidatesReady.connect(
245 this, &P2PTransportChannel::OnCandidatesReady); 246 this, &P2PTransportChannel::OnCandidatesReady);
246 session->SignalCandidatesAllocationDone.connect( 247 session->SignalCandidatesAllocationDone.connect(
247 this, &P2PTransportChannel::OnCandidatesAllocationDone); 248 this, &P2PTransportChannel::OnCandidatesAllocationDone);
248 session->StartGettingPorts(); 249 session->StartGettingPorts();
250 is_getting_ports_ = true;
249 } 251 }
250 252
251 void P2PTransportChannel::AddConnection(Connection* connection) { 253 void P2PTransportChannel::AddConnection(Connection* connection) {
252 connections_.push_back(connection); 254 connections_.push_back(connection);
253 connection->set_remote_ice_mode(remote_ice_mode_); 255 connection->set_remote_ice_mode(remote_ice_mode_);
254 connection->set_receiving_timeout(receiving_timeout_); 256 connection->set_receiving_timeout(receiving_timeout_);
255 connection->SignalReadPacket.connect( 257 connection->SignalReadPacket.connect(
256 this, &P2PTransportChannel::OnReadPacket); 258 this, &P2PTransportChannel::OnReadPacket);
257 connection->SignalReadyToSend.connect( 259 connection->SignalReadyToSend.connect(
258 this, &P2PTransportChannel::OnReadyToSend); 260 this, &P2PTransportChannel::OnReadyToSend);
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 bool receiving = false; 1064 bool receiving = false;
1063 for (const Connection* connection : connections_) { 1065 for (const Connection* connection : connections_) {
1064 if (connection->receiving()) { 1066 if (connection->receiving()) {
1065 receiving = true; 1067 receiving = true;
1066 break; 1068 break;
1067 } 1069 }
1068 } 1070 }
1069 set_receiving(receiving); 1071 set_receiving(receiving);
1070 } 1072 }
1071 1073
1072 // We checked the status of our connections and we had at least one that 1074 void P2PTransportChannel::MaybeStopSessions() {
pthatcher1 2015/10/24 00:39:04 Should be MaybeStopPortAllocatorSessions
honghaiz3 2015/10/26 16:47:46 Done.
1073 // was writable, go into the writable state. 1075 if (!is_getting_ports_) {
1074 void P2PTransportChannel::HandleWritable() {
1075 ASSERT(worker_thread_ == rtc::Thread::Current());
1076 if (writable()) {
1077 return; 1076 return;
1078 } 1077 }
1078 is_getting_ports_ = false;
pthatcher1 2015/10/24 00:39:04 How is is_getting_ports_ going to be different tha
honghaiz3 2015/10/26 16:47:46 It is pretty much the same except for the last ses
pthatcher1 2015/10/27 07:24:04 OK, could we make this a little cleaner by doing s
honghaiz3 2015/10/27 16:59:42 The problem is that whenever Continual Gathering i
1079 1079
1080 for (PortAllocatorSession* session : allocator_sessions_) { 1080 for (PortAllocatorSession* session : allocator_sessions_) {
1081 if (!session->IsGettingPorts()) { 1081 if (!session->IsGettingPorts()) {
1082 continue; 1082 continue;
1083 } 1083 }
1084 // If gathering continually, keep the last session running so that it 1084 // If gathering continually, keep the last session running so that it
1085 // will gather candidates if the networks change. 1085 // will gather candidates if the networks change.
1086 if (gather_continually_ && session == allocator_sessions_.back()) { 1086 if (gather_continually_ && session == allocator_sessions_.back()) {
1087 session->ClearGettingPorts(); 1087 session->ClearGettingPorts();
1088 break; 1088 break;
1089 } 1089 }
1090 session->StopGettingPorts(); 1090 session->StopGettingPorts();
1091 } 1091 }
1092 }
1092 1093
1093 was_writable_ = true; 1094 // Go into the writable state and notify upper layer if it was not before.
1094 set_writable(true); 1095 void P2PTransportChannel::HandleWritable() {
1096 ASSERT(worker_thread_ == rtc::Thread::Current());
1097 if (!writable()) {
1098 set_writable(true);
1099 }
1095 } 1100 }
1096 1101
1097 // Notify upper layer about channel not writable state, if it was before. 1102 // Notify upper layer about channel not writable state, if it was before.
1098 void P2PTransportChannel::HandleNotWritable() { 1103 void P2PTransportChannel::HandleNotWritable() {
1099 ASSERT(worker_thread_ == rtc::Thread::Current()); 1104 ASSERT(worker_thread_ == rtc::Thread::Current());
1100 if (was_writable_) { 1105 if (writable()) {
1101 was_writable_ = false;
1102 set_writable(false); 1106 set_writable(false);
1103 } 1107 }
1104 } 1108 }
1105 1109
1106 void P2PTransportChannel::HandleAllTimedOut() { 1110 void P2PTransportChannel::HandleAllTimedOut() {
1107 // Currently we are treating this as channel not writable. 1111 // Currently we are treating this as channel not writable.
1108 HandleNotWritable(); 1112 HandleNotWritable();
1109 } 1113 }
1110 1114
1111 bool P2PTransportChannel::weak() const { 1115 bool P2PTransportChannel::weak() const {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 // connection and role is controlled. 1277 // connection and role is controlled.
1274 if (ice_role_ == ICEROLE_CONTROLLED) { 1278 if (ice_role_ == ICEROLE_CONTROLLED) {
1275 if (connection == pending_best_connection_ && connection->writable()) { 1279 if (connection == pending_best_connection_ && connection->writable()) {
1276 pending_best_connection_ = NULL; 1280 pending_best_connection_ = NULL;
1277 LOG(LS_INFO) << "Switching best connection on controlled side" 1281 LOG(LS_INFO) << "Switching best connection on controlled side"
1278 << " because it's now writable: " << connection->ToString(); 1282 << " because it's now writable: " << connection->ToString();
1279 SwitchBestConnectionTo(connection); 1283 SwitchBestConnectionTo(connection);
1280 } 1284 }
1281 } 1285 }
1282 1286
1287 // May stop the session after at least one connection becomes strong
1288 // after starting to get ports.
1289 if (!connection->weak()) {
pthatcher1 2015/10/24 00:39:04 Can you document more clearly why connection->writ
honghaiz3 2015/10/26 16:47:46 Done.
1290 MaybeStopSessions();
1291 }
1292
1283 // We have to unroll the stack before doing this because we may be changing 1293 // We have to unroll the stack before doing this because we may be changing
1284 // the state of connections while sorting. 1294 // the state of connections while sorting.
1285 RequestSort(); 1295 RequestSort();
1286 } 1296 }
1287 1297
1288 // When a connection is removed, edit it out, and then update our best 1298 // When a connection is removed, edit it out, and then update our best
1289 // connection. 1299 // connection.
1290 void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) { 1300 void P2PTransportChannel::OnConnectionDestroyed(Connection* connection) {
1291 ASSERT(worker_thread_ == rtc::Thread::Current()); 1301 ASSERT(worker_thread_ == rtc::Thread::Current());
1292 1302
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 SignalSentPacket(this, sent_packet); 1374 SignalSentPacket(this, sent_packet);
1365 } 1375 }
1366 1376
1367 void P2PTransportChannel::OnReadyToSend(Connection* connection) { 1377 void P2PTransportChannel::OnReadyToSend(Connection* connection) {
1368 if (connection == best_connection_ && writable()) { 1378 if (connection == best_connection_ && writable()) {
1369 SignalReadyToSend(this); 1379 SignalReadyToSend(this);
1370 } 1380 }
1371 } 1381 }
1372 1382
1373 } // namespace cricket 1383 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698