Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: net/quic/core/congestion_control/simulation/queue.cc

Issue 2322233004: Landing Recent QUIC changes until Sun Sep 4 03:41:00 (Closed)
Patch Set: Remove simulation files from the build. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/core/congestion_control/simulation/queue.h"
6
7 namespace net {
8 namespace simulation {
9
10 Queue::ListenerInterface::~ListenerInterface() {}
11
12 Queue::Queue(Simulator* simulator, std::string name, QuicByteCount capacity)
13 : Actor(simulator, name),
14 capacity_(capacity),
15 bytes_queued_(0),
16 listener_(nullptr) {}
17 Queue::~Queue() {}
18
19 void Queue::set_tx_port(ConstrainedPortInterface* port) {
20 tx_port_ = port;
21 }
22
23 void Queue::AcceptPacket(std::unique_ptr<Packet> packet) {
24 if (packet->size + bytes_queued_ > capacity_) {
25 DVLOG(1) << "Queue [" << name() << "] has received a packet from ["
26 << packet->source << "] to [" << packet->destination
27 << "] which is over capacity. Dropping it.";
28 DVLOG(1) << "Queue size: " << bytes_queued_ << " out of " << capacity_
29 << ". Packet size: " << packet->size;
30 return;
31 }
32
33 bytes_queued_ += packet->size;
34 queue_.emplace(std::move(packet));
35 ScheduleNextPacketDequeue();
36 }
37
38 void Queue::Act() {
39 DCHECK(!queue_.empty());
40 if (tx_port_->TimeUntilAvailable().IsZero()) {
41 DCHECK(bytes_queued_ >= queue_.front()->size);
42 bytes_queued_ -= queue_.front()->size;
43
44 tx_port_->AcceptPacket(std::move(queue_.front()));
45 queue_.pop();
46 if (listener_ != nullptr) {
47 listener_->OnPacketDequeued();
48 }
49 }
50
51 ScheduleNextPacketDequeue();
52 }
53
54 void Queue::ScheduleNextPacketDequeue() {
55 if (queue_.empty()) {
56 DCHECK_EQ(bytes_queued_, 0u);
57 return;
58 }
59
60 Schedule(clock_->Now() + tx_port_->TimeUntilAvailable());
61 }
62
63 } // namespace simulation
64 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/congestion_control/simulation/queue.h ('k') | net/quic/core/congestion_control/simulation/quic_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698