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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/quic/core/congestion_control/simulation/queue.cc
diff --git a/net/quic/core/congestion_control/simulation/queue.cc b/net/quic/core/congestion_control/simulation/queue.cc
new file mode 100644
index 0000000000000000000000000000000000000000..24593e35ba778ae0c85df0f95b505b9081c4b47d
--- /dev/null
+++ b/net/quic/core/congestion_control/simulation/queue.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/quic/core/congestion_control/simulation/queue.h"
+
+namespace net {
+namespace simulation {
+
+Queue::ListenerInterface::~ListenerInterface() {}
+
+Queue::Queue(Simulator* simulator, std::string name, QuicByteCount capacity)
+ : Actor(simulator, name),
+ capacity_(capacity),
+ bytes_queued_(0),
+ listener_(nullptr) {}
+Queue::~Queue() {}
+
+void Queue::set_tx_port(ConstrainedPortInterface* port) {
+ tx_port_ = port;
+}
+
+void Queue::AcceptPacket(std::unique_ptr<Packet> packet) {
+ if (packet->size + bytes_queued_ > capacity_) {
+ DVLOG(1) << "Queue [" << name() << "] has received a packet from ["
+ << packet->source << "] to [" << packet->destination
+ << "] which is over capacity. Dropping it.";
+ DVLOG(1) << "Queue size: " << bytes_queued_ << " out of " << capacity_
+ << ". Packet size: " << packet->size;
+ return;
+ }
+
+ bytes_queued_ += packet->size;
+ queue_.emplace(std::move(packet));
+ ScheduleNextPacketDequeue();
+}
+
+void Queue::Act() {
+ DCHECK(!queue_.empty());
+ if (tx_port_->TimeUntilAvailable().IsZero()) {
+ DCHECK(bytes_queued_ >= queue_.front()->size);
+ bytes_queued_ -= queue_.front()->size;
+
+ tx_port_->AcceptPacket(std::move(queue_.front()));
+ queue_.pop();
+ if (listener_ != nullptr) {
+ listener_->OnPacketDequeued();
+ }
+ }
+
+ ScheduleNextPacketDequeue();
+}
+
+void Queue::ScheduleNextPacketDequeue() {
+ if (queue_.empty()) {
+ DCHECK_EQ(bytes_queued_, 0u);
+ return;
+ }
+
+ Schedule(clock_->Now() + tx_port_->TimeUntilAvailable());
+}
+
+} // namespace simulation
+} // namespace net
« 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