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.
5 #ifndef NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_
6 #define NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "net/tools/flip_server/constants.h"
15 #include "net/tools/flip_server/epoll_server.h"
16 #include "net/tools/flip_server/mem_cache.h"
20 class SMConnectionInterface
;
22 class OutputOrdering
{
24 typedef std::list
<MemCacheIter
> PriorityRing
;
25 typedef std::map
<uint32
, PriorityRing
> PriorityMap
;
27 struct PriorityMapPointer
{
30 PriorityRing::iterator it
;
32 EpollServer::AlarmRegToken alarm_token
;
35 typedef std::map
<uint32
, PriorityMapPointer
> StreamIdToPriorityMap
;
37 StreamIdToPriorityMap stream_ids_
;
38 PriorityMap priority_map_
;
39 PriorityRing first_data_senders_
;
40 uint32 first_data_senders_threshold_
; // when you've passed this, you're no
41 // longer a first_data_sender...
42 SMConnectionInterface
* connection_
;
43 EpollServer
* epoll_server_
;
45 explicit OutputOrdering(SMConnectionInterface
* connection
);
48 bool ExistsInPriorityMaps(uint32 stream_id
);
50 struct BeginOutputtingAlarm
: public EpollAlarmCallbackInterface
{
52 BeginOutputtingAlarm(OutputOrdering
* oo
,
53 OutputOrdering::PriorityMapPointer
* pmp
,
54 const MemCacheIter
& mci
);
55 virtual ~BeginOutputtingAlarm();
57 // EpollAlarmCallbackInterface:
58 virtual int64
OnAlarm() OVERRIDE
;
59 virtual void OnRegistration(const EpollServer::AlarmRegToken
& tok
,
60 EpollServer
* eps
) OVERRIDE
;
61 virtual void OnUnregistration() OVERRIDE
;
62 virtual void OnShutdown(EpollServer
* eps
) OVERRIDE
;
65 OutputOrdering
* output_ordering_
;
66 OutputOrdering::PriorityMapPointer
* pmp_
;
68 EpollServer
* epoll_server_
;
71 void MoveToActive(PriorityMapPointer
* pmp
, MemCacheIter mci
);
72 void AddToOutputOrder(const MemCacheIter
& mci
);
73 void SpliceToPriorityRing(PriorityRing::iterator pri
);
74 MemCacheIter
* GetIter();
75 void RemoveStreamId(uint32 stream_id
);
77 static double server_think_time_in_s() { return server_think_time_in_s_
; }
78 static void set_server_think_time_in_s(double value
) {
79 server_think_time_in_s_
= value
;
83 static double server_think_time_in_s_
;
88 #endif // NET_TOOLS_FLIP_SERVER_OUTPUT_ORDERING_H_