Source code

Revision control

Other Tools

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/. */
5
6
#ifndef mozilla_net_Tickler_h
7
#define mozilla_net_Tickler_h
8
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.
29
30
#if defined(ANDROID) && !defined(MOZ_PROXY_BYPASS_PROTECTION)
31
# define MOZ_USE_WIFI_TICKLER
32
#endif
33
34
#include "mozilla/Attributes.h"
35
#include "nsISupports.h"
36
#include <stdint.h>
37
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"
47
48
class nsIPrefBranch;
49
#endif
50
51
namespace mozilla {
52
namespace net {
53
54
#ifdef MOZ_USE_WIFI_TICKLER
55
56
// 8f769ed6-207c-4af9-9f7e-9e832da3754e
57
# define NS_TICKLER_IID \
58
{ \
59
0x8f769ed6, 0x207c, 0x4af9, { \
60
0x9f, 0x7e, 0x9e, 0x83, 0x2d, 0xa3, 0x75, 0x4e \
61
} \
62
}
63
64
class Tickler final : public nsSupportsWeakReference {
65
public:
66
NS_DECL_THREADSAFE_ISUPPORTS
67
NS_DECLARE_STATIC_IID_ACCESSOR(NS_TICKLER_IID)
68
69
// These methods are main thread only
70
Tickler();
71
void Cancel();
72
nsresult Init();
73
void SetIPV4Address(uint32_t address);
74
void SetIPV4Port(uint16_t port);
75
76
// Tickle the tickler to (re-)start the activity.
77
// May call from any thread
78
void Tickle();
79
80
private:
81
~Tickler();
82
83
friend class TicklerTimer;
84
Mutex mLock;
85
nsCOMPtr<nsIThread> mThread;
86
nsCOMPtr<nsITimer> mTimer;
87
nsCOMPtr<nsIPrefBranch> mPrefs;
88
89
bool mActive;
90
bool mCanceled;
91
bool mEnabled;
92
uint32_t mDelay;
93
TimeDuration mDuration;
94
PRFileDesc* mFD;
95
96
TimeStamp mLastTickle;
97
PRNetAddr mAddr;
98
99
// These functions may be called from any thread
100
void PostCheckTickler();
101
void MaybeStartTickler();
102
void MaybeStartTicklerUnlocked();
103
104
// Tickler thread only
105
void CheckTickler();
106
void StartTickler();
107
void StopTickler();
108
};
109
110
NS_DEFINE_STATIC_IID_ACCESSOR(Tickler, NS_TICKLER_IID)
111
112
#else // not defined MOZ_USE_WIFI_TICKLER
113
114
class Tickler final : public nsISupports {
115
~Tickler() = default;
116
117
public:
118
NS_DECL_THREADSAFE_ISUPPORTS
119
120
Tickler() = default;
121
nsresult Init() { return NS_ERROR_NOT_IMPLEMENTED; }
122
void Cancel() {}
123
void SetIPV4Address(uint32_t){};
124
void SetIPV4Port(uint16_t) {}
125
void Tickle() {}
126
};
127
128
#endif // defined MOZ_USE_WIFI_TICKLER
129
130
} // namespace net
131
} // namespace mozilla
132
133
#endif // mozilla_net_Tickler_h