diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/base/PollableEvent.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/base/PollableEvent.h')
-rw-r--r-- | netwerk/base/PollableEvent.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/netwerk/base/PollableEvent.h b/netwerk/base/PollableEvent.h new file mode 100644 index 0000000000..6a17cd909d --- /dev/null +++ b/netwerk/base/PollableEvent.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef PollableEvent_h__ +#define PollableEvent_h__ + +#include "mozilla/Mutex.h" +#include "mozilla/TimeStamp.h" + +struct PRFileDesc; + +namespace mozilla { +namespace net { + +// class must be called locked +class PollableEvent { + public: + PollableEvent(); + ~PollableEvent(); + + // Signal/Clear return false only if they fail + bool Signal(); + // This is called only when we get non-null out_flags for the socket pair + bool Clear(); + bool Valid() { return mWriteFD && mReadFD; } + + // We want to detect if writing to one of the socket pair sockets takes + // too long to be received by the other socket from the pair. + // Hence, we remember the timestamp of the earliest write by a call to + // MarkFirstSignalTimestamp() from Signal(). After waking up from poll() + // we check how long it took get the 'readable' signal on the socket pair. + void MarkFirstSignalTimestamp(); + // Called right before we enter poll() to exclude any possible delay between + // the earlist call to Signal() and entering poll() caused by processing + // of events dispatched to the socket transport thread. + void AdjustFirstSignalTimestamp(); + // This returns false on following conditions: + // - PR_Write has failed + // - no out_flags were signalled on the socket pair for too long after + // the earliest Signal() + bool IsSignallingAlive(TimeDuration const& timeout); + + PRFileDesc* PollableFD() { return mReadFD; } + + private: + PRFileDesc* mWriteFD{nullptr}; + PRFileDesc* mReadFD{nullptr}; + bool mSignaled{false}; + // true when PR_Write to the socket pair has failed (status < 1) + bool mWriteFailed{false}; + // Set true after AdjustFirstSignalTimestamp() was called + // Set false after Clear() was called + // Ensures shifting the timestamp before entering poll() only once + // between Clear()'ings. + bool mSignalTimestampAdjusted{false}; + // Timestamp of the first call to Signal() (or time we enter poll()) + // that happened after the last Clear() call + TimeStamp mFirstSignalAfterClear; +}; + +} // namespace net +} // namespace mozilla + +#endif |