24 QueuedConnectionReader::
28 #ifdef SIMULATE_NETWORK_DELAY 29 _delay_active =
false;
31 _delay_variance = 0.0;
32 #endif // SIMULATE_NETWORK_DELAY 38 QueuedConnectionReader::
39 ~QueuedConnectionReader() {
52 #ifdef SIMULATE_NETWORK_DELAY 54 #endif // SIMULATE_NETWORK_DELAY 55 return thing_available();
68 return get_thing(result);
92 void QueuedConnectionReader::
102 #ifdef SIMULATE_NETWORK_DELAY 103 delay_datagram(datagram);
105 #else // SIMULATE_NETWORK_DELAY 106 if (!enqueue_thing(datagram)) {
108 <<
"QueuedConnectionReader queue full!\n";
110 #endif // SIMULATE_NETWORK_DELAY 114 #ifdef SIMULATE_NETWORK_DELAY 122 void QueuedConnectionReader::
123 start_delay(
double min_delay,
double max_delay) {
125 _min_delay = min_delay;
126 _delay_variance = std::max(max_delay - min_delay, 0.0);
127 _delay_active =
true;
135 void QueuedConnectionReader::
138 _delay_active =
false;
141 while (!_delayed.empty()) {
142 const DelayedDatagram &dd = _delayed.front();
143 if (!enqueue_thing(dd._datagram)) {
145 <<
"QueuedConnectionReader queue full!\n";
147 _delayed.pop_front();
155 void QueuedConnectionReader::
160 while (!_delayed.empty()) {
161 const DelayedDatagram &dd = _delayed.front();
162 if (dd._reveal_time > now) {
166 if (!enqueue_thing(dd._datagram)) {
168 <<
"QueuedConnectionReader queue full!\n";
170 _delayed.pop_front();
178 void QueuedConnectionReader::
180 if (!_delay_active) {
181 if (!enqueue_thing(datagram)) {
183 <<
"QueuedConnectionReader queue full!\n";
188 if (!_delay_active) {
189 if (!enqueue_thing(datagram)) {
191 <<
"QueuedConnectionReader queue full!\n";
196 double reveal_time = now + _min_delay;
198 if (_delay_variance > 0.0) {
199 reveal_time += _delay_variance * ((double)rand() / (double)RAND_MAX);
201 _delayed.push_back(DelayedDatagram());
202 DelayedDatagram &dd = _delayed.back();
203 dd._reveal_time = reveal_time;
204 dd._datagram = datagram;
209 #endif // SIMULATE_NETWORK_DELAY static TrueClock * get_global_ptr()
Returns a pointer to the one TrueClock object in the world.
A specific kind of Datagram, especially for sending across or receiving from a network.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The primary interface to the low-level networking layer in this package.
void shutdown()
Terminates all threads cleanly.
This is an abstract base class for a family of classes that listen for activity on a socket and respo...
void poll()
Explicitly polls the available sockets to see if any of them have any noise.
bool data_available()
Returns true if a datagram is available on the queue; call get_data() to extract the datagram.
Similar to MutexHolder, but for a light mutex.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool get_data(NetDatagram &result)
If a previous call to data_available() returned true, this function will return the datagram that has...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.