OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 const ServerAddresses& stun_servers, | 33 const ServerAddresses& stun_servers, |
34 const std::vector<RelayServerConfig>& turn_servers, | 34 const std::vector<RelayServerConfig>& turn_servers, |
35 int candidate_pool_size, | 35 int candidate_pool_size, |
36 bool prune_turn_ports) { | 36 bool prune_turn_ports) { |
37 bool ice_servers_changed = | 37 bool ice_servers_changed = |
38 (stun_servers != stun_servers_ || turn_servers != turn_servers_); | 38 (stun_servers != stun_servers_ || turn_servers != turn_servers_); |
39 stun_servers_ = stun_servers; | 39 stun_servers_ = stun_servers; |
40 turn_servers_ = turn_servers; | 40 turn_servers_ = turn_servers; |
41 prune_turn_ports_ = prune_turn_ports; | 41 prune_turn_ports_ = prune_turn_ports; |
42 | 42 |
43 bool candidate_pool_drain_began = | 43 if (candidate_pool_frozen_) { |
44 static_cast<int>(pooled_sessions_.size()) != candidate_pool_size_; | 44 if (candidate_pool_size != candidate_pool_size_) { |
45 if (candidate_pool_drain_began && | 45 LOG(LS_ERROR) << "Trying to change candidate pool size after pool was " |
46 candidate_pool_size != candidate_pool_size_) { | 46 << "frozen."; |
47 LOG(LS_ERROR) << "Trying to change candidate pool size after pool started " | 47 return false; |
48 "to be drained."; | 48 } |
49 return false; | 49 return true; |
50 } | 50 } |
| 51 |
51 if (candidate_pool_size < 0) { | 52 if (candidate_pool_size < 0) { |
52 LOG(LS_ERROR) << "Can't set negative pool size."; | 53 LOG(LS_ERROR) << "Can't set negative pool size."; |
53 return false; | 54 return false; |
54 } | 55 } |
| 56 |
55 candidate_pool_size_ = candidate_pool_size; | 57 candidate_pool_size_ = candidate_pool_size; |
56 | 58 |
57 // If sessions need to be recreated, only recreate as many as the current | |
58 // pool size if the pool has begun to be drained. | |
59 int sessions_needed = candidate_pool_drain_began | |
60 ? static_cast<int>(pooled_sessions_.size()) | |
61 : candidate_pool_size_; | |
62 | |
63 // If ICE servers changed, throw away any existing pooled sessions and create | 59 // If ICE servers changed, throw away any existing pooled sessions and create |
64 // new ones. | 60 // new ones. |
65 if (ice_servers_changed) { | 61 if (ice_servers_changed) { |
66 pooled_sessions_.clear(); | 62 pooled_sessions_.clear(); |
67 } | 63 } |
68 | 64 |
69 // If |sessions_needed| is less than the number of pooled sessions, get rid | 65 // If |candidate_pool_size_| is less than the number of pooled sessions, get |
70 // of the extras. | 66 // rid of the extras. |
71 while (sessions_needed < static_cast<int>(pooled_sessions_.size())) { | 67 while (candidate_pool_size_ < static_cast<int>(pooled_sessions_.size())) { |
72 pooled_sessions_.front().reset(nullptr); | 68 pooled_sessions_.front().reset(nullptr); |
73 pooled_sessions_.pop_front(); | 69 pooled_sessions_.pop_front(); |
74 } | 70 } |
75 | 71 |
76 // If |sessions_needed| is greater than the number of pooled sessions, | 72 // If |candidate_pool_size_| is greater than the number of pooled sessions, |
77 // create new sessions. | 73 // create new sessions. |
78 while (static_cast<int>(pooled_sessions_.size()) < sessions_needed) { | 74 while (static_cast<int>(pooled_sessions_.size()) < candidate_pool_size_) { |
79 PortAllocatorSession* pooled_session = CreateSessionInternal("", 0, "", ""); | 75 PortAllocatorSession* pooled_session = CreateSessionInternal("", 0, "", ""); |
80 pooled_session->StartGettingPorts(); | 76 pooled_session->StartGettingPorts(); |
81 pooled_sessions_.push_back( | 77 pooled_sessions_.push_back( |
82 std::unique_ptr<PortAllocatorSession>(pooled_session)); | 78 std::unique_ptr<PortAllocatorSession>(pooled_session)); |
83 } | 79 } |
84 return true; | 80 return true; |
85 } | 81 } |
86 | 82 |
87 std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession( | 83 std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession( |
88 const std::string& content_name, | 84 const std::string& content_name, |
(...skipping 26 matching lines...) Expand all Loading... |
115 return ret; | 111 return ret; |
116 } | 112 } |
117 | 113 |
118 const PortAllocatorSession* PortAllocator::GetPooledSession() const { | 114 const PortAllocatorSession* PortAllocator::GetPooledSession() const { |
119 if (pooled_sessions_.empty()) { | 115 if (pooled_sessions_.empty()) { |
120 return nullptr; | 116 return nullptr; |
121 } | 117 } |
122 return pooled_sessions_.front().get(); | 118 return pooled_sessions_.front().get(); |
123 } | 119 } |
124 | 120 |
| 121 void PortAllocator::FreezeCandidatePool() { |
| 122 candidate_pool_frozen_ = true; |
| 123 } |
| 124 |
| 125 void PortAllocator::DiscardPooledSessions() { |
| 126 pooled_sessions_.clear(); |
| 127 } |
| 128 |
125 } // namespace cricket | 129 } // namespace cricket |
OLD | NEW |