summaryrefslogtreecommitdiffstats
path: root/netwerk/base/nsSocketTransportService2.h
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-12-08 17:19:01 +0000
committerMoonchild <moonchild@palemoon.org>2020-12-08 17:19:01 +0000
commit6b45065f147c76c630e2bd51f9d6ac4fa1cb123a (patch)
treecb4469de6c77f181d7bf569cd11440013e60b81c /netwerk/base/nsSocketTransportService2.h
parent6cb00e2cfd2630877e947ab8266497672df306d0 (diff)
downloadUXP-6b45065f147c76c630e2bd51f9d6ac4fa1cb123a.tar
UXP-6b45065f147c76c630e2bd51f9d6ac4fa1cb123a.tar.gz
UXP-6b45065f147c76c630e2bd51f9d6ac4fa1cb123a.tar.lz
UXP-6b45065f147c76c630e2bd51f9d6ac4fa1cb123a.tar.xz
UXP-6b45065f147c76c630e2bd51f9d6ac4fa1cb123a.zip
Issue #1695 - Fix socket timeout logic.
Diffstat (limited to 'netwerk/base/nsSocketTransportService2.h')
-rw-r--r--netwerk/base/nsSocketTransportService2.h33
1 files changed, 29 insertions, 4 deletions
diff --git a/netwerk/base/nsSocketTransportService2.h b/netwerk/base/nsSocketTransportService2.h
index 0b88a6535..31efec1d9 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"
@@ -167,7 +166,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 +228,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.