Panda3D
 All Classes Functions Variables Enumerations
queuedConnectionReader.h
00001 // Filename: queuedConnectionReader.h
00002 // Created by:  drose (08Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef QUEUEDCONNECTIONREADER_H
00016 #define QUEUEDCONNECTIONREADER_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "connectionReader.h"
00021 #include "netDatagram.h"
00022 #include "queuedReturn.h"
00023 #include "lightMutex.h"
00024 #include "pdeque.h"
00025 
00026 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_NET, EXPTP_PANDA_NET, QueuedReturn<NetDatagram>);
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : QueuedConnectionReader
00030 // Description : This flavor of ConnectionReader will read from its
00031 //               sockets and queue up all of the datagrams read for
00032 //               later receipt by the client code.  This class is
00033 //               useful for client code that doesn't want to deal with
00034 //               threading and is willing to poll for datagrams at its
00035 //               convenience.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDA_NET QueuedConnectionReader : public ConnectionReader,
00038                                public QueuedReturn<NetDatagram> {
00039 PUBLISHED:
00040   QueuedConnectionReader(ConnectionManager *manager, int num_threads);
00041   virtual ~QueuedConnectionReader();
00042 
00043   BLOCKING bool data_available();
00044   bool get_data(NetDatagram &result);
00045   bool get_data(Datagram &result);
00046 
00047 protected:
00048   virtual void receive_datagram(const NetDatagram &datagram);
00049 
00050 #ifdef SIMULATE_NETWORK_DELAY
00051 PUBLISHED:
00052   void start_delay(double min_delay, double max_delay);
00053   void stop_delay();
00054 
00055 private:
00056   void get_delayed();
00057   void delay_datagram(const NetDatagram &datagram);
00058 
00059   class DelayedDatagram {
00060   public:
00061     double _reveal_time;
00062     NetDatagram _datagram;
00063   };
00064     
00065   LightMutex _dd_mutex;
00066   typedef pdeque<DelayedDatagram> Delayed;
00067   Delayed _delayed;
00068   bool _delay_active;
00069   double _min_delay, _delay_variance;
00070 
00071 #endif  // SIMULATE_NETWORK_DELAY
00072 };
00073 
00074 #endif
00075 
 All Classes Functions Variables Enumerations