LCOV - code coverage report
Current view: top level - netwerk/base - Tickler.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 6 50.0 %
Date: 2017-07-14 16:53:18 Functions: 3 6 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_B2G)
      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             : { 0x8f769ed6, 0x207c, 0x4af9, \
      59             :   { 0x9f, 0x7e, 0x9e, 0x83, 0x2d, 0xa3, 0x75, 0x4e } }
      60             : 
      61             : class Tickler final : public nsSupportsWeakReference
      62             : {
      63             : public:
      64             :   NS_DECL_THREADSAFE_ISUPPORTS
      65             :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_TICKLER_IID)
      66             : 
      67             :   // These methods are main thread only
      68             :   Tickler();
      69             :   void Cancel();
      70             :   nsresult Init();
      71             :   void SetIPV4Address(uint32_t address);
      72             :   void SetIPV4Port(uint16_t port);
      73             : 
      74             :   // Tickle the tickler to (re-)start the activity.
      75             :   // May call from any thread
      76             :   void Tickle();
      77             : 
      78             : private:
      79             :   ~Tickler();
      80             : 
      81             :   friend class TicklerTimer;
      82             :   Mutex mLock;
      83             :   nsCOMPtr<nsIThread> mThread;
      84             :   nsCOMPtr<nsITimer> mTimer;
      85             :   nsCOMPtr<nsIPrefBranch> mPrefs;
      86             : 
      87             :   bool mActive;
      88             :   bool mCanceled;
      89             :   bool mEnabled;
      90             :   uint32_t mDelay;
      91             :   TimeDuration mDuration;
      92             :   PRFileDesc* mFD;
      93             : 
      94             :   TimeStamp mLastTickle;
      95             :   PRNetAddr mAddr;
      96             : 
      97             :   // These functions may be called from any thread
      98             :   void PostCheckTickler();
      99             :   void MaybeStartTickler();
     100             :   void MaybeStartTicklerUnlocked();
     101             : 
     102             :   // Tickler thread only
     103             :   void CheckTickler();
     104             :   void StartTickler();
     105             :   void StopTickler();
     106             : };
     107             : 
     108             : NS_DEFINE_STATIC_IID_ACCESSOR(Tickler, NS_TICKLER_IID)
     109             : 
     110             : #else // not defined MOZ_USE_WIFI_TICKLER
     111             : 
     112             : class Tickler final : public nsISupports
     113             : {
     114           2 :   ~Tickler() { }
     115             : public:
     116             :   NS_DECL_THREADSAFE_ISUPPORTS
     117             : 
     118           2 :   Tickler() { }
     119           2 :   nsresult Init() { return NS_ERROR_NOT_IMPLEMENTED; }
     120           0 :   void Cancel() { }
     121           0 :   void SetIPV4Address(uint32_t) { };
     122             :   void SetIPV4Port(uint16_t) { }
     123           0 :   void Tickle() { }
     124             : };
     125             : 
     126             : #endif // defined MOZ_USE_WIFI_TICKLER
     127             : 
     128             : } // namespace net
     129             : } // namespace mozilla
     130             : 
     131             : #endif // mozilla_net_Tickler_h

Generated by: LCOV version 1.13