Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_net_Tickler_h
7 #define mozilla_net_Tickler_h
9 // The tickler sends a regular 0 byte UDP heartbeat out to a
10 // particular address for a short time after it has been touched. This
11 // is used on some mobile wifi chipsets to mitigate Power Save Polling
12 // (PSP) Mode when we are anticipating a response packet
13 // soon. Typically PSP adds 100ms of latency to a read event because
14 // the packet delivery is not triggered until the 802.11 beacon is
15 // delivered to the host (100ms is the standard Access Point
16 // configuration for the beacon interval.) Requesting a frequent
17 // transmission and getting a CTS frame from the AP at least that
18 // frequently allows for low latency receives when we have reason to
19 // expect them (e.g a SYN-ACK).
20 //
21 // The tickler is used to allow RTT based phases of web transport to
22 // complete quickly when on wifi - ARP, DNS, TCP handshake, SSL
23 // handshake, HTTP headers, and the TCP slow start phase. The
24 // transaction is given up to 400 miliseconds by default to get
25 // through those phases before the tickler is disabled.
26 //
27 // The tickler only applies to wifi on mobile right now. Hopefully it
28 // can also be restricted to particular handset models in the future.
30 #if defined(ANDROID) && !defined(MOZ_B2G)
31 #define MOZ_USE_WIFI_TICKLER
32 #endif
34 #include "mozilla/Attributes.h"
35 #include "nsISupports.h"
36 #include <stdint.h>
38 #ifdef MOZ_USE_WIFI_TICKLER
39 #include "mozilla/Mutex.h"
40 #include "mozilla/TimeStamp.h"
41 #include "nsAutoPtr.h"
42 #include "nsISupports.h"
43 #include "nsIThread.h"
44 #include "nsITimer.h"
45 #include "nsWeakReference.h"
46 #include "prio.h"
48 class nsIPrefBranch;
49 #endif
51 namespace mozilla {
52 namespace net {
54 #ifdef MOZ_USE_WIFI_TICKLER
56 // 8f769ed6-207c-4af9-9f7e-9e832da3754e
57 #define NS_TICKLER_IID \
58 { 0x8f769ed6, 0x207c, 0x4af9, \
59 { 0x9f, 0x7e, 0x9e, 0x83, 0x2d, 0xa3, 0x75, 0x4e } }
61 class Tickler MOZ_FINAL : public nsSupportsWeakReference
62 {
63 public:
64 NS_DECL_THREADSAFE_ISUPPORTS
65 NS_DECLARE_STATIC_IID_ACCESSOR(NS_TICKLER_IID)
67 // These methods are main thread only
68 Tickler();
69 ~Tickler();
70 void Cancel();
71 nsresult Init();
72 void SetIPV4Address(uint32_t address);
73 void SetIPV4Port(uint16_t port);
75 // Tickle the tickler to (re-)start the activity.
76 // May call from any thread
77 void Tickle();
79 private:
80 friend class TicklerTimer;
81 Mutex mLock;
82 nsCOMPtr<nsIThread> mThread;
83 nsCOMPtr<nsITimer> mTimer;
84 nsCOMPtr<nsIPrefBranch> mPrefs;
86 bool mActive;
87 bool mCanceled;
88 bool mEnabled;
89 uint32_t mDelay;
90 TimeDuration mDuration;
91 PRFileDesc* mFD;
93 TimeStamp mLastTickle;
94 PRNetAddr mAddr;
96 // These functions may be called from any thread
97 void PostCheckTickler();
98 void MaybeStartTickler();
99 void MaybeStartTicklerUnlocked();
101 // Tickler thread only
102 void CheckTickler();
103 void StartTickler();
104 void StopTickler();
105 };
107 NS_DEFINE_STATIC_IID_ACCESSOR(Tickler, NS_TICKLER_IID)
109 #else // not defined MOZ_USE_WIFI_TICKLER
111 class Tickler MOZ_FINAL : public nsISupports
112 {
113 public:
114 NS_DECL_THREADSAFE_ISUPPORTS
116 Tickler() { }
117 ~Tickler() { }
118 nsresult Init() { return NS_ERROR_NOT_IMPLEMENTED; }
119 void Cancel() { }
120 void SetIPV4Address(uint32_t) { };
121 void SetIPV4Port(uint16_t) { }
122 void Tickle() { }
123 };
125 #endif // defined MOZ_USE_WIFI_TICKLER
127 } // namespace mozilla::net
128 } // namespace mozilla
130 #endif // mozilla_net_Tickler_h