| Index: net/tools/quic/quic_time_wait_list_manager.cc
|
| diff --git a/net/tools/quic/quic_time_wait_list_manager.cc b/net/tools/quic/quic_time_wait_list_manager.cc
|
| index 98f96ece34c455b36aa67f7bd514f15070184246..5d0423aaf59aebf0771413def70dc814fcf7571d 100644
|
| --- a/net/tools/quic/quic_time_wait_list_manager.cc
|
| +++ b/net/tools/quic/quic_time_wait_list_manager.cc
|
| @@ -18,7 +18,6 @@
|
| #include "net/quic/quic_framer.h"
|
| #include "net/quic/quic_protocol.h"
|
| #include "net/quic/quic_utils.h"
|
| -#include "net/tools/epoll_server/epoll_server.h"
|
| #include "net/tools/quic/quic_server_session.h"
|
|
|
| using base::StringPiece;
|
| @@ -30,27 +29,29 @@ namespace tools {
|
| // "net/quic/quic_time_wait_list_manager.cc"
|
|
|
| // A very simple alarm that just informs the QuicTimeWaitListManager to clean
|
| -// up old connection_ids. This alarm should be unregistered and deleted before
|
| +// up old connection_ids. This alarm should be cancelled and deleted before
|
| // the QuicTimeWaitListManager is deleted.
|
| -class ConnectionIdCleanUpAlarm : public EpollAlarm {
|
| +class ConnectionIdCleanUpAlarm : public QuicAlarm::Delegate {
|
| public:
|
| explicit ConnectionIdCleanUpAlarm(
|
| QuicTimeWaitListManager* time_wait_list_manager)
|
| : time_wait_list_manager_(time_wait_list_manager) {
|
| }
|
|
|
| - int64 OnAlarm() override {
|
| - EpollAlarm::OnAlarm();
|
| + QuicTime OnAlarm() override {
|
| time_wait_list_manager_->CleanUpOldConnectionIds();
|
| // Let the time wait manager register the alarm at appropriate time.
|
| - return 0;
|
| + return QuicTime::Zero();
|
| }
|
|
|
| private:
|
| // Not owned.
|
| QuicTimeWaitListManager* time_wait_list_manager_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ConnectionIdCleanUpAlarm);
|
| };
|
|
|
| +
|
| // This class stores pending public reset packets to be sent to clients.
|
| // server_address - server address on which a packet what was received for
|
| // a connection_id in time wait state.
|
| @@ -83,20 +84,20 @@ class QuicTimeWaitListManager::QueuedPacket {
|
| QuicTimeWaitListManager::QuicTimeWaitListManager(
|
| QuicPacketWriter* writer,
|
| QuicServerSessionVisitor* visitor,
|
| - EpollServer* epoll_server,
|
| + QuicConnectionHelperInterface* helper,
|
| const QuicVersionVector& supported_versions)
|
| - : epoll_server_(epoll_server),
|
| - kTimeWaitPeriod_(
|
| + : time_wait_period_(
|
| QuicTime::Delta::FromSeconds(FLAGS_quic_time_wait_list_seconds)),
|
| - connection_id_clean_up_alarm_(new ConnectionIdCleanUpAlarm(this)),
|
| - clock_(epoll_server_),
|
| + connection_id_clean_up_alarm_(
|
| + helper->CreateAlarm(new ConnectionIdCleanUpAlarm(this))),
|
| + clock_(helper->GetClock()),
|
| writer_(writer),
|
| visitor_(visitor) {
|
| SetConnectionIdCleanUpAlarm();
|
| }
|
|
|
| QuicTimeWaitListManager::~QuicTimeWaitListManager() {
|
| - connection_id_clean_up_alarm_->UnregisterIfRegistered();
|
| + connection_id_clean_up_alarm_->Cancel();
|
| STLDeleteElements(&pending_packets_queue_);
|
| for (ConnectionIdMap::iterator it = connection_id_map_.begin();
|
| it != connection_id_map_.end();
|
| @@ -122,7 +123,7 @@ void QuicTimeWaitListManager::AddConnectionIdToTimeWait(
|
| static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections));
|
| ConnectionIdData data(num_packets,
|
| version,
|
| - clock_.ApproximateNow(),
|
| + clock_->ApproximateNow(),
|
| close_packet);
|
| connection_id_map_.insert(std::make_pair(connection_id, data));
|
| if (new_connection_id) {
|
| @@ -253,27 +254,25 @@ bool QuicTimeWaitListManager::WriteToWire(QueuedPacket* queued_packet) {
|
| }
|
|
|
| void QuicTimeWaitListManager::SetConnectionIdCleanUpAlarm() {
|
| - connection_id_clean_up_alarm_->UnregisterIfRegistered();
|
| - int64 next_alarm_interval;
|
| + connection_id_clean_up_alarm_->Cancel();
|
| + QuicTime::Delta next_alarm_interval = QuicTime::Delta::Zero();
|
| if (!connection_id_map_.empty()) {
|
| QuicTime oldest_connection_id =
|
| connection_id_map_.begin()->second.time_added;
|
| - QuicTime now = clock_.ApproximateNow();
|
| - if (now.Subtract(oldest_connection_id) < kTimeWaitPeriod_) {
|
| - next_alarm_interval = oldest_connection_id.Add(kTimeWaitPeriod_)
|
| - .Subtract(now)
|
| - .ToMicroseconds();
|
| + QuicTime now = clock_->ApproximateNow();
|
| + if (now.Subtract(oldest_connection_id) < time_wait_period_) {
|
| + next_alarm_interval = oldest_connection_id.Add(time_wait_period_)
|
| + .Subtract(now);
|
| } else {
|
| - LOG(ERROR) << "ConnectionId lingered for longer than kTimeWaitPeriod";
|
| - next_alarm_interval = 0;
|
| + LOG(ERROR) << "ConnectionId lingered for longer than time_wait_period_";
|
| }
|
| } else {
|
| - // No connection_ids added so none will expire before kTimeWaitPeriod_.
|
| - next_alarm_interval = kTimeWaitPeriod_.ToMicroseconds();
|
| + // No connection_ids added so none will expire before time_wait_period_.
|
| + next_alarm_interval = time_wait_period_;
|
| }
|
|
|
| - epoll_server_->RegisterAlarmApproximateDelta(
|
| - next_alarm_interval, connection_id_clean_up_alarm_.get());
|
| + connection_id_clean_up_alarm_->Set(
|
| + clock_->ApproximateNow().Add(next_alarm_interval));
|
| }
|
|
|
| bool QuicTimeWaitListManager::MaybeExpireOldestConnection(
|
| @@ -296,8 +295,8 @@ bool QuicTimeWaitListManager::MaybeExpireOldestConnection(
|
| }
|
|
|
| void QuicTimeWaitListManager::CleanUpOldConnectionIds() {
|
| - QuicTime now = clock_.ApproximateNow();
|
| - QuicTime expiration = now.Subtract(kTimeWaitPeriod_);
|
| + QuicTime now = clock_->ApproximateNow();
|
| + QuicTime expiration = now.Subtract(time_wait_period_);
|
|
|
| while (MaybeExpireOldestConnection(expiration)) {
|
| }
|
|
|