Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/netwerk/base/PollableEvent.h
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef PollableEvent_h__
8
#define PollableEvent_h__
9
10
#include "mozilla/Mutex.h"
11
#include "mozilla/TimeStamp.h"
12
13
namespace mozilla {
14
namespace net {
15
16
// class must be called locked
17
class PollableEvent
18
{
19
public:
20
  PollableEvent();
21
  ~PollableEvent();
22
23
  // Signal/Clear return false only if they fail
24
  bool Signal();
25
  // This is called only when we get non-null out_flags for the socket pair
26
  bool Clear();
27
3
  bool Valid() { return mWriteFD && mReadFD; }
28
29
  // We want to detect if writing to one of the socket pair sockets takes
30
  // too long to be received by the other socket from the pair.
31
  // Hence, we remember the timestamp of the earliest write by a call to
32
  // MarkFirstSignalTimestamp() from Signal().  After waking up from poll()
33
  // we check how long it took get the 'readable' signal on the socket pair.
34
  void MarkFirstSignalTimestamp();
35
  // Called right before we enter poll() to exclude any possible delay between
36
  // the earlist call to Signal() and entering poll() caused by processing
37
  // of events dispatched to the socket transport thread.
38
  void AdjustFirstSignalTimestamp();
39
  // This returns false on following conditions:
40
  // - PR_Write has failed
41
  // - no out_flags were signalled on the socket pair for too long after
42
  //   the earliest Signal()
43
  bool IsSignallingAlive(TimeDuration const& timeout);
44
45
3
  PRFileDesc *PollableFD() { return mReadFD; }
46
47
private:
48
  PRFileDesc *mWriteFD;
49
  PRFileDesc *mReadFD;
50
  bool        mSignaled;
51
  // true when PR_Write to the socket pair has failed (status < 1)
52
  bool        mWriteFailed;
53
  // Set true after AdjustFirstSignalTimestamp() was called
54
  // Set false after Clear() was called
55
  // Ensures shifting the timestamp before entering poll() only once
56
  // between Clear()'ings.
57
  bool        mSignalTimestampAdjusted;
58
  // Timestamp of the first call to Signal() (or time we enter poll())
59
  // that happened after the last Clear() call
60
  TimeStamp   mFirstSignalAfterClear;
61
};
62
63
} // namespace net
64
} // namespace mozilla
65
66
#endif