summaryrefslogtreecommitdiffstats
path: root/net/tools/flip_server/output_ordering.h
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-02 20:03:02 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-02 20:03:02 +0000
commit878984e6a994d308543f3ce93b2d5a511c81ba00 (patch)
tree755e2c50ee764ad05e5600f97bad1bd7ef972f78 /net/tools/flip_server/output_ordering.h
parentb3c57fe514e2b3cf10278004abe1d4b189cdb7f9 (diff)
downloadchromium_src-878984e6a994d308543f3ce93b2d5a511c81ba00.zip
chromium_src-878984e6a994d308543f3ce93b2d5a511c81ba00.tar.gz
chromium_src-878984e6a994d308543f3ce93b2d5a511c81ba00.tar.bz2
Split flip_in_mem_edsm_server into a gazillion pieces.
For the most part, this is a straight refactor. I'm sure I broke something. BUG=monolithic code TEST=none Review URL: http://codereview.chromium.org/6392011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools/flip_server/output_ordering.h')
-rw-r--r--net/tools/flip_server/output_ordering.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/net/tools/flip_server/output_ordering.h b/net/tools/flip_server/output_ordering.h
new file mode 100644
index 0000000..14c1587
--- /dev/null
+++ b/net/tools/flip_server/output_ordering.h
@@ -0,0 +1,103 @@
+// Copyright (c) 2009 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.
+
+#ifndef NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_
+#define NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_
+
+#include <list>
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "net/tools/flip_server/constants.h"
+#include "net/tools/flip_server/epoll_server.h"
+#include "net/tools/flip_server/mem_cache.h"
+
+namespace net {
+
+class SMConnectionInterface;
+
+class OutputOrdering {
+ public:
+ typedef std::list<MemCacheIter> PriorityRing;
+ typedef std::map<uint32, PriorityRing> PriorityMap;
+
+ struct PriorityMapPointer {
+ PriorityMapPointer(): ring(NULL), alarm_enabled(false) {}
+ PriorityRing* ring;
+ PriorityRing::iterator it;
+ bool alarm_enabled;
+ EpollServer::AlarmRegToken alarm_token;
+ };
+
+ typedef std::map<uint32, PriorityMapPointer> StreamIdToPriorityMap;
+
+ StreamIdToPriorityMap stream_ids_;
+ PriorityMap priority_map_;
+ PriorityRing first_data_senders_;
+ uint32 first_data_senders_threshold_; // when you've passed this, you're no
+ // longer a first_data_sender...
+ SMConnectionInterface* connection_;
+ EpollServer* epoll_server_;
+
+ explicit OutputOrdering(SMConnectionInterface* connection);
+ void Reset();
+ bool ExistsInPriorityMaps(uint32 stream_id);
+
+ struct BeginOutputtingAlarm : public EpollAlarmCallbackInterface {
+ public:
+ BeginOutputtingAlarm(OutputOrdering* oo,
+ OutputOrdering::PriorityMapPointer* pmp,
+ const MemCacheIter& mci) :
+ output_ordering_(oo), pmp_(pmp), mci_(mci), epoll_server_(NULL) {}
+
+ int64 OnAlarm() {
+ OnUnregistration();
+ output_ordering_->MoveToActive(pmp_, mci_);
+ VLOG(2) << "ON ALARM! Should now start to output...";
+ delete this;
+ return 0;
+ }
+ void OnRegistration(const EpollServer::AlarmRegToken& tok,
+ EpollServer* eps) {
+ epoll_server_ = eps;
+ pmp_->alarm_token = tok;
+ pmp_->alarm_enabled = true;
+ }
+ void OnUnregistration() {
+ pmp_->alarm_enabled = false;
+ }
+ void OnShutdown(EpollServer* eps) {
+ OnUnregistration();
+ }
+ ~BeginOutputtingAlarm() {
+ if (epoll_server_ && pmp_->alarm_enabled)
+ epoll_server_->UnregisterAlarm(pmp_->alarm_token);
+ }
+ private:
+ OutputOrdering* output_ordering_;
+ OutputOrdering::PriorityMapPointer* pmp_;
+ MemCacheIter mci_;
+ EpollServer* epoll_server_;
+ };
+
+ void MoveToActive(PriorityMapPointer* pmp, MemCacheIter mci);
+ void AddToOutputOrder(const MemCacheIter& mci);
+ void SpliceToPriorityRing(PriorityRing::iterator pri);
+ MemCacheIter* GetIter();
+ void RemoveStreamId(uint32 stream_id);
+
+ static double server_think_time_in_s() { return server_think_time_in_s_; }
+ static void set_server_think_time_in_s(double value) {
+ server_think_time_in_s_ = value;
+ }
+
+ private:
+ static double server_think_time_in_s_;
+};
+
+} // namespace net
+
+#endif // NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_
+