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/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 #include "net/base/rand_callback.h" | 13 #include "net/base/rand_callback.h" |
13 #include "net/socket/client_socket_factory.h" | 14 #include "net/socket/client_socket_factory.h" |
| 15 #include "net/socket/stream_socket.h" |
14 #include "net/udp/datagram_client_socket.h" | 16 #include "net/udp/datagram_client_socket.h" |
15 | 17 |
16 namespace net { | 18 namespace net { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // When we initialize the SocketPool, we allocate kInitialPoolSize sockets. | 22 // When we initialize the SocketPool, we allocate kInitialPoolSize sockets. |
21 // When we allocate a socket, we ensure we have at least kAllocateMinSize | 23 // When we allocate a socket, we ensure we have at least kAllocateMinSize |
22 // sockets to choose from. When we free a socket, we retain it if we have | 24 // sockets to choose from. When we free a socket, we retain it if we have |
23 // less than kRetainMaxSize sockets in the pool. | 25 // less than kRetainMaxSize sockets in the pool. |
(...skipping 26 matching lines...) Expand all Loading... |
50 const std::vector<IPEndPoint>* nameservers, | 52 const std::vector<IPEndPoint>* nameservers, |
51 NetLog* net_log) { | 53 NetLog* net_log) { |
52 DCHECK(nameservers); | 54 DCHECK(nameservers); |
53 DCHECK(!initialized_); | 55 DCHECK(!initialized_); |
54 | 56 |
55 net_log_ = net_log; | 57 net_log_ = net_log; |
56 nameservers_ = nameservers; | 58 nameservers_ = nameservers; |
57 initialized_ = true; | 59 initialized_ = true; |
58 } | 60 } |
59 | 61 |
| 62 scoped_ptr<StreamSocket> DnsSocketPool::CreateTCPSocket( |
| 63 unsigned server_index, |
| 64 const NetLog::Source& source) { |
| 65 DCHECK_LT(server_index, nameservers_->size()); |
| 66 |
| 67 return scoped_ptr<StreamSocket>( |
| 68 socket_factory_->CreateTransportClientSocket( |
| 69 AddressList((*nameservers_)[server_index]), net_log_, source)); |
| 70 } |
| 71 |
60 scoped_ptr<DatagramClientSocket> DnsSocketPool::CreateConnectedSocket( | 72 scoped_ptr<DatagramClientSocket> DnsSocketPool::CreateConnectedSocket( |
61 unsigned server_index) { | 73 unsigned server_index) { |
62 DCHECK_LT(server_index, nameservers_->size()); | 74 DCHECK_LT(server_index, nameservers_->size()); |
63 | 75 |
64 scoped_ptr<DatagramClientSocket> socket; | 76 scoped_ptr<DatagramClientSocket> socket; |
65 | 77 |
66 NetLog::Source no_source; | 78 NetLog::Source no_source; |
67 socket.reset(socket_factory_->CreateDatagramClientSocket( | 79 socket.reset(socket_factory_->CreateDatagramClientSocket( |
68 kBindType, base::Bind(&base::RandInt), net_log_, no_source)); | 80 kBindType, base::Bind(&base::RandInt), net_log_, no_source)); |
69 | 81 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 for (unsigned pool_index = pool.size(); pool_index < size; ++pool_index) { | 225 for (unsigned pool_index = pool.size(); pool_index < size; ++pool_index) { |
214 DatagramClientSocket* socket = | 226 DatagramClientSocket* socket = |
215 CreateConnectedSocket(server_index).release(); | 227 CreateConnectedSocket(server_index).release(); |
216 if (!socket) | 228 if (!socket) |
217 break; | 229 break; |
218 pool.push_back(socket); | 230 pool.push_back(socket); |
219 } | 231 } |
220 } | 232 } |
221 | 233 |
222 } // namespace net | 234 } // namespace net |
OLD | NEW |