diff options
Diffstat (limited to 'netwerk/base/nsSocketTransportService2.h')
-rw-r--r-- | netwerk/base/nsSocketTransportService2.h | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/netwerk/base/nsSocketTransportService2.h b/netwerk/base/nsSocketTransportService2.h index 0b88a6535..9360dd905 100644 --- a/netwerk/base/nsSocketTransportService2.h +++ b/netwerk/base/nsSocketTransportService2.h @@ -19,7 +19,6 @@ #include "mozilla/Mutex.h" #include "mozilla/net/DashboardTypes.h" #include "mozilla/Atomics.h" -#include "mozilla/TimeStamp.h" #include "nsITimer.h" #include "mozilla/UniquePtr.h" #include "PollableEvent.h" @@ -117,6 +116,9 @@ public: // Returns true if keepalives are enabled in prefs. bool IsKeepaliveEnabled() { return mKeepaliveEnabledPref; } + + // Returns true if socket timeout clamping is enabled in prefs. + bool IsSocketTimeoutClamped() { return mClampSocketTimeout; } PRIntervalTime MaxTimeForPrClosePref() {return mMaxTimeForPrClosePref; } protected: @@ -167,7 +169,33 @@ private: { PRFileDesc *mFD; nsASocketHandler *mHandler; - uint16_t mElapsedTime; // time elapsed w/o activity + PRIntervalTime mPollStartEpoch; // Epoch timestamp when we started to poll this socket + + public: + // Helper functions implementing a timeout mechanism. + + // Returns true if the socket has not been signalled in more than the desired + // timeout for this socket (mHandler->mPollTimeout). + bool IsTimedOut(PRIntervalTime now) const; + + // Records the epoch timestamp we started polling this socket. If the epoch is already + // recorded, then it does nothing (i.e. does not re-arm) so it's safe to call whenever + // this socket is put into the active polling list. + void StartTimeout(PRIntervalTime now); + + // Turns off the timout calculation. + void StopTimeout(); + + // Returns the number of intervals from "now" after which this socket will timeout, + // or 0 (zero) when it has already timed out. Returns NS_SOCKET_POLL_TIMEOUT + // when there is no timeout set on the socket. + PRIntervalTime TimeoutIn(PRIntervalTime now) const; + + // When a socket timeout is set to not time out and later set again to time out, it + // is possible that mPollStartEpoch is not reset in-between. We have to manually + // call this on every iteration over sockets to ensure the epoch timestamp is reset + // and our socket bookkeeping remains accurate. + void ResetTimeout(); }; SocketContext *mActiveList; /* mListSize entries */ @@ -203,10 +231,10 @@ private: PRPollDesc *mPollList; /* mListSize + 1 entries */ - PRIntervalTime PollTimeout(); // computes ideal poll timeout + PRIntervalTime PollTimeout(PRIntervalTime now); // computes ideal poll timeout nsresult DoPollIteration(); // perfoms a single poll iteration - int32_t Poll(uint32_t *interval); + int32_t Poll(PRIntervalTime now); // calls PR_Poll. the out param // interval indicates the poll // duration in seconds. @@ -228,6 +256,8 @@ private: int32_t mKeepaliveProbeCount; // True if TCP keepalive is enabled globally. bool mKeepaliveEnabledPref; + // True if socket polling should be clamped. + bool mClampSocketTimeout; Atomic<bool> mServingPendingQueue; Atomic<int32_t, Relaxed> mMaxTimePerPollIter; |