Panda3D
 All Classes Functions Variables Enumerations
queuedConnectionReader.h
1 // Filename: queuedConnectionReader.h
2 // Created by: drose (08Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef QUEUEDCONNECTIONREADER_H
16 #define QUEUEDCONNECTIONREADER_H
17 
18 #include "pandabase.h"
19 
20 #include "connectionReader.h"
21 #include "netDatagram.h"
22 #include "queuedReturn.h"
23 #include "lightMutex.h"
24 #include "pdeque.h"
25 
26 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_NET, EXPTP_PANDA_NET, QueuedReturn<NetDatagram>);
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : QueuedConnectionReader
30 // Description : This flavor of ConnectionReader will read from its
31 // sockets and queue up all of the datagrams read for
32 // later receipt by the client code. This class is
33 // useful for client code that doesn't want to deal with
34 // threading and is willing to poll for datagrams at its
35 // convenience.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_NET QueuedConnectionReader : public ConnectionReader,
38  public QueuedReturn<NetDatagram> {
39 PUBLISHED:
40  QueuedConnectionReader(ConnectionManager *manager, int num_threads);
41  virtual ~QueuedConnectionReader();
42 
43  BLOCKING bool data_available();
44  bool get_data(NetDatagram &result);
45  bool get_data(Datagram &result);
46 
47 protected:
48  virtual void receive_datagram(const NetDatagram &datagram);
49 
50 #ifdef SIMULATE_NETWORK_DELAY
51 PUBLISHED:
52  void start_delay(double min_delay, double max_delay);
53  void stop_delay();
54 
55 private:
56  void get_delayed();
57  void delay_datagram(const NetDatagram &datagram);
58 
59  class DelayedDatagram {
60  public:
61  double _reveal_time;
62  NetDatagram _datagram;
63  };
64 
65  LightMutex _dd_mutex;
66  typedef pdeque<DelayedDatagram> Delayed;
67  Delayed _delayed;
68  bool _delay_active;
69  double _min_delay, _delay_variance;
70 
71 #endif // SIMULATE_NETWORK_DELAY
72 };
73 
74 #endif
75 
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:43
The primary interface to the low-level networking layer in this package.
This is our own Panda specialization on the default STL deque.
Definition: pdeque.h:38
This is an abstract base class for a family of classes that listen for activity on a socket and respo...
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:45
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43