00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef QUEUEDCONNECTIONREADER_H
00020 #define QUEUEDCONNECTIONREADER_H
00021
00022 #include <pandabase.h>
00023
00024 #include "connectionReader.h"
00025 #include "netDatagram.h"
00026 #include "queuedReturn.h"
00027
00028 #include <prlock.h>
00029 #include "pdeque.h"
00030
00031 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA, EXPTP_PANDA, QueuedReturn<NetDatagram>);
00032
00033 #ifndef NDEBUG
00034
00035
00036
00037
00038 #define SIMULATE_NETWORK_DELAY
00039 #endif
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 class EXPCL_PANDA QueuedConnectionReader : public ConnectionReader,
00051 public QueuedReturn<NetDatagram> {
00052 PUBLISHED:
00053 QueuedConnectionReader(ConnectionManager *manager, int num_threads);
00054 virtual ~QueuedConnectionReader();
00055
00056 bool data_available();
00057 bool get_data(NetDatagram &result);
00058 bool get_data(Datagram &result);
00059
00060 protected:
00061 virtual void receive_datagram(const NetDatagram &datagram);
00062
00063 #ifdef SIMULATE_NETWORK_DELAY
00064 PUBLISHED:
00065 void start_delay(double min_delay, double max_delay);
00066 void stop_delay();
00067
00068 private:
00069 void get_delayed();
00070 void delay_datagram(const NetDatagram &datagram);
00071
00072 class DelayedDatagram {
00073 public:
00074 double _reveal_time;
00075 NetDatagram _datagram;
00076 };
00077
00078 PRLock *_dd_mutex;
00079 typedef pdeque<DelayedDatagram> Delayed;
00080 Delayed _delayed;
00081 bool _delay_active;
00082 double _min_delay, _delay_variance;
00083
00084 #endif // SIMULATE_NETWORK_DELAY
00085 };
00086
00087 #endif
00088