Source code

Revision control

Other Tools

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
public:
19
PollableEvent();
20
~PollableEvent();
21
22
// Signal/Clear return false only if they fail
23
bool Signal();
24
// This is called only when we get non-null out_flags for the socket pair
25
bool Clear();
26
bool Valid() { return mWriteFD && mReadFD; }
27
28
// We want to detect if writing to one of the socket pair sockets takes
29
// too long to be received by the other socket from the pair.
30
// Hence, we remember the timestamp of the earliest write by a call to
31
// MarkFirstSignalTimestamp() from Signal(). After waking up from poll()
32
// we check how long it took get the 'readable' signal on the socket pair.
33
void MarkFirstSignalTimestamp();
34
// Called right before we enter poll() to exclude any possible delay between
35
// the earlist call to Signal() and entering poll() caused by processing
36
// of events dispatched to the socket transport thread.
37
void AdjustFirstSignalTimestamp();
38
// This returns false on following conditions:
39
// - PR_Write has failed
40
// - no out_flags were signalled on the socket pair for too long after
41
// the earliest Signal()
42
bool IsSignallingAlive(TimeDuration const& timeout);
43
44
PRFileDesc* PollableFD() { return mReadFD; }
45
46
private:
47
PRFileDesc* mWriteFD;
48
PRFileDesc* mReadFD;
49
bool mSignaled;
50
// true when PR_Write to the socket pair has failed (status < 1)
51
bool mWriteFailed;
52
// Set true after AdjustFirstSignalTimestamp() was called
53
// Set false after Clear() was called
54
// Ensures shifting the timestamp before entering poll() only once
55
// between Clear()'ings.
56
bool mSignalTimestampAdjusted;
57
// Timestamp of the first call to Signal() (or time we enter poll())
58
// that happened after the last Clear() call
59
TimeStamp mFirstSignalAfterClear;
60
};
61
62
} // namespace net
63
} // namespace mozilla
64
65
#endif