OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/dns/dns_session.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" |
| 9 #include "base/time.h" |
| 10 #include "net/base/ip_endpoint.h" |
| 11 #include "net/dns/dns_config_service.h" |
| 12 #include "net/socket/client_socket_factory.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 DnsSession::DnsSession(const DnsConfig& config, |
| 17 ClientSocketFactory* factory, |
| 18 const RandIntCallback& rand_int_callback, |
| 19 NetLog* net_log) |
| 20 : config_(config), |
| 21 socket_factory_(factory), |
| 22 rand_callback_(base::Bind(rand_int_callback, 0, kuint16max)), |
| 23 net_log_(net_log), |
| 24 server_index_(0) { |
| 25 } |
| 26 |
| 27 int DnsSession::NextId() const { |
| 28 return rand_callback_.Run(); |
| 29 } |
| 30 |
| 31 const IPEndPoint& DnsSession::NextServer() { |
| 32 // TODO(szym): Rotate servers on failures. |
| 33 const IPEndPoint& ipe = config_.nameservers[server_index_]; |
| 34 if (config_.rotate) |
| 35 server_index_ = (server_index_ + 1) % config_.nameservers.size(); |
| 36 return ipe; |
| 37 } |
| 38 |
| 39 base::TimeDelta DnsSession::NextTimeout(int attempt) { |
| 40 // TODO(szym): Adapt timeout to observed RTT. |
| 41 return config_.timeout * (attempt + 1); |
| 42 } |
| 43 |
| 44 DnsSession::~DnsSession() {} |
| 45 |
| 46 } // namespace net |
| 47 |
OLD | NEW |