OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/dns_socket_pool.h" | 5 #include "net/dns/dns_socket_pool.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 180 } |
181 | 181 |
182 scoped_ptr<DatagramClientSocket> DefaultDnsSocketPool::AllocateSocket( | 182 scoped_ptr<DatagramClientSocket> DefaultDnsSocketPool::AllocateSocket( |
183 unsigned server_index) { | 183 unsigned server_index) { |
184 DCHECK_LT(server_index, pools_.size()); | 184 DCHECK_LT(server_index, pools_.size()); |
185 SocketVector& pool = pools_[server_index]; | 185 SocketVector& pool = pools_[server_index]; |
186 | 186 |
187 FillPool(server_index, kAllocateMinSize); | 187 FillPool(server_index, kAllocateMinSize); |
188 if (pool.size() == 0) { | 188 if (pool.size() == 0) { |
189 LOG(WARNING) << "No DNS sockets available in pool " << server_index << "!"; | 189 LOG(WARNING) << "No DNS sockets available in pool " << server_index << "!"; |
190 return scoped_ptr<DatagramClientSocket>(NULL); | 190 return scoped_ptr<DatagramClientSocket>(); |
191 } | 191 } |
192 | 192 |
193 if (pool.size() < kAllocateMinSize) { | 193 if (pool.size() < kAllocateMinSize) { |
194 LOG(WARNING) << "Low DNS port entropy: wanted " << kAllocateMinSize | 194 LOG(WARNING) << "Low DNS port entropy: wanted " << kAllocateMinSize |
195 << " sockets to choose from, but only have " << pool.size() | 195 << " sockets to choose from, but only have " << pool.size() |
196 << " in pool " << server_index << "."; | 196 << " in pool " << server_index << "."; |
197 } | 197 } |
198 | 198 |
199 unsigned socket_index = base::RandInt(0, pool.size() - 1); | 199 unsigned socket_index = base::RandInt(0, pool.size() - 1); |
200 DatagramClientSocket* socket = pool[socket_index]; | 200 DatagramClientSocket* socket = pool[socket_index]; |
(...skipping 24 matching lines...) Expand all Loading... |
225 for (unsigned pool_index = pool.size(); pool_index < size; ++pool_index) { | 225 for (unsigned pool_index = pool.size(); pool_index < size; ++pool_index) { |
226 DatagramClientSocket* socket = | 226 DatagramClientSocket* socket = |
227 CreateConnectedSocket(server_index).release(); | 227 CreateConnectedSocket(server_index).release(); |
228 if (!socket) | 228 if (!socket) |
229 break; | 229 break; |
230 pool.push_back(socket); | 230 pool.push_back(socket); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 } // namespace net | 234 } // namespace net |
OLD | NEW |