Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/net/queuedConnectionReader.h

Go to the documentation of this file.
00001 // Filename: queuedConnectionReader.h
00002 // Created by:  drose (08Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 // We define this variable if we're compiling code to implement a
00035 // simulated network latency, useful for debuggin networked programs.
00036 // Normally, since this is a debugging tool, we wouldn't compile this
00037 // feature in if we're building a program for public release.
00038 #define SIMULATE_NETWORK_DELAY
00039 #endif
00040 
00041 ////////////////////////////////////////////////////////////////////
00042 //       Class : QueuedConnectionReader
00043 // Description : This flavor of ConnectionReader will read from its
00044 //               sockets and queue up all of the datagrams read for
00045 //               later receipt by the client code.  This class is
00046 //               useful for client code that doesn't want to deal with
00047 //               threading and is willing to poll for datagrams at its
00048 //               convenience.
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 

Generated on Fri May 2 00:40:36 2003 for Panda by doxygen1.3